Quick Start
This guide creates the SDK clients, reads exchange data, submits a signed order, and subscribes to live updates.
1. Install the SDK
npm install @gammaswap/v2-exchange-sdk ethers2. Configure the environment
EXCHANGE_API_URL=https://exchange-api.gammaswap.com/api
MARKET_WS_URL=wss://exchange-api.gammaswap.com/ws/
ORACLE_WS_URL=wss://exchange-api.gammaswap.com/oracle-ws/
CHAIN_ID=84532
RPC_URL=https://your-rpc-provider.example
PRIVATE_KEY=0x...Keep private keys in a server-side secret manager. Do not include them in frontend bundles or commit them to source control.
3. Read asset metadata
Read-only methods use InfoClient and do not require a wallet.
import { createInfoClient } from "@gammaswap/v2-exchange-sdk";
const info = createInfoClient({
apiUrl: process.env.EXCHANGE_API_URL!,
});
const assetId =
"261336857817713630688382311349658711122006440411137";
const asset = await info.getAsset(assetId);
console.log(asset);Example response:
4. Load an order-book snapshot
Example response:
5. Create a signed exchange client
6. Place an order
Order input conventions:
side: false
Buy
side: true
Sell
price
Human decimal string with up to one decimal place
size
Human decimal string with up to two decimal places
timeInForce
Optional; defaults to GTC
nonce
Optional; generated by the SDK
Example response:
7. Subscribe to market updates
Load the REST order-book snapshot before applying live updates.
When the subscription is no longer needed:
8. Subscribe to oracle prices
When the subscription is no longer needed:
9. Create a deposit client
Deposits communicate directly with onchain contracts.
Check the connected wallet’s settlement-token balance:
Before submitting a deposit, approve the required spender using the relevant deposit-ledger or Permit2 approval method.
Next steps
Use
InfoClientto read balances, positions, books, and resolutions.Use
ExchangeClientto place orders, cancel orders, claim, and withdraw.Use an agent wallet to separate automated signing from the master wallet.
Use
DepositClientfor token approvals and deposits.Use the WebSocket clients for real-time market and oracle updates.
Last updated