For the complete documentation index, see llms.txt. This page is also available as Markdown.

Exchange Methods

ExchangeClient signs exchange actions with the configured ethers wallet and submits them to the Exchange HTTP API.

The SDK constructs the EIP-712 action, generates missing nonces, calculates the action hash, creates the signature, and serializes the HTTP request.

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

const wallet = new Wallet(process.env.PRIVATE_KEY!);

const exchange = createExchangeClient({
  apiUrl: "https://exchange-api.gammaswap.com/api",
  wallet,
  chainId: "84532",
});

placeOrder

Places an order signed directly by the configured wallet.

const result = await exchange.placeOrder({
  assetId: "261336857817713630688382311349658711122006440411137",
  epoch: "12",
  side: false,
  price: "99.9",
  size: "10.25",
});

Endpoint:

Response:

Possible status values:

Possible rejection reasons include:

placeAgentOrder

Places an order signed by an approved agent for a master account.

Endpoint:

Response:

The configured wallet is the agent signer. The sender field is the master account that owns the order.

If approvalNonce is omitted, the SDK fetches it through InfoClient.

cancelOrder

Cancels one order signed directly by the configured wallet.

Endpoint:

Response:

Possible status values:

cancelAll

Cancels all orders owned by the configured wallet for an asset and epoch.

Endpoint:

The SDK uses the zero hash internally to request cancel-all.

Response:

cancelAgentOrder

Cancels one master-account order as an approved agent.

Endpoint:

Response:

If approvalNonce is omitted, the SDK fetches it through InfoClient.

cancelAllAgent

Cancels all master-account orders for an asset and epoch as an approved agent.

Endpoint:

Response:

cancelReplaceOrder

Cancels one order and submits a replacement order in the same request.

Endpoint:

Response:

Possible top-level status values:

The replacement must use the same market and side as the cancelled order. Cancel-all is not supported by cancel-and-replace.

cancelReplaceAgentOrder

Cancels and replaces a master-account order as an approved agent.

Endpoint:

Response:

If approvalNonce is omitted, the SDK fetches it through InfoClient.

claim

Claims available funds for a resolved asset epoch.

Endpoint:

Response:

Possible status values:

claimAgent

Claims available funds for a master account as an approved agent.

Endpoint:

Response:

If approvalNonce is omitted, the SDK fetches it through InfoClient.

withdraw

Submits a signed withdrawal request.

Endpoint:

Response:

Possible status values:

If receiver is omitted, it defaults to the configured wallet address.

approveAgent

Approves an agent wallet to sign exchange actions for the master account.

Endpoint:

Response:

Possible status values:

The agent must differ from the configured master wallet.

If approvalNonce is omitted, the SDK creates the required approval value.

revokeAgent

Revokes the master account’s current agent approval.

Endpoint:

Response:

Possible status values:

signAgentApproval

Creates the inner agent-approval signature without submitting an HTTP request.

SDK response:

This is a local signing operation. It does not approve the agent by itself. Use approveAgent to sign and submit the complete agent-approval action.

Available methods

Method
Endpoint or action

placeOrder

POST /orders

placeAgentOrder

POST /orders

cancelOrder

POST /cancels

cancelAll

POST /cancels

cancelReplaceOrder

POST /cancel-replace

cancelAgentOrder

POST /cancels

cancelAllAgent

POST /cancels

cancelReplaceAgentOrder

POST /cancel-replace

claim

POST /claim

claimAgent

POST /claim

withdraw

POST /withdrawals

approveAgent

POST /agents/approve

revokeAgent

POST /agents/revoke

signAgentApproval

Local signing

Last updated