API reference · Sim

Run a simulation

POST/v1/sim/runs

Replay a past event against its recorded order books with a built-in strategy, at several latencies, and get the scorecard.

On this page

Auth. An API token: Authorization: Bearer lb_… (create one). Signed-in web sessions work too.

Limits. One Sim run (20 a month on Free, 100 on Builder, unlimited on Standard).

Parameters

Body

NameTypeRequiredDescription
event_idstringyesA replayable event (ev_…); see List replayable events.
strategystringnoA built-in strategy name; see List built-in strategies. Default hold_none.
paramsobjectnoThe strategy's parameters; unknown names are refused.
latency_msarray of integernoMilliseconds after each event's emission to evaluate fills at, up to 6 values; default [250, 2250, 5250].
starting_cashnumbernoPaper cash in USD. Up to 10,000,000. Default 1000.0.
maker_fee_ratenumbernoThe maker fee rate. 0 to 0.5. Default 0.0175.
queue_positionbooleannoMake resting orders wait behind the size recorded at their price. Default false.
taker_delay_msintegernoA venue speed bump on taking orders, in ms. 0 to 60,000. Default 0.
codestringnoRefused. Your own strategy files run on your machine with langbot sim run -s my_bot.py.

Request

Terminal
curl -X POST "https://api.langbot.ai/v1/sim/runs" \
  -H "Authorization: Bearer $LANGBOT_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"event_id": "ev_kxearningsmentiongs_26oct13", "strategy": "buy_yes_on_first_counting_hit", "params": {"max_price": 0.6}}'

Response

201 Created

JSON
{
  "id": "run_01K8Z3…",
  "kind": "server",
  "event_id": "ev_kxearningsmentiongs_26oct13",
  "strategy": "buy_yes_on_first_counting_hit",
  "params": { "max_price": 0.6 },
  "latency_ms": [250, 2250, 5250],
  "starting_cash": 1000.0,
  "paid": false,
  "created_at": 1793500000000,
  "scorecard": {
    "books_replayed": 18342,
    "by_latency": [
      { "latency_ms": 250, "net": 41.2, "fees": 3.1, "fills": 4, "fill_rate": 1.0, "max_drawdown": 6.0 },
      { "latency_ms": 2250, "net": 18.7, "fees": 3.3, "fills": 4, "fill_rate": 1.0, "max_drawdown": 9.5 },
      { "latency_ms": 5250, "net": -4.9, "fees": 2.4, "fills": 3, "fill_rate": 0.75, "max_drawdown": 14.0 }
    ],
    "markets": []
  },
  "allowance": { "plan": "free", "runs": 20, "period": "month", "used": 3, "remaining": 17, "resets_at": 1793577600000 }
}

A scorecard describes what the strategy would have done against the recorded books, after the venue's fees; it is not a forecast. How fills and fees are modelled: Simulator and backtesting.

Errors

StatuscodeWhen
400bad_requestThe body carries code: custom strategies run locally.
404not_foundNo recorded feed or no order books for the event.
413too_largeOver 5 million book snapshots in the window; run it locally.
401auth_requiredNo token was sent.
401token_invalidThe token was not recognised (mistyped, revoked or expired).
422validation_errorA parameter failed validation; detail[].loc names it.
429quota_exceededThis month's Sim runs are spent; quota.resets_at says when they reset.
429rate_limitedOver your request budget; wait Retry-After seconds.

Every error body is {"detail": …, "code": "…"}; branch on code. All codes: Errors.