Welcome to Tradelocker Streams API, designed to provide seamless and efficient live data streaming for third parties using the Tradelocker platform.
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, establish a WebSocket connection to Tradelocker Streams API using the Socket.IO client library. Once connected, the server will immediately begin streaming an initial set of data. You must send the developer-api-key header.
Getting a Streams API token for an account
Call the new auth endpoint on our Tradelocker Backend API which will return Streams API JWT tokens for all of the user's accounts. You should not send the developer-api-key header for this request.
Subscribing to an account
Subscribe to the account using the JWT, the account ID, and the Brand ID (Server name). Use Socket.IO's ACK functionality. You will receive responses regarding successful or unsucessful subscriptions.
Initial Data Synchronization
When the account subscription connection is first established, the API sends a stream of messages containing the current state of the user's accounts, positions, and open orders. Once all the initial data has been sent, you will receive a special message type: Property name: SyncEnd. This message indicates that the initial synchronization is complete, and the API will only send updates for new events or changes in the data.
Streams API 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.
Property: messages are used for special signals. Property message with name: SyncEnd 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.
Position: Updates on opening or modifying 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.
/streams-api/streams-api/socket.iowebsocketDevelopment server for Tradelocker Backend API.
Production server for Tradelocker Streams API.
Development server for Tradelocker Streams API.
Available only on servers:
Accepts the following message:
Combination of the user's email, password and server
{
"email": "[email protected]",
"password": "Password1!",
"server": "BAPIA"
}
Socket.IO event stream
Subscribe to this event to receive all updates for accounts.
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",
"brandId": "BAPIA",
"userId": "4f78705c-d09e-4fa8-9744-7a87d81b4327"
}
{
"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",
"brandId": "BAPIA",
"userId": "4f78705c-d09e-4fa8-9744-7a87d81b4327"
}
{
"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",
"side": "BUY",
"fee": "0",
"swaps": "0",
"brandId": "BAPIA",
"userId": "4f78705c-d09e-4fa8-9744-7a87d81b4327"
}
{
"type": "ClosePosition",
"accountId": "L#775077",
"positionId": "144115188076313663",
"closePrice": "0.62947",
"closeDateTime": "2025-01-27T13:43:53.987Z",
"brandId": "BAPIA",
"userId": "4f78705c-d09e-4fa8-9744-7a87d81b4327"
}
Socket.IO event subscriptions receives messages for SUBSCRIBE and UNSUBSCRIBE to an account stream.
Socket.IO event that handles subscription actions with acknowledgment responses.
Available only on servers:
Accepts one of the following messages:
{
"action": "SUBSCRIBE",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30"
}
{
"action": "UNSUBSCRIBE",
"accountId": "L#737031",
"brandId": "BAPIA"
}
Events for disconnect or other connection errors.
Available only on servers:
Accepts one of the following messages:
{
"status": "ok",
"message": "string"
}
General status message for updates and errors
{
"status": "ok",
"code": "connected",
"message": "Successfully connected to the streams socket server."
}
{
"status": "ok",
"code": "disconnected",
"message": "Disconnect initiated."
}
{
"status": "ok",
"code": "shutdown",
"message": "Streams Socket Service shutting down, disconnecting."
}
{
"status": "error",
"code": "unauthorized.invalidApiKey",
"message": "Invalid API key provided, make sure header developer-api-key is valid."
}
{
"status": "error",
"code": "unknown",
"message": "Unknown runtime error."
}
{
"status": "ok",
"code": "connected",
"message": "Connected to account BAPIA#L#737031",
"remainingRequests": 29
}
The account status message contains real time TradeLocker account status:
General status message for updates and errors
ACK Status messages for subscription actions
Combination of the user's email, password and server
Error acknowledgment for subscription actions