Documentation

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/v1

For sandbox/testing:

https://sandbox.api.tradingplatform.com/v1

Authentication

The Trading Platform API uses API keys for authentication. Every request must include your API key in the headers.

Getting Your API Keys

  1. Log into your Trading Platform account
  2. Navigate to Settings → API Access
  3. Click Generate New API Key
  4. Select permissions:
    • Read - View account data and market information
    • Trade - Place and manage orders
  5. 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_ms

Computing 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

CodeHTTP StatusDescription
INVALID_API_KEY401API key is missing or invalid
INVALID_SIGNATURE401Signature computation incorrect
TIMESTAMP_EXPIRED401Request timestamp too old (>30s)
PERMISSION_DENIED403API key lacks required permission
RATE_LIMITED429Too many requests
INSUFFICIENT_FUNDS400Not enough margin for trade
INVALID_SYMBOL400Trading instrument not found
MARKET_CLOSED400Market is not open for trading

Rate Limiting

API requests are rate limited to ensure fair usage and system stability.

Endpoint TypeLimitWindow
Public (market data)120 requestsPer minute
Private (account)60 requestsPer minute
Trading (orders)30 requestsPer minute

Rate limit headers are included in every response:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 45
X-RateLimit-Reset: 1704067260

SDK 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/sdk
import { 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-sdk
from 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:

ActionMethodEndpoint
Get accountGET/v1/account
List positionsGET/v1/positions
List ordersGET/v1/orders
Create orderPOST/v1/orders
Cancel orderDELETE/v1/orders/:id
Get market priceGET/v1/market/:symbol/price
Get candlesGET/v1/market/:symbol/candles

Next Steps

Now that you've made your first API request, explore these topics:

⚠️

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.