DNS
Common DNS syntax -backend-<network>.gains.trade
- Arbitrum: https://backend-arbitrum.gains.trade
- Base: https://backend-base.gains.trade
- Polygon: https://backend-polygon.gains.trade
- Sepolia: https://backend-sepolia.gains.trade
- Arbitrum WS:
wss://backend-arbitrum.gains.trade - Base WS:
wss://backend-base.gains.trade - Polygon WS:
wss://backend-polygon.gains.trade - Sepolia WS:
wss://backend-sepolia.gains.trade
Backend types
You can find backend return types HEREv10 Update
As of v10, the SDK now offers normalization for both trading variables and trades. Current version: @gainsnetwork/sdk@1.0.0-rc1For most SDK interactions you will need
tradingVariables object. Learn below how to fetch it and transform it to use within SDK.Example: fetching and transforming trading variables
For detailed `/trading-variables` information, see “Common Endpoints” section below
Example: getting all trades for current address
Example: converting TradeContainerBackend to TradeContainer
Example: converting array of FeeBackend to FeeFrontend
Common Endpoints
Trading Variables
Provides main data necessary for opening, closing, and managing trades. Payload also contains all active trades (allTrades).
Request:
GET /trading-variables
Response:
Open Trades
Returns all open trades (matches deprecatedallTrades output from /trading-variables endpoint). Optionally specify trader address for filtering.
Request:
GET /open-tradesGET /open-trades/<address>Response:
User Trading Variables
Provides useful trader specific data, such as pending order IDs and fee tiers. Request:GET /user-trading-variables/<address>
Response:
Historical Trades
Provides all historical trades (open & closed) for a given address Request:GET /personal-trading-history-table/<address>
Provides all open & closed trades in last 24hrs
GET /trading-history-24h
Response (same for both historical endpoints):
Event Stream
As mentioned in Trading Contracts, backend event streams can serve as proxies for on-chain trade events. The stream will publish both unconfirmed and confirmed events. Unconfirmed events are published until the risk a block is reorged is negligible, at which point a confirmed event is sent. For most integrations, only confirmed events (liveEvent) need to be listened to.
Backends also publish structured, post-processed events based on what on-chain event has just taken place. For example, registerTrade provides a full trade struct following the raw event MarketOrderExecuted. This is to limit how much clients need to fetch additional data.
Structure:
liveEvents- raw on-chain events. Payload is identical to on-chain event.registerTrade- trade has been registeredunregisterTrade- trade has been closedupdateTrade- trade SL/TP has been updatedupdateLeverage- trade leverage updated (collateral removed or added)updatePositionSize- trade position size updated (adding to position or partial close)tradingVariables- updated/trading-variablespayloadcurrentBlock- L2 block number for networkcurrentL1Block- L1 block number for networkdeepReorg- Reorg has been detected - refresh datanew-trade-history- New trade history document
