API Reference

FxSocket exposes your MT4 and MT5 terminals through a REST API and WebSocket streams. All endpoints return JSON. Authenticate with a Bearer token in the Authorization header.

Base URLhttps://api.fxsocket.com

API Tester

Try a live request. Enter your API key and select an endpoint.

Authentication

HeaderAuthorization: Bearer sk_live_xxx

All requests require a Bearer token. Create API keys from your dashboard. Keys can be scoped to read-only, trade, or full access.

Account

GET/v1/account

Returns account balance, equity, margin, free margin, and currency. Use this to monitor account health or display P&L.

Response
{
  "id": "acc_8xKm2",
  "balance": 10000.00,
  "equity": 10234.50,
  "margin": 120.40,
  "free_margin": 10114.10,
  "currency": "USD"
}
GET/v1/accounts

List all connected accounts under your API key. Returns account IDs, broker info, platform type (MT4/MT5), and connection status.

Response
[{
  "id": "acc_8xKm2",
  "broker": "ICMarkets",
  "platform": "MT5",
  "status": "connected"
}]

Trading

GET/v1/positions

List all open positions. Returns symbol, direction, volume, open price, current profit, and stop loss / take profit levels.

Response
[{
  "id": "pos_3nF8x",
  "symbol": "EURUSD",
  "type": "BUY",
  "volume": 0.1,
  "open_price": 1.08342,
  "sl": 1.0800,
  "tp": 1.0900,
  "profit": 23.50
}]
POST/v1/orders

Create a market or pending order. Specify symbol, type (BUY, SELL, BUY_LIMIT, SELL_LIMIT, BUY_STOP, SELL_STOP), volume, and optional SL/TP.

Response
{
  "id": "ord_2aF9xK",
  "symbol": "EURUSD",
  "type": "BUY",
  "volume": 0.1,
  "price": 1.08342,
  "status": "filled"
}
PATCH/v1/orders/{id}

Modify an existing order. Update stop loss, take profit, or pending order price. Cannot change symbol or direction.

Response
{
  "id": "ord_2aF9xK",
  "sl": 1.0720,
  "tp": 1.0950,
  "updated": true
}
DELETE/v1/orders/{id}

Close an open position or cancel a pending order. Returns the closing price and realized profit.

Response
{
  "id": "ord_2aF9xK",
  "status": "closed",
  "close_price": 1.08501,
  "profit": 15.90
}

Market Data

GET/v1/quotes/{symbol}

Get the current bid/ask price for a symbol. For real-time streaming, use the WebSocket endpoint instead.

Response
{
  "symbol": "EURUSD",
  "bid": 1.08340,
  "ask": 1.08342,
  "spread": 0.2,
  "time": "2026-04-02T14:30:00.123Z"
}
GET/v1/candles/{symbol}

Fetch historical OHLCV candlestick data. Supports all standard timeframes: M1, M5, M15, M30, H1, H4, D1, W1, MN. Specify date range with from/to parameters.

Response
{
  "symbol": "EURUSD",
  "timeframe": "H1",
  "candles": [{
    "time": "2026-04-02T14:00:00Z",
    "open": 1.0830,
    "high": 1.0841,
    "low": 1.0828,
    "close": 1.0834,
    "volume": 1243
  }]
}
GET/v1/history

Retrieve closed trade and order history. Filter by date range, symbol, or order type. Includes profit, commission, and swap.

Response
{
  "trades": [{
    "id": "trd_x9Km3",
    "symbol": "XAUUSD",
    "type": "BUY",
    "volume": 0.05,
    "profit": 45.20,
    "closed_at": "2026-04-02T14:30:00Z"
  }],
  "total": 142
}

WebSocket Streams

WSwss://ws.fxsocket.com/v1/stream

Real-time streaming connection. Subscribe to price quotes, order updates, and account changes. Authenticate via the Authorization header. No rate limits on WebSocket connections.

Response
// Price update
{
  "type": "quote",
  "data": {
    "symbol": "EURUSD",
    "bid": 1.08340,
    "ask": 1.08342,
    "time": "2026-04-02T14:30:00.123Z"
  }
}

// Order update
{
  "type": "order_opened",
  "data": {
    "id": "ord_2aF9xK",
    "symbol": "EURUSD",
    "type": "BUY",
    "volume": 0.1,
    "price": 1.08342
  }
}

SDKs

Official client libraries are available for Python, Node.js, Go, and Rust. Each SDK wraps the REST API and WebSocket streams with language-native interfaces.

  • Python: pip install fxsocket
  • Node.js: npm install fxsocket
  • Go: go get github.com/fxsocket/go
  • Rust: cargo add fxsocket

Rate Limits

REST API requests are limited to 60 requests per second per account. WebSocket connections have no rate limits. If you hit a rate limit, the API returns HTTP 429 with a Retry-After header.

Errors

All errors return a JSON body with error and message fields. HTTP status codes follow standard conventions: 400 for bad requests, 401 for auth failures, 404 for missing resources, 429 for rate limits, and 500 for server errors.