Streams API 1.0.1

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.

Why WebSocket API?

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.

Getting Started

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Message Types

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.

The Socket.IO server configuration:

  • Namespace: /streams-api
  • Handshake path: /streams-api/socket.io
  • Transport: websocket

Servers

  • https://stg.tradelocker.com/backend-apihttpsstaging-tl-api

    Development server for Tradelocker Backend API.

  • wss://api.tradelocker.com/streams-api/socket.iowssproduction

    Production server for Tradelocker Streams API.

  • wss://api-dev.tradelocker.com/streams-api/socket.iowssdevelopment

    Development server for Tradelocker Streams API.

Operations

  • REQUEST /auth/jwt/accounts/tokens

    Operation IDget-tokens

    Available only on servers:

    object

    Accepts the following message:

    Combination of the user's email, password and server

    Message IDuserMessage
    object

    Examples

    REPLY INFORMATION

    REPLY CHANNEL INFORMATION

    Reply will be provided via this designated address: /auth/jwt/accounts/tokens
  • RECEIVE stream

    Socket.IO event stream

    Subscribe to this event to receive all updates for accounts.

    Operation IDstream.subscribe

    Available only on servers:

    Accepts one of the following messages:

    • #0
      Message IDAccountStatus

      The account status message contains real time TradeLocker account status:

      • balance
      • equity
      • marginAvailable
      • marginUsed
      • blockedBalance
      • credit
      object

      Examples

    • #1
      Message IDProperty
      object

      Examples

    • #2
      Message IDOpenOrder
      object

      Examples

    • #3
      Message IDPosition
      object

      Examples

    • #4
      Message IDClosePosition
      object

      Examples

  • REQUEST subscriptions

    Socket.IO event subscriptions receives messages for SUBSCRIBE and UNSUBSCRIBE to an account stream.

    Socket.IO event that handles subscription actions with acknowledgment responses.

    Operation IDsubscriptions.publish

    Available only on servers:

    Accepts one of the following messages:

    • #0

      Subscribe to an account stream

      Message IDAccountSubscribeAction
      object

      Examples

    • #1

      Unsubscribe from an account stream

      Message IDAccountUnsubscribeAction
      object

      Examples

    REPLY INFORMATION

    REPLY CHANNEL INFORMATION

  • RECEIVE connection

    Events for disconnect or other connection errors.

    Operation IDconnection.subscribe

    Available only on servers:

    Accepts one of the following messages:

    • #0

      Connection updates and errors

      Message IDConnectionErrorMessage
      object

      Examples

    • #1

      General status message for updates and errors

      Message IDStatusMessage
      object
        Examples values:
      • {"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}

      Examples

Messages

  • #1
    Message IDAccountStatus

    The account status message contains real time TradeLocker account status:

    • balance
    • equity
    • marginAvailable
    • marginUsed
    • blockedBalance
    • credit
    object
  • #2
    Message IDProperty
    object
  • #3
    Message IDPosition
    object
  • #4
    Message IDClosePosition
    object
  • #5
    Message IDOpenOrder
    object
  • #6

    Subscribe to an account stream

    Message IDAccountSubscribeAction
    object
  • #7

    Unsubscribe from an account stream

    Message IDAccountUnsubscribeAction
    object
  • #8

    Connection updates and errors

    Message IDConnectionErrorMessage
    object
  • #9

    General status message for updates and errors

    Message IDStatusMessage
    object
      Examples values:
    • {"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}
  • #10

    ACK Status messages for subscription actions

    Message IDSubscriptionsStatusMessage
    object
      Examples values:
    • {"status":"error","code":"unknown","message":"Unknown runtime error."}
    • {"status":"ok","code":"connected","message":"Connected to account BAPIA#L#737031","remainingRequests":29}
    • {"status":"error","code":"alreadyConnectedError","message":"Already connected to account BAPIA#L#737031"}
  • #11

    Combination of the user's email, password and server

    Message IDGetAccountTokensPayload
    object
  • #12
    Message IDGetAccountTokensResponse
    object
  • #13

    Error acknowledgment for subscription actions

    Message IDSubscriptionErrorAck
    object
      Examples values:
    • {"status":"error","code":"invalidJwt","message":"jwt expired"}
    • {"status":"error","code":"accountNotFound","message":"Account not found"}