> For the complete documentation index, see [llms.txt](https://docs.gammaswap.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gammaswap.com/developers/getting-started/clients.md).

# Clients

The SDK separates read requests, signed actions, on-chain deposits, and real-time subscriptions into five clients.

<table><thead><tr><th width="228.109375">Client</th><th width="287.0859375">Primary use</th><th align="right">Wallet required</th></tr></thead><tbody><tr><td><code>InfoClient</code></td><td>Read exchange and account data</td><td align="right">No</td></tr><tr><td><code>ExchangeClient</code></td><td>Submit signed exchange actions</td><td align="right">Yes</td></tr><tr><td><code>DepositClient</code></td><td>Read and write deposit-contract state</td><td align="right">Yes</td></tr><tr><td><code>ExchangeWebSocketClient</code></td><td>Subscribe to market updates</td><td align="right">No</td></tr><tr><td><code>OracleWebSocketClient</code></td><td>Subscribe to oracle prices</td><td align="right">No</td></tr></tbody></table>

### InfoClient

Use `InfoClient` for unsigned, read-only HTTP requests.

Available methods:

* `getAsset`
* `getResolutionPrice`
* `getLastResolutionPrice`
* `getBalance`
* `getOrderBook`
* `getBookOrders`
* <sup>`getTopOfBook`</sup>
* `getPosition`
* `getAgentApproval`
* `getAgentApprovalNonce`
* `getExchangeConfig`

Create a client:

```ts
import { createInfoClient } from "@gammaswap/v2-exchange-sdk";

const info = createInfoClient({
  apiUrl: "https://exchange-api.gammaswap.com/api",
});
```

Constructor options:

| Option    | Required | Description                        |
| --------- | -------: | ---------------------------------- |
| `apiUrl`  |      Yes | Exchange HTTP API base URL         |
| `fetch`   |       No | Replacement for `globalThis.fetch` |
| `headers` |       No | Headers added to every request     |

No wallet or signature is required.

### ExchangeClient

Use `ExchangeClient` for wallet-signed exchange actions.

Available methods:

* `placeOrder`
* `placeAgentOrder`
* `cancelOrder`
* `cancelAll`
* `cancelReplaceOrder`
* `cancelAgentOrder`
* `cancelAllAgent`
* `cancelReplaceAgentOrder`
* `claim`
* `claimAgent`
* `withdraw`
* `approveAgent`
* `revokeAgent`
* `signAgentApproval`

Create a client:

```ts
import { createExchangeClient } from "@gammaswap/v2-exchange-sdk";
import { Wallet } from "ethers";

const exchange = createExchangeClient({
  apiUrl: "https://exchange-api.gammaswap.com/api",
  wallet: new Wallet(process.env.PRIVATE_KEY!),
  chainId: "84532",
});
```

Constructor options:

| Option         | Required | Description                             |
| -------------- | -------: | --------------------------------------- |
| `apiUrl`       |      Yes | Exchange HTTP API base URL              |
| `wallet`       |      Yes | `ethers` wallet used for signing        |
| `chainId`      |      Yes | Chain ID included in EIP-712 signatures |
| `contracts`    |       No | Contract-address overrides              |
| `fetch`        |       No | Replacement for `globalThis.fetch`      |
| `headers`      |       No | Headers added to every request          |
| `infoClient`   |       No | Existing `InfoClient` instance          |
| `nonceManager` |       No | Custom action nonce manager             |

The SDK fills signing fields, hashes the action, creates the EIP-712 signature, and serializes the request body.

### DepositClient

Use `DepositClient` for direct contract reads and deposit transactions.

Available methods:

* `getSettlementToken`
* `getPermit2`
* `getAccountLedger`
* `getPendingBalance`
* `getProcessedBalance`
* `getPendingDepositCount`
* `getNextPendingDepositId`
* `getProcessedDepositIndex`
* `getMinBlockWait`
* `canProcessNext`
* `getSettlementTokenBalance`
* `getSettlementTokenAllowance`
* `approveDepositLedger`
* `approvePermit2`
* `deposit`
* `signDepositPermit`
* `depositWithPermit`
* `parseAmount`

Create a client:

```ts
import { createDepositClient } from "@gammaswap/v2-exchange-sdk";
import { Wallet } from "ethers";

const deposit = createDepositClient({
  rpcUrl: process.env.RPC_URL!,
  wallet: new Wallet(process.env.PRIVATE_KEY!),
  chainId: "84532",
});
```

Constructor options:

| Option                    | Required | Description                                             |
| ------------------------- | -------: | ------------------------------------------------------- |
| `rpcUrl`                  |      Yes | EVM JSON-RPC URL                                        |
| `wallet`                  |      Yes | Wallet used for reads, approvals, and deposits          |
| `chainId`                 |      Yes | Expected RPC network chain ID                           |
| `depositLedger`           |       No | Deposit-ledger address override                         |
| `contracts`               |       No | Contract-address overrides                              |
| `settlementTokenDecimals` |       No | Settlement-token decimals; currently required to be `6` |

The client communicates directly with chain contracts rather than the Exchange HTTP API.

### ExchangeWebSocketClient

Use `ExchangeWebSocketClient` for live market events by `assetId`.

Available methods and properties:

* `connectionState`
* `connect`
* `close`
* `subscribeOrderBook`
* `unsubscribeOrderBook`

Create a client:

```ts
import {
  createExchangeWebSocketClient,
} from "@gammaswap/v2-exchange-sdk";

const marketStream = createExchangeWebSocketClient({
  websocketUrl: "wss://exchange-api.gammaswap.com/ws/",
  onError: console.error,
});
```

Subscription handlers:

* `onUpdate`
* `onOrder`
* `onTrade`
* `onCancel`
* `onResolution`
* `onError`
* `onResyncRequired`

One client can subscribe to multiple asset IDs. Multiple local handlers for the same asset share one server subscription.

### OracleWebSocketClient

Use `OracleWebSocketClient` for live oracle prices by `symbolId`.

Available methods and properties:

* `connectionState`
* `connect`
* `close`
* `subscribePrice`
* `unsubscribePrice`

Create a client:

```ts
import {
  createOracleWebSocketClient,
} from "@gammaswap/v2-exchange-sdk";

const oracleStream = createOracleWebSocketClient({
  websocketUrl: "wss://exchange-api.gammaswap.com/oracle-ws/",
  stalePriceTimeoutMs: 30_000,
  onError: console.error,
});
```

Subscription handlers:

* `onPrice`
* `onError`
* `onStale`

After a reconnect or stale-price event, accept the next live price update.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.gammaswap.com/developers/getting-started/clients.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
