> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trdrs.co/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> A typed client for every route, generated from the served contract — install it instead of writing one.

`@trdrs/sdk` is the TypeScript client for this API. Zero dependencies, works in Node and the
browser, and every method is generated from the same OpenAPI document this site renders — so the
SDK cannot describe a route the engine does not serve.

Install from the repository until the first npm release:

```bash theme={null}
git clone https://github.com/Trdrsco/trdrs-sdk.git
cd trdrs-sdk && npm install && npm run build
```

## Construct once

```ts theme={null}
import { Trdrs } from '@trdrs/sdk'

const client = new Trdrs({
  apiKey: process.env.TRDRS_TENANT_KEY,
  partnerKey: process.env.TRDRS_PARTNER_KEY, // only for /api/partner/ routes
})
```

The right key is chosen per operation from the contract's own security block, so a partner call
sends the partner key and a trading call sends the firm key without you routing anything.

## Call a route

```ts theme={null}
const bars = await client.marketData.getPriceHistory({ instrument: 'ESU6', tf: '5m' })

const order = await client.trading.placeAnOrder({
  instrument: 'ESU6',
  side: 'buy',
  qty: 1,
  orderType: 'market',
})
console.log(order.clientOrderId) // sdk-… generated for you, so a retry cannot double the order
```

Every method carries the operation's summary and semantics as JSDoc, so an editor shows you the
idempotency and atomicity rules without leaving the call.

## Stream

```ts theme={null}
for await (const event of client.marketData.streamLiveBars({ instrument: 'ESU6', tf: '1m' })) {
  // a full snapshot arrives first on every (re)connect, then live events
}
```

## Handle refusals

```ts theme={null}
import { TrdrsRiskLockedError, TrdrsRateLimitedError } from '@trdrs/sdk'

try {
  await client.trading.placeAnOrder({ /* … */ })
} catch (err) {
  if (err instanceof TrdrsRiskLockedError) return showLockBanner()
  if (err instanceof TrdrsRateLimitedError) return retryAfter(err.retryAfterSeconds)
  throw err
}
```

A `423` is a state to display, not an error to retry — the SDK names it so you cannot mistake it.

## Regenerating

The generated methods and types are committed, so nothing is fetched at build time. When the
engine ships a route, `npm run generate` rewrites them from the served document, and a test fails
if the committed output ever drifts from the contract.
