API Quick Start
Get up and running with the Trading Platform API in under 10 minutes. This guide covers authentication, your first request, and response handling.
Prerequisites
You need a Trading Platform account with API access enabled. Go to Settings → API Access to generate your API keys.
Base URL
All API requests are made to:
https://api.tradingplatform.com/v1For sandbox/testing:
https://sandbox.api.tradingplatform.com/v1Authentication
The Trading Platform API uses API keys for authentication. Every request must include your API key in the headers.
Getting Your API Keys
- Log into your Trading Platform account
- Navigate to Settings → API Access
- Click Generate New API Key
- Select permissions:
- Read - View account data and market information
- Trade - Place and manage orders
- Copy and securely store your API Key and Secret
Security Warning
Your API Secret is only shown once. Store it securely. Never commit API keys to version control or share them publicly.
Authentication Headers
Include these headers with every request:
X-API-Key: your_api_key_here
X-API-Signature: computed_hmac_signature
X-API-Timestamp: unix_timestamp_msComputing the Signature
The signature is an HMAC-SHA256 hash of the request payload. Here's how to compute it:
// TypeScript Example
import crypto from 'crypto';
function createSignature(
apiSecret: string,
timestamp: string,
method: string,
path: string,
body: string = ''
): string {
const message = timestamp + method.toUpperCase() + path + body;
return crypto
.createHmac('sha256', apiSecret)
.update(message)
.digest('hex');
}# Python Example
import hmac
import hashlib
def create_signature(
api_secret: str,
timestamp: str,
method: str,
path: str,
body: str = ''
) -> str:
message = f"{timestamp}{method.upper()}{path}{body}"
return hmac.new(
api_secret.encode(),
message.encode(),
hashlib.sha256
).hexdigest()Your First Request
Let's make a simple request to get your account information. This confirms your authentication is working correctly.
Get Account Information
curl -X GET "https://api.tradingplatform.com/v1/account" \
-H "X-API-Key: your_api_key" \
-H "X-API-Signature: computed_signature" \
-H "X-API-Timestamp: 1704067200000"Successful Response
{
"success": true,
"data": {
"id": "acc_123456789",
"email": "trader@example.com",
"balance": 10000.00,
"equity": 10250.50,
"margin_used": 500.00,
"margin_free": 9750.50,
"margin_level": 2050.10,
"currency": "USD",
"leverage": "1:100",
"created_at": "2025-01-01T00:00:00Z"
},
"timestamp": "2026-01-04T12:00:00Z"
}Response Format
All API responses follow a consistent format for easy parsing.
Success Response
{
"success": true,
"data": { ... }, // Response payload
"timestamp": "ISO8601", // Server timestamp
"request_id": "string" // Unique request identifier
}Error Response
{
"success": false,
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid or expired",
"details": { ... } // Additional error context
},
"timestamp": "ISO8601",
"request_id": "string"
}Common Error Codes
| Code | HTTP Status | Description |
|---|---|---|
| INVALID_API_KEY | 401 | API key is missing or invalid |
| INVALID_SIGNATURE | 401 | Signature computation incorrect |
| TIMESTAMP_EXPIRED | 401 | Request timestamp too old (>30s) |
| PERMISSION_DENIED | 403 | API key lacks required permission |
| RATE_LIMITED | 429 | Too many requests |
| INSUFFICIENT_FUNDS | 400 | Not enough margin for trade |
| INVALID_SYMBOL | 400 | Trading instrument not found |
| MARKET_CLOSED | 400 | Market is not open for trading |
Rate Limiting
API requests are rate limited to ensure fair usage and system stability.
| Endpoint Type | Limit | Window |
|---|---|---|
| Public (market data) | 120 requests | Per minute |
| Private (account) | 60 requests | Per minute |
| Trading (orders) | 30 requests | Per minute |
Rate limit headers are included in every response:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1704067260SDK Installation
We provide official SDKs for popular languages. Use them to simplify authentication and request handling.
TypeScript/JavaScript
npm install @tradingplatform/sdk
# or
yarn add @tradingplatform/sdkimport { TradingClient } from '@tradingplatform/sdk';
const client = new TradingClient({
apiKey: process.env.API_KEY,
apiSecret: process.env.API_SECRET,
sandbox: true // Use sandbox environment
});
// Get account info
const account = await client.account.get();
console.log(account.balance);
// Get positions
const positions = await client.positions.list();
// Place an order
const order = await client.orders.create({
symbol: 'EURUSD',
side: 'buy',
type: 'market',
quantity: 0.1,
stopLoss: 1.0950,
takeProfit: 1.1100
});Python
pip install tradingplatform-sdkfrom tradingplatform import TradingClient
client = TradingClient(
api_key=os.environ['API_KEY'],
api_secret=os.environ['API_SECRET'],
sandbox=True
)
# Get account info
account = client.account.get()
print(f"Balance: {account.balance}")
# Get positions
positions = client.positions.list()
# Place an order
order = client.orders.create(
symbol='EURUSD',
side='buy',
type='market',
quantity=0.1,
stop_loss=1.0950,
take_profit=1.1100
)Testing with Sandbox
Always test your integration in the sandbox environment before going live.
Sandbox Features
- Virtual funds - $100,000 demo balance
- Real market data - Live prices with simulated execution
- Same API - Identical endpoints and responses
- No risk - Perfect for development and testing
Best Practice
Use environment variables for API credentials and a configuration flag to switch between sandbox and production environments.
Quick Reference
Common API endpoints you'll use frequently:
| Action | Method | Endpoint |
|---|---|---|
| Get account | GET | /v1/account |
| List positions | GET | /v1/positions |
| List orders | GET | /v1/orders |
| Create order | POST | /v1/orders |
| Cancel order | DELETE | /v1/orders/:id |
| Get market price | GET | /v1/market/:symbol/price |
| Get candles | GET | /v1/market/:symbol/candles |
Next Steps
Now that you've made your first API request, explore these topics:
- API Endpoints - Complete endpoint reference
- Code Examples - Ready-to-use code samples
- Webhooks - Real-time event notifications
- Technical FAQ - Common questions answered
Risk Disclosure
Automated trading via API carries the same risks as manual trading. Test thoroughly in sandbox before deploying to production. Never trade with money you cannot afford to lose.