Welcome to the BrandSocket WebSocket API, designed to provide seamless and efficient live data streaming for brands using the Tradelocker platform. By leveraging the Socket.IO protocol, BrandSocket offers real-time updates and actionable insights, enabling you to make informed and timely decisions.
Compared to traditional REST APIs, which rely on frequent polling to retrieve updates, the WebSocket API maintains an always-on connection. This approach ensures you receive data changes as they happen, reducing latency and improving responsiveness.
Real-time updates - Instantly react to market changes, account status updates, and trade activities.
Efficient resource usage - Maintain a single persistent connection instead of repeatedly querying for updates.
Enhanced decision-making -Leverage live data to optimize trading strategies and outcomes.
Setting Up the Connection
To start streaming data, establish a WebSocket connection to BrandSocket using the Socket.IO client library. Once connected, the server will immediately begin streaming an initial set of data.
Initial Data Synchronization
When the connection is first established, BrandSocket sends a stream of messages containing the current state of your accounts, positions, and open orders. Once all the initial data has been sent, you will receive a special message type: SyncEnd
SyncEnd
message signifies the completion of the initial data synchronization process.
After receiving SyncEnd, the server will only send updates for new events or changes in the data.
BrandSocket sends different types of messages to keep you updated on key events:
AccountStatus: Provides updates about the status of an account, such as changes in balance, margin, or account status.
SyncEnd: Indicates that the initial synchronization of data is complete. After this, only updates will be sent.
Position: Updates on opening or modifying a positions.
ClosePosition: Sent when a position is closed, providing details of the closure, such as time and realized P&L.
OpenOrder: Details about new or updated order, allowing you to track pending trades in real-time.
/brand-socket
/brand-socket/socket.io
websocket
import { io } from 'socket.io-client';
// Configuration
const SERVER_URL = 'wss://api-dev.tradelocker.com';
const NAMESPACE = '/brand-socket';
const BRAND_API_KEY = '<your-brand-api-key>';
const HANDSHAKE_PATH = '/brand-api/socket.io';
const QUERY_PARAM_TYPE = 'LIVE';
// Create a connection to the Socket.IO server
const socket = io(SERVER_URL + NAMESPACE, {
path: HANDSHAKE_PATH, // Custom handshake path
transports: ['websocket'], // Use websocket transport
query: {
type: QUERY_PARAM_TYPE,
},
extraHeaders: {
'brand-api-key': BRAND_API_KEY, // Add custom API key header
},
});
// Event listeners
socket.on('connect', () => {
console.log('Connected to Socket.IO server');
console.log(`Socket ID: ${socket.id}`);
});
socket.on('stream', (data: any) => {
console.log('stream: ', data);
});
// event listener for 'connection' events
socket.on('connection', (data: any) => {
console.error('connection: ', data);
});
socket.on('disconnect', (reason) => {
console.log('Disconnected: ', reason);
});
socket.on('error', (error) => {
console.log('error: ', error);
});
// Disconnect after 30 seconds
setTimeout(() => {
socket.disconnect();
console.log('Disconnected manually');
}, 30000);
To explore the REST API documentation visit https://brand-docs.tradelocker.com/
Production server for BrandSocket API.
Query parameter for environment type.
Development server for BrandSocket API.
Query parameter for environment type.
Socket.IO event stream
Subscribe to this event to receive all updates from BrandSocket server.
Available only on servers:
Accepts one of the following messages:
The account status message contains real time TradeLocker account status:
{
"type": "AccountStatus",
"accountId": "L#706984",
"currency": "USD",
"balance": "9888.95",
"marginAvailable": "3583.45",
"marginUsed": "6305.5",
"equity": "10628.95"
}
{
"type": "Property",
"name": "SyncEnd"
}
{
"type": "OpenOrder",
"accountId": "L#706984",
"instrument": "AUDUSD",
"orderId": "144115188077153593",
"orderType": "MARKET",
"status": "STATUS_FILLED",
"positionId": "144115188076313665",
"price": "0.62956",
"side": "BUY",
"amount": "10",
"lotSize": "100000",
"lastUpdate": "2025-01-27T13:43:57.532Z",
"createdDateTime": "2025-01-27T13:43:57.327Z",
"isOpen": true,
"tif": "IOC",
"trStopOffset": "0",
"averageFilledPrice": "0.62962",
"filledAmount": "10"
}
{
"type": "Position",
"accountId": "L#617509",
"lots": "0.01",
"lotSize": "10",
"units": "0.1",
"instrument": "ETHUSD",
"openPrice": "3299.71",
"openDateTime": "2024-03-19T20:15:51.465Z",
"positionId": "144115188076017329",
"openOrderId": "144115188076017329",
"maintMargin": "3.06485",
"stopLossLimit": "0",
"takeProfitLimit": "0",
"side": "BUY",
"fee": "0",
"swaps": "0"
}
{
"type": "ClosePosition",
"positionId": "144115188076313663",
"closePrice": "0.62947",
"closeDateTime": "2025-01-27T13:43:53.987Z"
}
Events for disconnect or other connection errors.
Available only on servers:
Accepts the following message:
Connection updates and errors
{
"status": "ok",
"message": "string"
}
The account status message contains real time TradeLocker account status:
Connection updates and errors