Skip to main content
This guide builds a deliberately small bot that places one credit-funded limit order and cleans up any unfilled quantity. It demonstrates the API lifecycle without hiding order state or precision handling behind an SDK.
The example can create a real order on your PaperDrill account, but it only uses simulated funds. Review the selected symbol, side, price, and quantity before running it.

Prerequisites

  • Bun installed locally
  • A verified PaperDrill account with a funded credit balance
  • An API key with ORDER_READ, ORDER_CREATE, and ORDER_CANCEL
Set the key and, optionally, the market:

Create the bot

Save this file as bot.ts:
The bot uses scaled integers to move one price tick below the current best bid and submits the smallest quantity allowed by the market’s precision. That makes an immediate fill less likely, but another order can still match it at any time.

Run it

The script prints the created order, polls it for roughly ten seconds, and cancels any remaining open quantity. Pressing Ctrl+C also attempts cancellation before exit.

Make it production-ready

Before turning this example into a long-running strategy:
  • Use the WebSocket streams instead of polling market data.
  • Fetch a fresh order-book snapshot after every reconnect.
  • Reconcile open orders and balances when the process starts.
  • Add exponential backoff and jitter for 429, 503, and 504 responses.
  • Never blindly retry POST /orders after an ambiguous timeout.
  • Persist order IDs and decisions so a restart cannot duplicate activity.
  • Add explicit risk limits for order quantity, total exposure, and outstanding orders.
See Place and manage orders for the order lifecycle and Errors and rate limits for retry behavior.