Skip to content

REST API

The engine's web server answers a JSON REST API on the same port as the dashboard. It runs on its own uWebSockets thread, started by WebServer, and every route lives in WebServer::setup_routes(). The dashboard uses nothing else, so anything it does you can do with curl. Live updates come over the WebSocket.

The examples use port 3000, as in config/config_example.json. The code default is 8080 when web_server_port is missing.

There is no authentication

The server listens on every interface (config_.host is only logged, listen() gets the port alone). It checks no token, no Origin and no Content-Type. Anyone who can reach the port can place orders, halt strategies and rewrite their parameters. Keep it on localhost, or put a proxy with TLS and auth in front. A browser page from another site can also send a "simple" cross-origin POST (a text/plain body holding JSON) to a local engine, because the server parses the body whatever its type is.

Conventions

  • Bodies and answers are JSON. Request bodies are read whole before the handler runs, so a body that arrives in several chunks is fine.
  • Prices and quantities are plain JSON numbers (doubles), never the engine's 1e-8 fixed point. Timestamps are not wall time unless the Clocks section says so.
  • An error is {"error": "<reason>"} with the status code on the response line. Content-Type is application/json on every API answer.
  • POST, PUT and DELETE handlers that take a body parse it as JSON and answer 400 Invalid JSON: ... when they cannot, an empty body included. Send {} when a route has nothing to say. The exceptions are POST /api/strategies/:id/resume, POST /api/sim/replay and DELETE /api/orders/cancel-all, which ignore the body.
  • A 202 means the request was queued for a broker or a strategy, not that it took effect. Watch the WebSocket's order_update messages for the outcome.
  • Path parameters are not percent-decoded, so a strategy id with a space or a slash cannot be addressed.

Status codes

Code When
200 Done, or a read
202 Queued: a new order, a modify, a cancel, cancel-all, or a replay start
302 /app/<token>/ redirects to /?grouped
400 Bad JSON, a missing or invalid field, an unknown broker id, an unknown value for an enum-like field
403 A static path that leaves the web root
404 Unknown strategy, order or workspace, a missing file, or POST /api/sim/replay off Sim
409 POST /api/sim/replay while slick-sim is connected but cannot start yet
422 A new order turned down before it left the engine, by MANUAL's risk limits
500 An exception inside a handler, with its text
503 The order's broker takes no orders now, the config update could not be published, or slick-sim is not connected

Clocks

Most *_ns fields come from the engine's get_timestamp_ns(), which reads std::chrono::steady_clock. That is nanoseconds since an arbitrary point (usually boot), so it orders events within one run of the engine and means nothing as a date.

Field Clock
timestamp_ns in /api/pnl and /api/pnl/:id Steady, taken when the request is served
last_update_time in /api/positions and /api/positions/:id Steady, from the last fill
timestamp_ns in fills (/api/fills, order_update messages) Steady, stamped by the connector
created_time in /api/orders Wall clock (system_clock, nanoseconds since the Unix epoch) for an order placed through POST /api/orders. Steady for an order the server first saw in a broker ack
last_update_time in /api/orders The same clock as created_time until the first ack or fill, then steady
The number in a client order id (MANUAL_<n>) Steady
timestamp in level2 messages Milliseconds of venue event time

Do not compare or subtract values from different rows. created_time and last_update_time of one order can be on different clocks.

Route summary

