Articles in this section

automated-trading-api.html









Automated Trading API Documentation


Automated Trading API Documentation

Overview

The Automated Trading API provides programmatic access to place, manage, and monitor trading orders in real-time. The API supports both REST endpoints for order management and WebSocket connections for real-time updates.

Getting Started

API Access

  • API Key: Unique identifier for authentication
  • Base URL: https://waf.trader2b.com/automatedTrades
  • WebSocket URL: wss://waf.trader2b.com

Quick Start

  1. Obtain your API key from your account settings
  2. Use the API key in the X-API-Key header
  3. Start with the /destinations endpoint
  4. Place orders using the /orders endpoint
  5. Connect to WebSocket for live updates

API Endpoints

Authentication

All requests require this header:

X-API-Key: your-api-key-here

1. Place Order – POST /orders

{
  "symbol": "AAPL",
  "side": "Buy",
  "quantity": 100,
  "orderType": "Limit",
  "timeInForce": "Day",
  "price": 150.50
}

2. Get Orders – GET /orders?page=1&pageSize=50&symbol=AAPL

Retrieves your order history with optional filters.

3. Get Positions – GET /positions?onlyOpenPositions=true

Returns your current trading positions.

4. Cancel Order – DELETE /orders/{orderId}

5. Update Order – PUT /orders/{orderId}

WebSocket Real-Time Updates

Connect to wss://waf.trader2b.com and authenticate:

socket.emit('api_key_login', {
  apiKey: 'your-api-key-here'
});

socket.on('api_key_auth_success', (data) => {
  console.log('Authenticated:', data);
});

Event Listeners

socket.on('order_update', (data) => console.log('Order update:', data));
socket.on('position_update', (data) => console.log('Position update:', data));

Code Examples

Node.js

const axios = require('axios');
// (Node.js code snippet as above)

Python

import requests
# (Python code snippet as above)

Java

import java.net.http.HttpClient;
// (Java code snippet as above)

C#

using System.Net.Http;
// (C# code snippet as above)

Advanced Features

OCO Orders

{
  "symbol": "TSLA",
  "side": "Buy",
  "quantity": 10,
  "orderType": "Limit",
  "timeInForce": "OCO",
  "price": 200.00,
  "stopLoss": 180.00,
  "takeProfit": 220.00
}

Rate Limiting

  • 10 requests/sec per API key
  • 5 WebSocket connections/API key
  • 100 orders/minute limit

Error Handling

if (error.response?.status === 401) console.log("Unauthorized");
if (error.response?.status === 400) console.log("Bad Request");

Support and Best Practices

  • Validate responses before processing
  • Use WebSocket for real-time updates
  • Implement exponential backoff for retries
  • Rotate API keys periodically
  • Use HTTPS for secure communication

Order Status Codes

  • 0 – New
  • 1 – Partially Filled
  • 2 – Filled
  • 4 – Cancelled
  • 8 – Rejected

Documentation and Testing

Visit the interactive docs at: https://waf.trader2b.com/api-docs


Was this article helpful?

Related articles

Leave a Reply

This product is currently unavailable in your region