> ## 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.

# Ostium API & SDK

> The official Ostium TypeScript SDK and Builder API for reading market data, streaming prices, and placing trades programmatically on Ostium.

The Ostium SDK is the current TypeScript client for reading Ostium market data, building mode-correct transactions, and submitting trading actions.

Current package: `@ostium/builder-sdk@0.7.0`.

## Install

```bash theme={null}
npm install @ostium/builder-sdk viem
```

## Core SDK surfaces

* client creation methods for each execution mode
* build-only transaction helpers for client-side signing
* SDK-managed write methods for direct submission
* read methods backed by the subgraph and builder API
* live streams for prices, positions, and low-latency account confirmations

Client construction is lazy: factories no longer pre-fetch the full pair list from the subgraph. Read methods populate market metadata on first use. Gasless submit-capable factories accept an optional known `safeAddress` to skip the smart-account derivation call during construction.

## Method index

### Client creation

* `createSelfAndSelf`
* `createSelfAndGasless`
* `createDelegatedAndSelf`
* `createDelegatedAndGasless`
* `createReadOnly`

See [Client Configuration](/developer/client-modes/configuration) for every parameter these factories accept.

### Helpers

* `canBuildTransactions`
* `canSubmitTransactions`
* `getTraderAddress`
* `isReadOnly`
* `getSmartAccountAddress`
* `checkUsdcAllowance`
* `getBalances`
* `extractOrderIdFromReceipt`

### Utilities and constants

* `parseUsdc`
* `parsePrice`
* `parseLeverage`
* `MIN_OPEN_SIZE_USD`
* `MIN_COLLATERAL_USD`
* `MAX_COLLATERAL_USD`

### Read methods

* `getPairs`
* `getAllPrices`
* `getOpenPositions`
* `getOpenOrders`
* `getOrders`
* `getBuilderOrders`
* `getFills`
* `getFillsByTime`
* `getSimSlippage`
* `getSimOrderbook`
* `getCandles`
* `streamPrices`
* `streamPositionUpdates`
* `streamAccountUpdates`

### Transaction builders

* `getSetupGaslessDelegationTx`
* `getApproveUsdcTx`
* `getSetDelegateTx`
* `getRemoveDelegateTx`
* `getOpenTradeTx`
* `getCloseTradeTx`
* `getCancelOrderTx`
* `getModifyOrderTx`
* `getUpdateCollateralTx`

### Write methods

* `approveUsdc`
* `setupGaslessDelegation`
* `setDelegate`
* `removeDelegate`
* `openTrade`
* `closeTrade`
* `modifyOrder`
* `updateCollateral`
* `cancelOrder`

## Build vs submit

Every write action now has two SDK surfaces:

* `get*Tx()` returns unsigned transaction data for wallet-driven or Safe-driven client applications
* the write method (`openTrade`, `closeTrade`, `approveUsdc`, and so on) signs and submits through the configured mode when the client was created with credentials

For example:

```ts theme={null}
const client = await OstiumClient.createSelfAndSelf({
  traderAddress: '0xTraderAddress',
});

const tx = client.getOpenTradeTx({
  pairId: 0,
  buy: true,
  price: '65000',
  collateral: '100',
  leverage: '5',
  type: OrderType.Market,
});
```

In gasless build-only modes, the same `get*Tx()` methods return a Safe-style request instead of an EOA request.

## Guides

If you want implementation examples instead of method reference, use the guides section:

* [Builder Set Up](/developer/builders/overview)
* [React Example](/developer/builders/react-quickstart)
* [Trader Quickstart](/developer/traders/approvals-and-first-trade)

## Error handling

See [Errors](/developer/sdk/errors) for the exported `OstiumError`, `OstiumSubgraphError`, and their error codes.

## Changelog

See [Changelog](/developer/sdk/changelog) for the versioned SDK changes, including the `0.7.0` construction, stream, and order-id fixes.