Method Path Success Notes
GET /api/health 200 Version and environment
GET /api/sim 200 slick-sim's state, Simulator
POST /api/sim/replay 202 Starts the pcap replay
GET /api/brokers 200 Connection state of each broker
GET /api/strategies 200 Name, status and type of each strategy
POST /api/strategies/:id/control 200 start, stop, pause, resume
GET, PUT /api/strategies/:id/risk 200 Risk limits, memory only
GET, PUT /api/strategies/:id/config 200 Parameters, persisted by the PUT
POST /api/strategies/:id/halt 200 Halts through the risk manager
POST /api/strategies/:id/resume 200 Lifts a halt
GET /api/positions, /api/positions/:id 200 Non-flat positions
GET /api/pnl, /api/pnl/:id 200 P&L snapshots
POST /api/orders 202 A MANUAL order
GET /api/orders 200 Open orders of every strategy
PUT /api/orders/:strategy/:order_id 202 Modify
DELETE /api/orders/:strategy/:order_id 202 Cancel one
DELETE /api/orders/cancel-all 202 Cancel everything
GET /api/fills 200 The last 1,000 fills
GET, PUT /api/ladder-config 200 Order size defaults, memory only
GET, PUT, DELETE /api/workspaces 200 Saved window layouts
PUT /api/workspaces/last 200 Marks the last used
GET /* 200 The dashboard's static files

Health and sim

curl http://localhost:3000/api/health
{"status":"ok","version":"0.11.0","environment":"Production","production":true}

environment is the config's top-level value, or Live Sim / Historical Sim once slick-sim's feeds are known. production is false for anything but empty, production or prod in any case.

GET /api/sim and POST /api/sim/replay are covered in Simulator. Off the Sim environment GET /api/sim answers {"enabled":false,"environment":"Production"}.

Brokers

curl http://localhost:3000/api/brokers
{"brokers":[
  {"id":1,"name":"Coinbase","md":{"enabled":true,"connected":true},"order":{"enabled":true,"connected":true}},
  {"id":3,"name":"Hyperliquid","md":{"enabled":true,"connected":true},"order":{"enabled":false,"connected":false}}
]}

id is the number POST /api/orders takes as broker_id. Ids are fixed by the BrokerId enum: 1 is Coinbase and 3 is Hyperliquid. The enum names other brokers too (2, 4, 5 and 6), but only brokers this engine built and registered are listed, so read the list rather than assuming one. The same shape arrives as a broker_status WebSocket message whenever any flag changes.

Strategies

List

curl http://localhost:3000/api/strategies
[
  {"name":"MANUAL","id":"MANUAL","status":"running","halt_reason":"","type":"builtin"},
  {"name":"MM","id":"MM","status":"halted","halt_reason":"Loss limit breached","type":"plugin"}
]

status is one of:

Value Meaning
halted The risk manager has it halted. halt_reason says why
paused The StrategyManager auto-paused it. halt_reason carries the pause reason
running Started
stopped Not started

type is builtin for MANUAL and plugin for everything else. MANUAL is always registered and always running. The list carries no parameters or instruments.

Control

curl -X POST http://localhost:3000/api/strategies/MM/control \
  -H "Content-Type: application/json" -d '{"action":"stop"}'

action is start or resume (both start it), stop or pause (both stop it). The answer is {"success":true,"strategy_id":"MM","action":"stop"}. An unknown id is a 404, any other action a 400. Starting also clears an auto-pause. Nothing is persisted: the strategy's enabled flag in its config file does not change.

pause and resume here are only aliases. They are not the risk manager's halt, which is below.

Halt and resume

curl -X POST http://localhost:3000/api/strategies/MM/halt \
  -H "Content-Type: application/json" -d '{"reason":"desk call"}'
curl -X POST http://localhost:3000/api/strategies/MM/resume

reason defaults to Manual halt via API. A halted strategy's new orders fail pre-trade risk (Strategy halted: <reason>). Neither route checks that the strategy exists, so a typo succeeds and halts a name nothing uses. Halts live in memory and are gone after a restart.

Halting MANUAL stops dashboard orders

Dashboard and POST /api/orders orders are booked to MANUAL, so halting MANUAL makes every one of them come back 422.

Risk limits

curl http://localhost:3000/api/strategies/MM/risk
curl -X PUT http://localhost:3000/api/strategies/MM/risk \
  -H "Content-Type: application/json" \
  -d '{"max_position_size":5,"max_order_value":250000,"max_orders_per_second":20,
       "max_loss_per_strategy":-2000,"instrument_limits":{"BTC-USD":{"max_position_size":1}}}'
Field Type Notes
max_position_size number Per instrument, in quantity units
max_order_value number Notional per order
max_orders_per_second integer
max_loss_per_strategy number Negative, the loss at which it halts
instrument_limits object Per instrument: max_position_size, max_order_value. Only present on GET when set
halted boolean GET only

The PUT merges: a field you leave out keeps its value, and each instrument you name replaces that instrument's whole entry. A strategy with no limits reads back the defaults (max_position_size 1,000,000, max_order_value 100,000, 100 orders per second, loss -10000), and a PUT on an unknown id quietly creates an entry for it. Limits are memory only: a restart goes back to the strategy's config file.

Parameters

curl http://localhost:3000/api/strategies/MM/config
curl -X PUT http://localhost:3000/api/strategies/MM/config \
  -H "Content-Type: application/json" -d '{"spread_bps":4,"max_inventory":2}'

GET returns the strategy's current parameters object. PUT takes a JSON object and:

  1. Publishes it on the event bus, so the StrategyManager worker applies it with on_config() on the thread that owns the strategy's state.
  2. Writes it to disk as the strategy's parameters block, replacing the old one whole. It looks for the *.config.json under strategies.strategy_configs_folder whose name matches, else the inline entry in a legacy strategies array in the main config. enabled and risk_limits stay as written.

The 200 ({"success":true,"message":"Config updated successfully","strategy_id":"MM"}) comes after the publish, before the strategy has applied it. A failed write, or no file to write to, is only logged, so the strategy runs with the new values and loses them at a restart.

Status Reason
400 Not an object, or the strategy has no config support
404 Unknown strategy
503 No bus producer, the JSON is over 64 KB, or the name is 64 bytes or longer

An update replaces every parameter. MANUAL's instruments list is one of them: a PUT without it lists every instrument again (see Dashboard).

Positions and P&L

curl http://localhost:3000/api/positions
curl http://localhost:3000/api/positions/MM
curl http://localhost:3000/api/pnl
curl http://localhost:3000/api/pnl/MM

/api/positions is an object keyed by strategy, each an array. Flat positions are left out, and a strategy with none is left out altogether.

{"MM":[{"instrument":"BTC-USD","quantity":0.5,"avg_price":64000.0,"realized_pnl":12.3,
        "unrealized_pnl":4.1,"mark_price":64010.0,"last_update_time":83412000000000}]}

/api/positions/:id is the same array for one strategy, without unrealized_pnl and mark_price, and [] for one with no position.

/api/pnl is an object keyed by strategy. /api/pnl/:id is the same entry with strategy_id added, and an unknown id gets zeros with a 200.

{"MM":{"realized_pnl":11.8,"unrealized_pnl":4.1,"total_fees":0.5,"total_pnl":15.9,"timestamp_ns":83412000000000}}

realized_pnl here is net of realized fees, while the realized_pnl on a position is gross. Only strategies that have held a position appear. See Positions, P&L and risk.

Orders

Every order the dashboard or this API places is booked to the built-in MANUAL strategy. Its risk limits apply before the order goes out.

Orders go wherever the broker URLs point

With the example config that is the real Coinbase, so an order from the dashboard or curl is live. To try things out first, point the broker at a simulator, see Simulator.

Place an order

curl -X POST http://localhost:3000/api/orders -H "Content-Type: application/json" \
  -d '{"instrument":"BTC-USD","broker_id":1,"side":"buy","type":"limit","price":50000,
       "quantity":0.01,"time_in_force":0}'
Field Type Required Notes
instrument string yes As the broker names it. Event headers hold 31 characters, so a longer name is cut
broker_id integer yes An id from /api/brokers. Read as a 64-bit integer, then range checked, so 258 is not broker 2
side string yes buy, sell, BUY or SELL
quantity number yes Base units. The handler does not check the sign
type string no market (default) or limit, lower case only
price number limit orders A limit price of 0 or less is a 400
time_in_force integer no 0 to 4, default 0

Time in force is a number, the TimeInForce enum:

Value Name Notes
0 GTC The default
1 IOC
2 FOK
3 GTD The API has no field for the end time
4 DAY Expires with the session. The crypto brokers reject it

The API passes the number through. The dashboard is the one that turns a market order left on GTC or DAY into IOC, so a market order sent here with time_in_force 0 goes out as asked and the broker decides.

The success answer is 202:

{"success":true,"message":"Order submitted successfully",
 "order":{"strategy_id":"MANUAL","instrument":"BTC-USD","broker_id":1,"side":"buy",
          "quantity":0.01,"type":"limit","price":50000.0,"time_in_force":0}}

The answer carries no order id

The engine makes the client order id, MANUAL_<nanosecond timestamp>, and the response does not repeat it. It is in GET /api/orders right away (status PENDING_NEW, empty order_id) and in the order_update acks. The broker's order_id shows up once the ack arrives. price reads null for a market order.

Errors, in the order the handler checks them:

Status Reason
400 Missing required fields: instrument, broker_id, side, quantity, or a field of the wrong JSON type (Invalid JSON: ...)
400 No broker N in this engine. It has: ...: the id is not a built, registered broker
503 <broker>: Broker order connector disabled or ... disconnected
400 Invalid time_in_force, Invalid side, Invalid order type, or Limit orders require a valid price
404 Strategy not found, when MANUAL is missing
422 Order rejected: <reason> from MANUAL's pre-trade checks: a position, order value or rate limit, or a halt

A 202 only means the order was queued. A broker can still refuse it, and that arrives as an order_update with event reject.

A limit order with no price gets through the check

The price check is price <= 0, and a missing price is NaN, which fails that comparison. The order is queued as a limit with a null price. Always send price with "type":"limit".

post_only. The handler passes post_only = true for every order. The strategy base clears it for CME and ICE, which have no such instruction. What a connector does with it for a market or IOC order is up to the connector: the Hyperliquid connector turns the flag into an ALO (post only) order whatever the time in force.

List open orders

curl http://localhost:3000/api/orders
[{"strategy_id":"MANUAL","order_id":"0a1b...","client_order_id":"MANUAL_83412000000000",
  "instrument":"BTC-USD","side":"buy","type":1,"price":50000.0,"qty":0.01,"filled_qty":0.0,
  "remaining_qty":0.01,"status":"ACKNOWLEDGED","created_time":1764547200000000000,
  "last_update_time":83412100000000}]

The web server keeps this list itself from the order events it reads off the bus, so it covers every strategy's orders, not only MANUAL's. type is the OrderType number (0 market, 1 limit, 2 stop, 3 stop-limit, 4 bracket). status is PENDING_NEW, PENDING_MODIFY, PENDING_CANCEL, ACKNOWLEDGED, PARTIALLY_FILLED, FILLED, CANCELLED or REJECTED, as the last event set it. An order leaves the list when its fill, cancel or reject event arrives. order_id is empty until the ack. A strategy name is recovered from the client id (everything before the last _) for orders the web server did not place.

Modify, cancel, cancel all

# order_id and client_order_id as /api/orders lists them
curl -X PUT http://localhost:3000/api/orders/MANUAL/<order_id> -H "Content-Type: application/json" \
  -d '{"client_order_id":"<client_order_id>","new_price":50010,"new_quantity":0.02}'
curl -X DELETE http://localhost:3000/api/orders/MANUAL/<order_id> -H "Content-Type: application/json" \
  -d '{"client_order_id":"<client_order_id>"}'
curl -X DELETE http://localhost:3000/api/orders/cancel-all
  • Modify. client_order_id is required, and at least one of new_price and new_quantity. What you leave out keeps the order's current value. new_quantity is the new total size, not a delta. The order must be one the named strategy knows (404 Order not found), and :order_id in the path is only logged. 202 {"success":true,"message":"Modify request submitted"}.
  • Cancel. :order_id is the broker's id and goes into the cancel request, so cancel only after the ack has filled it in. client_order_id is required. Only the strategy is checked (404 Strategy not found): an order id the strategy does not know still answers 202. 202 {"success":true,"message":"Cancel request submitted"}.
  • Cancel all. Asks every strategy to cancel its open orders that already have a broker id, and answers {"success":true,"message":"Cancel all request submitted","strategies_affected":N}, where N counts strategies, not orders.

In all three the order stays in /api/orders until the broker's cancel or fill event arrives, because a cancel can be refused. A cancel of an order the web server no longer tracks produces no order_update.

Fills

curl http://localhost:3000/api/fills

The last 1,000 fills, oldest first, kept in memory. Each is the exact message the WebSocket sent, with a seq that grows by one per fill, so a client that fetched this and then listened can drop what it sees twice. The shapes are under order_update. Fills a broker replays from its journal at startup are not in the list. A restart empties it.

Ladder config

curl http://localhost:3000/api/ladder-config
curl -X PUT http://localhost:3000/api/ladder-config -H "Content-Type: application/json" \
  -d '{"default_qty":0.01,"per_instrument":{"BTC-USD":{"default_qty":0.001,"default_broker_id":1}}}'

GET returns the config's web_service.ladder_config as it stands, or {"default_qty":0.01,"per_instrument":{}} when there is none. The PUT replaces the whole object, and the only check is that default_qty exists. Other keys come back as sent. The ladder's order quantity box reads default_qty and per_instrument[<instrument>].default_qty, and the Ticket reads default_broker_id.

It is memory only. The dashboard PUTs it each time you type a new quantity on a ladder, and all of it is lost at a restart. Put what you want to keep in web_service.ladder_config in the config file. Each dashboard sends the whole object it loaded, so the last writer wins.

Workspaces

A workspace is a named set of tool windows. The file is the one in web_server_workspaces_file (default state/workspaces.json), written on every change to a temp file that is renamed over the old one, so a crash leaves it whole. See Dashboard for what the dashboard does with it.

curl http://localhost:3000/api/workspaces
curl -X PUT http://localhost:3000/api/workspaces -H "Content-Type: application/json" \
  -d '{"name":"Morning","windows":[{"tool":"ladder","left":-1280,"top":40,"width":360,"height":720,
       "params":{"instrument":"ZNZ6"}}]}'
curl -X PUT http://localhost:3000/api/workspaces/last -d '{"name":"Default"}'
curl -X DELETE http://localhost:3000/api/workspaces -d '{"name":"Morning"}'

GET returns the whole document:

{"last":"Morning","workspaces":{"Default":{"windows":[]},"Morning":{"windows":[]}}}

The three writes answer {"status":"ok"}. The name travels in the body, so it needs no URL encoding.

Route Effect
PUT /api/workspaces Saves windows under name and makes it the last used. Replaces a workspace of that name
PUT /api/workspaces/last Marks name the last used. 404 if it does not exist
DELETE /api/workspaces Removes name. If it was the last used, Default becomes it

Limits, all a 400 unless noted:

  • name is a string of 1 to 64 bytes with no control characters. ASCII blanks, no-break spaces and ideographic spaces around it are trimmed ("Morning " is Morning).
  • windows is an array of at most 128. Each needs a tool (1 to 32 characters) and integer left, top, width and height. A negative left or top is normal on a second screen.
  • params is optional: an object whose keys and values are strings of at most 128 bytes each.
  • Any other key in a window is dropped.
  • Default always exists and cannot be deleted. Deleting or marking a missing name is a 404.
  • A write that fails on disk is a 500, and the in-memory copy goes back to what it was.

A file that is not valid, or a workspace in it that is, is dropped at startup with a warning, not the rest of the file.

Static files and the app path

Every other GET is looked up under web_server_static_path:

  • / is index.html. tool.html, css/, js/ and lib/ are served as they are.
  • The content type comes from the extension: .html, .css, .js, .json, .png, .jpg, .jpeg, .svg and .ico are known, anything else is application/octet-stream. Browsers refuse a module that is not application/javascript, so a vendored library keeps a .js name.
  • Every file answers Cache-Control: no-cache, and the whole file is read from disk on each request.
  • A path that resolves outside the web root is a 403 Invalid path, a missing file a 404 File not found. An unknown GET /api/... path falls through to here, so it also answers a 404.
  • /app/<anything> answers 302 with Location: /?grouped. The Windows helper slick-trader-app.exe opens each dashboard at /app/<token>/ so the browser names its windows after the path. See Dashboard.

CORS and unhandled methods

With web_server_cors true (the default) every answer carries Access-Control-Allow-Origin: *, Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS and Access-Control-Allow-Headers: Content-Type. Set it to false to drop all three.

OPTIONS has no route

The server registers no OPTIONS handler, although it lists the method. uWebSockets closes the connection of a request no route matches, without a response. A browser's CORS preflight, which a cross-origin PUT, DELETE or JSON POST triggers, therefore fails. HEAD, PATCH and a POST to a path with no route get the same treatment. Cross-origin use works for plain GETs only, and the dashboard itself is same-origin.

Where handlers run

Every handler runs on the web server's thread. The ones that touch engine state do it directly: order, cancel and modify calls go to MANUAL's StrategyBase methods, start and stop to the StrategyManager, and halt, resume and risk limit writes to the RiskManager. Strategy parameter updates are the exception: they go over the event bus so the StrategyManager worker applies them. See Architecture.