# The TypeScript SDK

> The @ftw/sdk package wraps every ftw.trade tool in a typed client that runs anywhere with fetch, and is the library hosted scripts are written with.

## A typed client

`@ftw/sdk/client` wraps the MCP tools in a typed client that runs anywhere `fetch` does: Node, Bun, Deno, a browser, a Cloudflare Worker.

```ts
import { Ftw, FtwError } from '@ftw/sdk/client';

const ftw = new Ftw({ token: process.env.FTW_TOKEN! });

const { strategies } = await ftw.listStrategies();
const report = await ftw.backtestStrategy({ id: strategies[0].id, series: 'perp:hyperliquid:ETH', interval: '1h' });
console.log(report.stats.returnPct, report.stats.maxDrawdownPct);

try {
  await ftw.runStrategy({ id: strategies[0].id, series: 'perp:hyperliquid:ETH', interval: '1h' });
} catch (e) {
  if (e instanceof FtwError) console.error(e.status, e.field, e.message);
}
```

> [!NOTE] Coming soon
> The client goes up on npm closer to launch. Until then, call the [MCP server](https://docs.ftw.trade/agents/mcp) directly. Hosted scripts on ftw.trade already have `@ftw/sdk`, nothing to install.

One method per tool (`backtest_strategy` is `backtestStrategy`), with its arguments and answer typed. A refusal is thrown as an `FtwError` with its status, message and field.

## Hosted scripts

The same package is what [TypeScript scripts](https://docs.ftw.trade/automate/scripts) are written with on ftw.trade: `automation()`, `source()` and `action()`, the `t` field kinds, and the types for wallets, pools, candles, swaps, bridges and events.

## Your own NATS

`@ftw/sdk/nats` feeds a pushed source from your own NATS JetStream stream, with exactly-once commits. See the sources skill for the details.

## Reference

The SDK's full README and types are in the [scripts skill's SDK reference](https://ftw.trade/skills/ftw-scripts/references/sdk.md).
