This is an old revision of the document!
Connecting & Authenticating
1. Open the socket
Connect to a V2 endpoint over WSS (TLS, port 443):
| Environment | URL |
|---|---|
| Simulator | wss:wss-sim.t4login.com/v2 |
Framing: send and receive binary frames. Each frame is exactly one serialized ClientMessage (out) or ServerMessage (in). There is no extra length prefix — the WebSocket frame is the message boundary.
2. Log in
The first message you send must be a LoginRequest (wrapped in a ClientMessage). Two authentication methods:
- API key — set
api_keyonly. Recommended for automated/API clients. - Username / password — set
firm,username,password,app_name,app_license.
Optionally set price_format to choose how prices are formatted (see Prices & Data Types).
// ClientMessage
login_request {
api_key: "YOUR_API_KEY"
price_format: PRICE_FORMAT_DECIMAL
}
The server replies with a LoginResponse:
result— aLoginResult. Anything other thanLOGIN_RESULT_SUCCESSmeans login failed; readerror_message.session_id,user_id,firm_id,roles— your session identity and permissions.exchanges— the exchanges/market-data you are entitled to.accounts— the accounts you can view/trade.authentication_token(optional) — a short-lived token (see below).
Roles matter. Order routing requires the appropriate role; without it, market data and account subscriptions still work but order submissions are rejected.
3. Stay connected (heartbeat)
Send a Heartbeat every 20 seconds. The server does the same. If the server receives nothing for 3 heartbeat intervals (~60s) it closes the connection.
// ClientMessage
heartbeat { timestamp: 1725600000000 } // UTC epoch milliseconds
4. Authentication token (optional)
LoginResponse may include an authentication_token. You can also request a fresh one at any time:
- Send
AuthenticationTokenRequestwith arequest_id. - Receive
AuthenticationTokenwithtokenandexpire_time(orfail_message).
Use it where a bearer token is needed for T4 REST services. It does not resume a dropped WebSocket session — you still re-authenticate on reconnect.
5. Reconnecting
Sessions are not resumable. On any disconnect:
- Reconnect to the endpoint.
- Send
LoginRequestagain. - Re-subscribe to markets and accounts, and reconcile order state from the account snapshot.
Maintenance window: connections are dropped for weekly maintenance (around midnight Friday) and service resumes Sunday morning. Build automatic reconnect-and-resubscribe into your client.