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.

  1. Install Python 3.8 or later.
  2. Install the recommended packages:
pip install requests pysher schedule pytz
  1. 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

  1. Create src/user_info.json:
{
  "access_key": "YOUR_ACCESS_KEY",
  "secret_key": "YOUR_SECRET_KEY",
  "tournaments": [123],
  "load_all_tournaments": false
}
  1. Ensure BASE_URL in your config points to the sandbox URL: https://api-ss-sandbox.betprophet.co/

Implementation outline

  1. Authentication

    • POST to the session login endpoint partner/auth/login with access_key and secret_key.
    • Store access_token and a requests.Session for headers and cookies.
    • Implement refresh token handling by calling partner/auth/refresh or re-authenticating on failure.
  2. 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 cache sport_events.
    • Validate that each market includes the required identifiers, such as selection and strike_id.
  3. Balance & wallet

    • Implement get_balance() to fetch and store the available balance.
    • Check balance before submitting orders.
  4. Submit and cancel orders

    • Implement the mm_place_order and mm_cancel_order endpoints.
    • Maintain a mapping of external_id -> order_id for cancellations.
    • Implement batch cancellation if your integration uses it.
  5. 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.
  6. Scheduling & automation

    • Use schedule to run periodic tasks:
      • seed every 30 minutes
      • run start_ordering every 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.
  7. 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_URL contains sandbox before submitting orders.
  8. 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.py in 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.py with a class that returns candidate orders
    • integrate the strategy into start_ordering()
  • 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.py

Safety checklist before running

  • Use sandbox credentials
  • Confirm BASE_URL points 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