GX CoreAPI Servers

API Servers

GX Core exposes three API interfaces for different use cases: a REST API for standard operations, a WebSocket server for real-time streaming, and an EVM JSON-RPC endpoint for smart contract interaction.


REST API (Port 4001)

The REST API is the primary interface for placing orders, querying account state, and retrieving market data. It is built on axum (Rust async HTTP framework) and follows a format compatible with common DEX indexer standards.

Endpoints

EndpointMethodDescription
/healthGETHealth check — returns 200 if the node is operational
/v1/heightGETCurrent block height
/v1/perpetualMarketsGETAll available perpetual markets with configuration
/v1/orderbooks/perpetualMarket/:tickerGETCurrent order book for a specific market
/v1/addresses/:address/subaccountNumber/:nGETAccount details: balances, positions, margin, PnL
/v1/ordersPOSTPlace a new order (EIP-712 signed body)
/v1/orders/cancelPOSTCancel an existing order (EIP-712 signed body)
/v1/fillsGETFill history for an address
/v1/trades/perpetualMarket/:tickerGETRecent trades for a specific market
/metricsGETPrometheus-compatible metrics

Authentication

All state-changing endpoints (POST /v1/orders, POST /v1/orders/cancel, POST /v1/withdraw) require an EIP-712 typed data signature in the request body. The signature is verified against the sender’s Ethereum address.

For programmatic access, API key authentication via HMAC-SHA256 is also supported, enabling high-frequency trading bots to submit orders without per-request wallet signing.

Rate Limiting

TierRequests/secDescription
Default100Unauthenticated read endpoints
Authenticated1,000Signed requests from verified addresses
API Key10,000HMAC-authenticated programmatic access

Example: Place an Order

curl -X POST https://api.gx.exchange/v1/orders \
  -H "Content-Type: application/json" \
  -d '{
    "market": "BTC-USD",
    "side": "buy",
    "size": "1.0",
    "price": "67400",
    "type": "limit",
    "timeInForce": "GTC",
    "signature": "0x...",
    "address": "0x..."
  }'

Example: Get Order Book

curl https://api.gx.exchange/v1/orderbooks/perpetualMarket/BTC-USD

Response:

{
  "bids": [
    { "price": "67400", "size": "2.5" },
    { "price": "67390", "size": "5.0" }
  ],
  "asks": [
    { "price": "67410", "size": "1.8" },
    { "price": "67420", "size": "3.2" }
  ]
}

WebSocket Server (Port 4000)

The WebSocket server provides real-time streaming of order book updates, trades, positions, and account state changes. It is designed for low-latency consumption by trading interfaces and bots.

Channels

ChannelDescriptionSubscription Message
orderbookReal-time order book deltas per market{"type": "subscribe", "channel": "orderbook", "market": "BTC-USD"}
tradesMatched trades as they occur{"type": "subscribe", "channel": "trades", "market": "BTC-USD"}
positionsAccount position updates (authenticated){"type": "subscribe", "channel": "positions", "address": "0x..."}
ordersOrder status changes (authenticated){"type": "subscribe", "channel": "orders", "address": "0x..."}
candlesOHLCV candle updates{"type": "subscribe", "channel": "candles", "market": "BTC-USD", "interval": "1m"}

Connection

const ws = new WebSocket("wss://ws.gx.exchange");
 
ws.onopen = () => {
  ws.send(JSON.stringify({
    type: "subscribe",
    channel: "orderbook",
    market: "BTC-USD"
  }));
};
 
ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  // Process real-time orderbook updates
};

Message Format

All WebSocket messages are JSON-encoded. Updates include a sequence number for gap detection:

{
  "channel": "orderbook",
  "market": "BTC-USD",
  "sequence": 42,
  "data": {
    "bids": [["67400", "2.5"]],
    "asks": [["67410", "1.8"]]
  }
}

EVM JSON-RPC (Port 3001)

The EVM JSON-RPC endpoint provides standard Ethereum JSON-RPC compatibility for the GX EVM execution environment. Any Ethereum tooling (MetaMask, Hardhat, Foundry, ethers.js) can connect to this endpoint.

Supported Methods

MethodDescription
eth_chainIdReturns the GX EVM chain ID
eth_blockNumberLatest block number
eth_getBalanceAccount GX balance
eth_getTransactionCountAccount nonce
eth_sendRawTransactionSubmit a signed EVM transaction
eth_callRead-only contract call
eth_estimateGasEstimate gas for a transaction
eth_getTransactionReceiptTransaction receipt with logs
eth_getLogsQuery event logs
eth_getBlockByNumberBlock data by number
eth_getCodeContract bytecode at address

Connection

# Using cast (Foundry)
cast chain-id --rpc-url https://rpc.gx.exchange
 
# Using curl
curl -X POST https://rpc.gx.exchange \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

Port Summary

PortProtocolService
4001HTTP (REST)GX Core API — orders, markets, accounts
4000WebSocketReal-time streaming — orderbook, trades, positions
3001HTTP (JSON-RPC)GX EVM — Ethereum-compatible RPC
9000TCPP2P networking — validator communication