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
| Endpoint | Method | Description |
|---|---|---|
/health | GET | Health check — returns 200 if the node is operational |
/v1/height | GET | Current block height |
/v1/perpetualMarkets | GET | All available perpetual markets with configuration |
/v1/orderbooks/perpetualMarket/:ticker | GET | Current order book for a specific market |
/v1/addresses/:address/subaccountNumber/:n | GET | Account details: balances, positions, margin, PnL |
/v1/orders | POST | Place a new order (EIP-712 signed body) |
/v1/orders/cancel | POST | Cancel an existing order (EIP-712 signed body) |
/v1/fills | GET | Fill history for an address |
/v1/trades/perpetualMarket/:ticker | GET | Recent trades for a specific market |
/metrics | GET | Prometheus-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
| Tier | Requests/sec | Description |
|---|---|---|
| Default | 100 | Unauthenticated read endpoints |
| Authenticated | 1,000 | Signed requests from verified addresses |
| API Key | 10,000 | HMAC-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-USDResponse:
{
"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
| Channel | Description | Subscription Message |
|---|---|---|
orderbook | Real-time order book deltas per market | {"type": "subscribe", "channel": "orderbook", "market": "BTC-USD"} |
trades | Matched trades as they occur | {"type": "subscribe", "channel": "trades", "market": "BTC-USD"} |
positions | Account position updates (authenticated) | {"type": "subscribe", "channel": "positions", "address": "0x..."} |
orders | Order status changes (authenticated) | {"type": "subscribe", "channel": "orders", "address": "0x..."} |
candles | OHLCV 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
| Method | Description |
|---|---|
eth_chainId | Returns the GX EVM chain ID |
eth_blockNumber | Latest block number |
eth_getBalance | Account GX balance |
eth_getTransactionCount | Account nonce |
eth_sendRawTransaction | Submit a signed EVM transaction |
eth_call | Read-only contract call |
eth_estimateGas | Estimate gas for a transaction |
eth_getTransactionReceipt | Transaction receipt with logs |
eth_getLogs | Query event logs |
eth_getBlockByNumber | Block data by number |
eth_getCode | Contract 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
| Port | Protocol | Service |
|---|---|---|
| 4001 | HTTP (REST) | GX Core API — orders, markets, accounts |
| 4000 | WebSocket | Real-time streaming — orderbook, trades, positions |
| 3001 | HTTP (JSON-RPC) | GX EVM — Ethereum-compatible RPC |
| 9000 | TCP | P2P networking — validator communication |