Examples
Runnable scripts ship in the npm tarball under node_modules/@tria-sdk/api-trading/examples/. Copy one out, fill in your env vars, and run it directly.
| Script | Demonstrates |
|---|---|
place-order.ts | Place + cancel an HL limit order; cloid generation. |
cancel-order.ts | Cancel by clientOrderId; idempotency on the second cancel. |
subscribe-fills.ts | Live HL fill stream + the onConnection lifecycle hook. |
multi-venue.ts | Fan-out fills from HL + Decibel into one position-tracking loop via the normalized Fill shape. |
market-data.ts | End-to-end pre-trade flow: markets(), top-of-book + candles, round price to tick, place + cancel, account snapshot. |
subscribe-orders-and-account.ts | Live order lifecycle + account snapshot streams together; clean unsubscribe on SIGINT. |
batch-modify-tpsl.ts | placeBatch (IOC + 2 GTCs in one signed action), attachTpSl, modifyOrder, cleanup close. |
Run one
# Run straight from the installed package:
npx tsx node_modules/@tria-sdk/api-trading/examples/place-order.ts
Or copy a script into your project and adapt it:
cp node_modules/@tria-sdk/api-trading/examples/place-order.ts ./my-first-bot.ts
# ...edit, then:
npx tsx my-first-bot.ts
Each script reads its credentials from TRIA_TRADE_* env vars — see Credentials to mint them, then source your .env before running:
set -a; source ./tria.env; set +a
npx tsx node_modules/@tria-sdk/api-trading/examples/market-data.ts
These run against real mainnet venues and place real orders (the order
examples cancel immediately, but fills can occur on crossing prices). Start
with market-data.ts, which is read-only until its final place+cancel step.