API Overview

The GX Exchange API provides programmatic access to the GX Chain L1 decentralized exchange. It supports perpetual futures trading, spot markets, real-time market data streaming, and on-chain asset management through three complementary interfaces.

Architecture

InterfaceProtocolPortDescription
REST APIHTTPS4001Market data queries and authenticated exchange actions
WebSocketWSS4000Real-time streaming of orderbooks, trades, fills, and account events
EVM JSON-RPCHTTPS3001Standard eth_* methods for GX EVM interaction

Base URLs

EnvironmentRESTWebSocketEVM RPC
Mainnethttps://api.gx.exchangewss://api.gx.exchange/wshttps://rpc.gx.exchange
Testnethttps://api.gx-exchange-testnet.xyzwss://api.gx-exchange-testnet.xyz/wshttps://rpc.gx-exchange-testnet.xyz
Localhttp://localhost:4001ws://localhost:4000http://localhost:3001

All connections require TLS 1.3 on mainnet and testnet.

Public Stats API

The Stats API provides protocol-level analytics data without authentication. Used by stats.gx.exchange, CoinGecko, DeFiLlama, and third-party dashboards.

Base URL: https://api.gx.exchange/stats

EndpointMethodDescription
/stats/total_usersGETTotal unique accounts
/stats/total_usd_volumeGET24-hour total trading volume (USD)
/stats/total_depositsGETTotal collateral deposited across all accounts
/stats/total_withdrawalsGETTotal withdrawn
/stats/cumulative_usd_volumeGETCumulative volume over time (chart data)
/stats/daily_usd_volumeGETDaily volume over time (chart data)
/stats/open_interestGETOpen interest per market with mark price
/stats/funding_rateGETCurrent funding rate per market
/stats/daily_unique_usersGETDaily unique users (chart data)
/stats/cumulative_usersGETCumulative user growth (chart data)
/stats/asset_ctxsGETAll market contexts: price, OI, volume, funding

Example:

curl https://api.gx.exchange/stats/total_users
# {"total_users": 15432}
 
curl https://api.gx.exchange/stats/asset_ctxs
# [{"coin":"BTC-USD","mark_price":65000,"open_interest":1234567,"volume_24h":98765432,...}]

No authentication required. Rate limited to 100 requests/minute per IP.

Request Format

All REST requests and responses use JSON. Set the Content-Type: application/json header on every request that includes a body.

The API exposes two primary REST endpoints:

  • POST /info — Public data queries. No authentication required. The type field in the request body determines which data is returned.
  • POST /exchange — Authenticated exchange actions (orders, cancels, transfers). Requires an EIP-712 signature.

Additional RESTful endpoints are available for specific resources:

MethodPathAuthDescription
GET/v1/healthNoneHealth check
GET/v1/heightNoneCurrent block height
GET/v1/perpetualMarketsNoneList all perpetual markets
GET/v1/orderbooks/perpetualMarket/:tickerNonePerpetual orderbook
GET/v1/addresses/:address/subaccountNumber/:nNoneSubaccount state
POST/v1/ordersEIP-712Place an order
POST/v1/orders/cancelEIP-712Cancel an order
GET/v1/fillsNoneRecent fills
GET/v1/trades/perpetualMarket/:tickerNoneRecent trades
GET/v1/spot/marketsNoneList spot markets
GET/v1/spot/orderbook/:pairNoneSpot orderbook
POST/v1/api-keysEIP-712Create API key
GET/v1/api-keys/:addressHMACList API keys
POST/v1/api-keys/:api_key/revokeHMACRevoke API key

Authentication Model

GX Exchange uses EIP-712 typed data signatures for all authenticated exchange operations. Every exchange action is signed with an Ethereum private key, providing cryptographic proof of authorization without transmitting secrets.

Direct Wallet Signing

Sign each request with the private key of the trading address. This is the simplest approach but requires the main wallet key to be available at signing time.

API Wallets (Agent Delegation)

For automated trading, authorize a secondary keypair (an “agent”) to sign on your behalf:

  1. Generate a fresh Ethereum keypair
  2. Authorize it via the approveAgent exchange action signed by your main wallet
  3. Use the agent’s private key for all subsequent request signatures
  4. Revoke the agent at any time

See Nonces and API Wallets and Signing for implementation details.

HMAC-SHA256 Authentication (API Keys)

API key endpoints use a separate HMAC-SHA256 signing scheme with three headers:

HeaderDescription
GX-API-KEYYour public API key (e.g., gx_k_7f3a...)
GX-API-SIGNBase64-encoded HMAC-SHA256 signature
GX-API-TIMESTAMPUnix epoch timestamp in seconds

The signature is computed as:

message   = timestamp + method + path + body
signature = base64( HMAC-SHA256( secret, message ) )

The server enforces a 30-second replay window on the timestamp.

EIP-712 Domain

All EIP-712 signatures use the following domain:

FieldValue
name"GXExchange"
version"1"
chainId42069
verifyingContract0x0000000000000000000000000000000000000000

Response Format

Successful responses return HTTP 200 with a JSON body.

Exchange endpoint responses include a status field:

{ "status": "ok", "response": { "type": "order", "data": { "statuses": [...] } } }
{ "status": "err", "response": "Insufficient margin" }

Info endpoint responses return the requested data directly as the response body.

Quick Start

import { GxClient } from "@gx-exchange/sdk";
 
const client = new GxClient();
await client.connect("https://api.gx.exchange");
 
// Public data -- no auth required
const mids = await client.getAllMids();
console.log("BTC mid:", mids["BTC"]);
 
// Authenticated trading -- requires wallet
client.setWallet("0xYourPrivateKey...");
const result = await client.placeOrder([{
  coin: "BTC",
  isBuy: true,
  sz: 0.001,
  limitPx: 60000,
  tif: "Gtc",
  reduceOnly: false,
}]);
from gx_exchange.info import Info
from gx_exchange.utils.constants import MAINNET_API_URL
 
info = Info(MAINNET_API_URL, skip_ws=True)
mids = info.all_mids()
print(f"BTC mid: {mids.get('BTC')}")

SDKs

LanguagePackageInstall
TypeScript@gx-exchange/sdknpm install @gx-exchange/sdk
Pythongx-exchange-python-sdkpip install gx-exchange-python-sdk
Rustgx_rust_sdkcargo add gx_rust_sdk

Source: github.com/GX-EXCHANGE