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

# Examples

> Runnable @ostium/builder-sdk programs shipped with the package: an order ticket, a live positions view, and a complete trade loop.

Three runnable programs ship with the package, at `node_modules/@ostium/builder-sdk/examples/` after install. They import the SDK by package name, so they also run unchanged if you copy them into your own project.

| File              | What it shows                                                                                      | Needs a key?                                 |
| ----------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------- |
| `order-ticket.ts` | Preview a trade the way an order ticket would — execution price, fees, liquidation price, validity | No                                           |
| `positions.ts`    | A trader's open positions, then live PnL over WebSocket                                            | Snapshot no; streaming needs a WebSocket RPC |
| `bot.ts`          | A complete trade loop: onboard, preview, submit, watch, close                                      | Yes                                          |

## Running them

```bash theme={null}
bun node_modules/@ostium/builder-sdk/examples/order-ticket.ts

bun node_modules/@ostium/builder-sdk/examples/positions.ts 0xTraderAddress

ARBITRUM_WS_URL=wss://... \
  bun node_modules/@ostium/builder-sdk/examples/positions.ts 0xTraderAddress

PRIVATE_KEY=0x... ARBITRUM_RPC_URL=https://... \
  bun node_modules/@ostium/builder-sdk/examples/bot.ts
```

They are TypeScript — run them with `bun`, or compile them with `tsc` first.

## order-ticket.ts

Resolves BTC/USD from [`getPairs()`](/developer/reference/get-pairs), then prints what [`previewOpenTrade()`](/developer/reference/preview-open-trade) returns: execution price, fees, liquidation price and any warnings. Read-only — no key, nothing submitted.

## positions.ts

Prints a trader's open positions from [`getOpenPositions()`](/developer/reference/get-open-positions), then streams live updates via [`streamAccountUpdates()`](/developer/reference/stream-account-updates).

The snapshot needs no credentials. Streaming needs a WebSocket Arbitrum RPC endpoint; without one the example prints the snapshot and skips streaming. `ALCHEMY_API_KEY` also works.

## bot.ts

The full lifecycle: [`getOnboardingStatus()`](/developer/reference/get-onboarding-status), [`previewOpenTrade()`](/developer/reference/preview-open-trade), `openTrade()`, watching the position, then `closeTrade()` — including how to handle `OstiumError` and `OstiumSubmissionPendingError`.

<Warning>
  `bot.ts` spends funds. It defaults to testnet; `MAINNET=1` points it at real money.
</Warning>

## For AI coding agents

The package also ships `llms.txt` and a Claude skill at `.claude/skills/ostium-builder-sdk/SKILL.md` — flat API references written for coding agents. Point your agent at one of them instead of pasting documentation pages.
