Bones for Building a Bot
Build a sandbox trading bot that authenticates with the API, retrieves market data, submits orders, and runs scheduled automation safely.
Build a sandbox trading bot that authenticates with the API, retrieves market data, submits orders, and runs scheduled automation safely.
Use the current Trading API endpoint paths in your integration. Your local code can retain implementation-specific identifiers such as sport_events, but use the documented API terms in developer-facing logs, interfaces, and documentation.
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.sandbox.prophetx.dev/
Implementation outline
-
Authentication
- Call
POST /auth/loginwithaccess_keyandsecret_key. - Store the
access_tokenand arequests.Sessionfor headers and cookies. - Refresh the session with
POST /auth/refresh, or authenticate again if refresh fails.
- Call
-
Seed data
- Call
GET /mm/get_price_ladder,GET /mm/get_tournaments,GET /mm/get_sport_events, andGET /mm/get_marketsorGET /mm/get_multiple_markets. - 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
strike_idbefore you submit an order.
- Call
-
Balance
- Call
GET /mm/get_balanceto fetch and store the available balance. - Check the available balance before submitting orders.
- Call
-
Submit and cancel orders
- Submit orders with
POST /mm/submit_orderorPOST /mm/submit_multiple_orders. - Cancel orders with
POST /mm/cancel_orderorPOST /mm/cancel_multiple_orders. - Maintain a mapping of
external_idtoorder_idfor cancellations.
- Submit orders with
-
WebSocket subscription (optional but highly recommended)
- Call
GET /websocket/connection-config, then callPOST /mm/pusherwith the connected socket ID to retrieve 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.
- Call
-
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 quantity 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 about 1 month ago
