Bones for Building a Bot
Build a sandbox trading bot with ProphetX with the the current API paths and implementation identifiers required by the live integration.
Building a trading bot
Build a sandbox trading bot that authenticates with the API, ingests market data, submits orders, and runs scheduled automation safely.
The current API still uses some legacy endpoint paths such as partner/auth/login and partner/auth/refresh, and some local code may still use identifiers like sport_events.
You are responsible for the behavior of your bot. Test only in the sandbox environment, and do not use production credentials or production endpoints during development.
Goals
- Authenticate with the API
- Seed markets, events, and prices
- Submit and cancel orders
- Maintain sessions and WebSocket connections
- Run scheduled automated logic (strategy)
- Log activity, test behavior, and enforce sandbox safety checks
Prerequisites
Use Python for the examples in this guide. You can adapt the same workflow to another language if needed.
- Install Python 3.8 or later.
- Install the recommended packages:
pip install requests pysher schedule pytz- Get sandbox credentials and confirm you are using a sandbox API endpoint.
Project layout
- src/main.py — entry point for startup and scheduling
- src/mm_calls.py — core MMInteractions class for authentication, seeding, order submission, order cancellation, and WebSocket handling
- src/config.py — endpoints, keys loader
- src/user_info.json — user keys & preferences (create locally)
- src/log.py, src/constants.py — logging and constants used by the bot
Configuration
- Create
src/user_info.json:
{
"access_key": "YOUR_ACCESS_KEY",
"secret_key": "YOUR_SECRET_KEY",
"tournaments": [123],
"load_all_tournaments": false
}- Ensure
BASE_URLin your config points to the sandbox URL: https://api-ss-sandbox.betprophet.co/
Implementation outline
-
Authentication
- POST to the session login endpoint
partner/auth/loginwithaccess_keyandsecret_key. - Store
access_tokenand arequests.Sessionfor headers and cookies. - Implement refresh token handling by calling
partner/auth/refreshor re-authenticating on failure.
- POST to the session login endpoint
-
Seeding data
- Pull markets, tournaments, events, and the valid price ladder.
- Build in-memory structures such as
valid_prices,all_tournaments, and an event cache. Your local code may still name that cachesport_events. - Validate that each market includes the required identifiers, such as selection and
strike_id.
-
Balance & wallet
- Implement
get_balance()to fetch and store the available balance. - Check balance before submitting orders.
- Implement
-
Submit and cancel orders
- Implement the
mm_place_orderandmm_cancel_orderendpoints. - Maintain a mapping of
external_id -> order_idfor cancellations. - Implement batch cancellation if your integration uses it.
- Implement the
-
WebSocket subscription (optional but highly recommended)
- Obtain connection config (key/cluster) and signed channels.
- Use pysher (or websocket-client) to subscribe and update local state on events.
- Bind public and private handlers to process market updates and order confirmations.
-
Scheduling & automation
- Use
scheduleto run periodic tasks:- seed every 30 minutes
- run
start_orderingevery N seconds with a small sandbox interval during testing - cancel random orders or batch cancellations
- refresh the session every few minutes
- Run schedule in a background thread.
- Use
-
Strategy & risk
- Start with a deterministic test strategy, not real money. For example, submit fixed small orders at random valid prices.
- Implement cost sizing, maximum exposure, and per-tournament limits.
- Add price filters to avoid thin markets.
- Never point to production endpoints or use production keys during development. Assert that
BASE_URLcontainssandboxbefore submitting orders.
-
Resilience & safety
- Add retry/backoff for transient network errors.
- Rate-limit requests to respect API constraints.
- Validate API responses and handle malformed responses.
- Add logging and error alerts.
Testing
- Use sandbox/test accounts only.
- Add unit tests for:
- auth flow (mock responses)
- seeding/parsing market data
- order submission and cancellation logic (mock API)
- Run
python3 src/main.pyin staging and review the bot behavior, logs, and API calls.
Deployment & monitoring
- Run in a contained environment (VM or container).
- Use process manager (systemd, supervisord) or Docker to restart on failures.
- Monitor logs, balance changes, and submitted orders.
- Set alerts for failed refreshes, repeated API errors, or unusually large orders.
Extending the bot
- Replace randomized orders with a strategy module:
- create
src/strategy.pywith a class that returns candidate orders - integrate the strategy into
start_ordering()
- create
- Add persistence (sqlite/postgres) for order history and state.
- Add metrics (Prometheus) and dashboards.
Minimal run example
From repo root:
cd sandbox-bot/mm-trading-bot
python3 src/main.pySafety checklist before running
- Use sandbox credentials
- Confirm
BASE_URLpoints to the sandbox environment - Start with extremely small order sizes
- Ensure logging is enabled
- Understand scheduled intervals
Useful TODOs
- Implement unit tests for mm_calls methods
- Add Dockerfile for sandboxed runs
- Add an integration test that mocks API endpoints
Updated 9 days ago
