Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| developers:apiv2:connecting [2026/09/07 13:40] – chad | developers:apiv2:connecting [2026/09/07 21:58] (current) – [WebSocket Connection] chad | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| Clients must connect using WebSocket Secure (WSS) over SSL/TLS on port 443. Messages are encoded with Google Protocol Buffers. | Clients must connect using WebSocket Secure (WSS) over SSL/TLS on port 443. Messages are encoded with Google Protocol Buffers. | ||
| - | ^ Environment ^ URL ^ | + | <WRAP 50%> |
| - | | Live | '' | + | ^ **Environment** ^ **WebSocket |
| - | | Simulator | '' | + | | **Simulator** |
| - | | Live (Admin) | + | | **Simulator |
| - | | Simulator | + | | **Live** | %%wss://wss.t4login.com/ |
| + | | **Live | ||
| + | </ | ||
| Develop and certify against the Simulator. | Develop and certify against the Simulator. | ||
| - | **Framing: | ||
| - | ==== Heartbeat ==== | ||
| - | Send a '' | + | ==== Heartbeat |
| + | To maintain an active connection, both the client and server must send a **heartbeat message every 20 seconds**. If no other message is sent during that interval, | ||
| < | < | ||
| Line 27: | Line 28: | ||
| ===== Authentication ===== | ===== Authentication ===== | ||
| + | Authentication must be performed **immediately after establishing a connection** by sending a `LoginRequest` message. This API supports two authentication methods: | ||
| + | - **API Key Authentication** (provide only the `apikey` field). | ||
| + | - **Username/ | ||
| - | The **first** message you send must be a '' | + | **Example |
| + | < | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| - | * **API key** — set '' | + | **Example LoginRequest (Username/Password Authentication): |
| - | * **Username / password** — set '' | + | < |
| + | { | ||
| + | "firm": " | ||
| + | "username": " | ||
| + | "password": " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| - | Optionally set '' | + | If authentication succeeds, the server will return a `LoginResponse` with a session ID and assigned roles. |
| + | **Example Successful LoginResponse: | ||
| < | < | ||
| - | // ClientMessage | + | { |
| - | login_request | + | |
| - | | + | |
| - | | + | " |
| + | " | ||
| + | " | ||
| } | } | ||
| </ | </ | ||
| - | The server | + | If authentication fails, the server |
| - | * '' | + | ^ LoginResult |
| - | * '' | + | | `LOGIN_FAILED` | Invalid credentials. | |
| - | * '' | + | | `TWO_FACTOR_REQUIRED` | Two-factor authentication is required. | |
| - | * '' | + | | `UNAUTHORIZED` | API key or username/ |
| - | * '' | + | | `PASSWORD_EXPIRED` | The password must be changed before logging in. | |
| + | | `LOCKED_OUT` | Too many failed login attempts. | | ||
| - | Order routing requires | + | For detailed message formats, refer to the [[developers:apiv2: |
| - | + | ||
| - | ==== Authentication Token ==== | + | |
| - | + | ||
| - | '' | + | |
| - | + | ||
| - | * Send '' | + | |
| - | * Receive '' | + | |
| - | + | ||
| - | The token authenticates to T4 REST services. It does not resume a dropped WebSocket session — you re-authenticate on reconnect. | + | |
| ===== Reconnection & Session Handling ===== | ===== Reconnection & Session Handling ===== | ||
| + | If the connection is lost, clients should **reconnect automatically** and **re-authenticate** as session resumption is **not supported**. Connections remain valid as long as heartbeats are exchanged. | ||
| - | Sessions are not resumable. On any disconnect: | + | The system undergoes |
| - | + | ||
| - | - Reconnect to the endpoint. | + | |
| - | - Send '' | + | |
| - | - Re-subscribe to markets and accounts, and reconcile order state from the account snapshot. | + | |
| - | + | ||
| - | **Maintenance: | + | |
| ===== Next Steps ===== | ===== Next Steps ===== | ||
| + | Once authenticated, | ||
| + | * Subscribe to **market data streams** ([[quote_data|Quote Data]]). | ||
| + | * Retrieve **account and position details** ([[account_data|Account Data]]). | ||
| + | * Submit **orders and manage trades** ([[order_submission|Order Submission]]). | ||
| - | * [[developers: | + | ---- |
| - | * [[developers: | + | |
| - | * [[developers: | + | |
| + | 💡 **Tip:** Test your WebSocket connection using tools like `wscat` or a sample SDK. | ||