API Documentation
Build trading bots, integrate market data, and manage your account programmatically. TradeGrail provides a REST API and WebSocket feeds for real-time data.
https://api.tradegrail.comWebSocket:
wss://api.tradegrail.com/ws/All requests use HTTPS. HTTP requests are rejected.
Quick Start
# Public endpoint - no authentication required
curl https://api.tradegrail.com/api/markets/tickerscurl https://api.tradegrail.com/api/wallets/balances \ -H "X-API-Key: your_api_key" \ -H "X-API-Secret: your_secret_key"
curl -X POST https://api.tradegrail.com/api/order \ -H "X-API-Key: your_api_key" \ -H "X-API-Secret: your_secret_key" \ -H "Content-Type: application/json" \ -d '{ "pair": "BTC-USDT", "side": "buy", "order_type": "limit", "amount": 0.001, "price": 45000.0 }'
Authentication
TradeGrail supports two authentication methods. API keys are recommended for programmatic access. Public endpoints (market data) do not require authentication.
API Keys (Recommended)
Include your API key and secret in the request headers:
X-API-Key: your_api_key X-API-Secret: your_api_secret
API Key Permissions
| Permission | Description |
|---|---|
read:all | Read balances, orders, trades, history |
write:orders | Place and cancel orders |
write:withdrawals | Create withdrawal requests |
Rate Limits
Rate limits protect the platform and ensure fair usage. Limits vary by endpoint category. When a limit is exceeded, the API returns HTTP 429.
| Category | Limit | Per | Endpoints |
|---|---|---|---|
| Market Data | 500 req/s | IP | Tickers, orderbook, public trades, candles |
| Read-Only | 600 req/min | User | Balances, user orders, user trades, history |
| Trading | 300 req/min | User | Place order, cancel order, API key management |
| Withdrawals | 5 req/min | User | Withdraw, change password |
| Login | 5 req/min | IP | Login, register, password reset |
X-RateLimit-Limit: 300 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 60 Retry-After: 45
Retry-After header for the number of seconds to wait before retrying.
Error Handling
The API uses standard HTTP status codes. Error responses include a JSON body with details.
| Status | Meaning |
|---|---|
200 | Success |
201 | Created (new resource) |
400 | Bad Request - invalid parameters |
401 | Unauthorized - missing or invalid authentication |
403 | Forbidden - insufficient permissions |
429 | Too Many Requests - rate limit exceeded |
500 | Internal Server Error |
{
"error": "Insufficient balance",
"details": "The requested amount exceeds your available balance."
}Market Data
Public endpoints for market data. No authentication required.
Returns 24-hour rolling window statistics for all trading pairs.
[
{
"symbol": "BTC-USDT",
"last_price": 45000.0,
"open_price": 44000.0,
"high_24h": 46000.0,
"low_24h": 43000.0,
"volume_24h": 100.5,
"quote_volume_24h": 4500000.0,
"price_change_percent": 2.27,
"best_bid": 44999.0,
"best_ask": 45001.0,
"num_trades_24h": 250
}
]Returns 24h ticker data for a specific trading pair.
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | string | Yes | Trading pair, e.g. BTC-USDT |
Returns current order book with bids and asks, sorted by best price.
| Name | Type | Required | Description |
|---|---|---|---|
| pair | string | Yes | Trading pair, e.g. BTC-USDT |
{
"bids": [
{ "price": 44999.0, "amount": 1.5 }
],
"asks": [
{ "price": 45001.0, "amount": 2.0 }
]
}Returns recent trades for a given pair.
| Name | Type | Required | Description |
|---|---|---|---|
| pair | string | Optional | Filter by pair, e.g. BTC-USDT |
| limit | integer | Optional | Number of trades (default: 100, max: 1000) |
[
{
"id": "uuid",
"pair": "BTC-USDT",
"price": 45000.0,
"amount": 0.5,
"side": "buy",
"timestamp": 1707000000000
}
]Returns OHLCV (Open-High-Low-Close-Volume) candle data for charts.
| Name | Type | Required | Description |
|---|---|---|---|
| pair | string | Yes | Trading pair, e.g. BTC-USDT |
| Name | Type | Required | Description |
|---|---|---|---|
| interval | string | Optional | 1m, 5m, 15m, 30m, 1h, 4h, 1d (default: 15m) |
| limit | integer | Optional | Number of candles (default: 100, max: 1500) |
[
{
"pair": "BTC-USDT",
"interval": "15m",
"timestamp": 1707000000000,
"open": 45000.0,
"high": 45500.0,
"low": 44500.0,
"close": 45200.0,
"volume": 50.5,
"trades": 125
}
]Returns aggregated fee statistics for the exchange.
[
{
"currency": "USDT",
"total_fees_collected": 1500.50,
"maker_fees": 500.25,
"taker_fees": 1000.25
}
]Trading
Endpoints for placing, cancelling, and querying orders. All trading endpoints require authentication.
Place a new limit or market order. Balance is locked immediately upon placement.
| Field | Type | Required | Description |
|---|---|---|---|
| pair | string | Yes | BTC-USDT or WART-USDT |
| side | string | Yes | buy or sell |
| order_type | string | Yes | limit or market |
| amount | decimal | Yes | Order quantity in base currency |
| price | decimal | Limit only | Price per unit (required for limit orders) |
{
"success": true,
"message": "Order placed and matched successfully",
"order_id": "550e8400-e29b-41d4-a716-446655440000",
"pair": "BTC-USDT",
"side": "buy",
"price": 45000.0,
"amount": 0.5
}Cancel an active or partially filled order. Remaining locked balance is returned.
| Name | Type | Required | Description |
|---|---|---|---|
| pair | string | Yes | Trading pair, e.g. BTC-USDT |
| order_id | uuid | Yes | Order UUID |
{
"success": true,
"message": "Order cancelled and funds unlocked"
}Returns all active and partially filled orders for the authenticated user.
[
{
"id": "uuid",
"pair": "BTC-USDT",
"order_type": "limit",
"side": "buy",
"price": 45000.0,
"amount": 0.5,
"remaining": 0.2,
"status": "partial",
"created_at": 1707000000000
}
]Returns filled and cancelled orders. Last 100 orders.
[
{
"id": "uuid",
"pair": "BTC-USDT",
"side": "buy",
"price": 45000.0,
"amount": 0.5,
"remaining": 0.0,
"status": "filled",
"created_at": 1707000000000
}
]Returns executed trades with fee details for the authenticated user.
[
{
"id": "uuid",
"pair": "BTC-USDT",
"side": "buy",
"price": 45000.0,
"amount": 0.5,
"fee_amount": 22.50,
"fee_currency": "USDT",
"fee_type": "taker",
"timestamp": 1707000000000
}
]Wallet
Endpoints for managing balances, deposit addresses, and withdrawals.
Returns balances for all currencies including available, locked, and network details.
[
{
"currency": "USDT",
"available": 1000.50,
"locked": 50.00,
"total": 1050.50,
"withdrawal_fee": 7.0,
"min_withdrawal": 10.0
}
]Get or generate a deposit address for the specified currency.
| Name | Type | Required | Description |
|---|---|---|---|
| currency | string | Yes | USDT, BTC, or WART |
{
"currency": "USDT",
"address": "TAddr123...",
"network": "TRC20"
}Submit a withdrawal request. Requires 2FA verification if enabled on your account.
| Field | Type | Required | Description |
|---|---|---|---|
| currency | string | Yes | USDT, BTC, or WART |
| amount | decimal | Yes | Withdrawal amount |
| address | string | Yes | Destination address |
| network | string | Yes | TRC20, BEP20, BTC, or WART |
| totp_code | string | If 2FA | 6-digit TOTP code (required if 2FA enabled) |
{
"id": "uuid",
"status": "pending_validation",
"message": "Withdrawal created"
}History
Returns last 100 deposits for the authenticated user.
[
{
"id": 1,
"currency": "USDT",
"amount": 500.0,
"txid": "0x...",
"confirmations": 12,
"created_at": 1707000000000
}
]Returns last 100 withdrawals for the authenticated user.
[
{
"id": "uuid",
"currency": "USDT",
"network": "TRC20",
"amount": 100.0,
"fee": 7.0,
"to_address": "TAddr...",
"state": "confirmed",
"txid": "0x...",
"created_at": 1707000000000
}
]Returns last 100 trading fee records for the authenticated user.
{
"user_id": 84291,
"fees": [
{
"trade_id": "uuid",
"currency": "USDT",
"amount": 22.50,
"fee_type": "taker",
"created_at": 1707000000000
}
],
"total_paid": 450.75
}API Key Management
Create a new API key pair. The secret is only shown once.
| Field | Type | Required | Description |
|---|---|---|---|
| key_name | string | Yes | Label for this key (e.g. "MyBot") |
| permissions | array | Optional | Array of permissions |
{
"id": "uuid",
"api_key": "your_api_key",
"secret_key": "your_api_secret",
"key_name": "MyBot",
"permissions": ["read:all", "write:orders"]
}secret_key immediately. It cannot be retrieved later.
List all API keys for the authenticated user. Secret keys are not returned.
[
{
"id": "uuid",
"key_name": "MyBot",
"api_key_prefix": "xxxxx...",
"permissions": ["read:all"],
"created_at": 1707000000000
}
]Permanently revoke an API key. This action cannot be undone.
| Name | Type | Required | Description |
|---|---|---|---|
| api_key_id | uuid | Yes | API key UUID |
WebSocket API
Real-time data streams via WebSocket. Connect to receive live order book updates, trades, candle data, and user-specific order updates.
wss://api.tradegrail.com/ws/Candles:
wss://api.tradegrail.com/ws/candlesAuthentication is optional. Authenticated connections receive user-specific order updates.
// JavaScript example const ws = new WebSocket("wss://api.tradegrail.com/ws/"); ws.onopen = () => { ws.send(JSON.stringify({ "type": "subscribe", "pair": "BTC-USDT" })); }; ws.onmessage = (event) => { const data = JSON.parse(event.data); console.log(data.type, data.payload); };
Order Book Stream
Receive real-time order book snapshots when orders are placed, filled, or cancelled.
{
"type": "BookUpdate",
"payload": {
"pair": "BTC-USDT",
"bids": [
{ "price": 44999.0, "amount": 1.5 }
],
"asks": [
{ "price": 45001.0, "amount": 2.0 }
],
"sequence": 12345
}
}Trades Stream
Receive real-time trade executions as they happen.
{
"type": "TradesUpdate",
"payload": {
"pair": "BTC-USDT",
"trades": [
{
"id": "uuid",
"price": 45000.0,
"amount": 0.5,
"side": "buy",
"timestamp": 1707000000000
}
]
}
}Candle Stream
Real-time OHLCV candle updates. Connect to wss://api.tradegrail.com/ws/candles.
{
"type": "candle_update",
"pair": "BTC-USDT",
"candle": {
"interval": "15m",
"timestamp": 1707000000000,
"open": 45000.0,
"high": 45500.0,
"low": 44500.0,
"close": 45200.0,
"volume": 50.5,
"trades": 125
}
}User Data Stream
Authenticated connections receive real-time updates about their own orders. Requires authenticated session (browser).
{
"type": "OrderUpdate",
"payload": {
"pair": "BTC-USDT",
"order_id": "uuid",
"status": "filled",
"remaining": 0.0,
"timestamp": 1707000000000
}
}