Skip to main content

TypeScript: @gainstrade/api

Node 20 needs a WebSocket implementation passed to client.websocket({ WebSocket }) (the ws package); Node 22+ and browsers use the built-in one. A client signs for the public Diamond of its chain. Pointed at another deployment through baseUrl (staging, a preview environment, a self-hosted API), pass that deployment’s domain as signingChain: { chainId, diamond }, the values GET /v1/{chain} reports there; without it, a deployment whose Diamond differs is refused with SIGNING_CHAIN_MISMATCH before any request is signed. client.signingChain() returns the domain in use. Worked examples live in the monorepo under miniapps/trading-api-examples: a first trade end to end, a resting-order market maker on the WebSocket, a TradingView webhook receiver, a public-data tape, and the Hyperliquid Python SDK against the facade.

Other languages

The contract is https://api.gains.trade/openapi.json (OpenAPI 3.1). Generate a client and add the signing helper from the Authentication page, which is under forty lines with any EIP-712 library. A published gains-api package on PyPI follows the mainnet release; until then generate from the spec.

CCXT

A CCXT adapter (gains) is planned on top of this API so bots and MCP servers that already speak CCXT get Gains without custom code. Track it on the changelog.

Hyperliquid SDKs

If you already use the official Hyperliquid Python SDK or @nktkas/hyperliquid, point them at https://api.gains.trade/hl/{chain} and read the compatibility page for what changes. The Python SDK’s Info client (meta, l2Book, allMids, clearinghouseState, openOrders) is verified against the facade as is; an SDK given a custom base URL signs L1 actions as testnet, and the facade accepts both phantom-agent sources.