Skip to main content
Call the API from TypeScript with typed methods instead of hand-written requests. Use this page when your server or script is written in TypeScript or JavaScript. @trdrs/sdk is generated from the same OpenAPI document this site documents, so it has a method for every route and can’t describe a route the engine doesn’t serve. It has no dependencies and runs in Node and in the browser, though a key never belongs in browser code. By the end you have a client, a first call, a stream and refusals handled by name.

Install it

The SDK isn’t on npm yet, so build it from its repository:
Then add the built package to your project from that folder.

Create a client

Create one client when your server starts and reuse it. Pass the keys your server holds, from its secret environment.
Each call picks the right key from the contract, so a trading call sends the Trading API key and a Connect call sends the Partner key without you choosing.

Make a call

Methods are grouped the way the API reference groups routes, and named after each route’s title. Parameters and the request body go in one object.
When you leave out clientOrderId, the SDK makes one, so a retry of the same call can’t place a second order. When your app retries on its own, mint the id yourself and pass it every time. Each method carries the route’s description in its documentation comment, so your editor shows the rules while you write the call.

Read a stream

A stream is an async iterator. It starts with the whole current picture on every connect, then sends changes.
Stream live data explains the events.

Handle refusals by name

A refusal throws an error class named after it, so your code tells a locked account from a failure without reading status codes.
A risk lock is a state to show, not an error to retry. Errors lists every refusal.

Stay in step with the API

The generated methods and types are committed to the repository, so nothing is downloaded when you build. When the engine adds a route, npm run generate writes the new methods from the served contract, and the SDK’s own test fails if the committed code ever differs from the contract.

Next steps

Place your first order

Follow a whole order from risk check to flatten, with curl and the SDK side by side.

Build a front end

Use the SDK on your server behind your own trading screens.