Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| developers:apiv2:connecting [2026/09/07 13:36] – created chad | developers:apiv2:connecting [2026/09/07 21:58] (current) – [WebSocket Connection] chad | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Connecting | + | ====== Connecting |
| [[developers: | [[developers: | ||
| - | ===== 1. Open the socket | + | ===== WebSocket Connection |
| - | Connect to a [[developers: | + | Clients must connect using WebSocket Secure |
| - | ^ Environment ^ URL ^ | + | <WRAP 50%> |
| - | | Simulator | '' | + | ^ **Environment** ^ **WebSocket |
| - | | Live | '' | + | | **Simulator** | %%wss:// |
| + | | **Simulator (Admin)** | %%wss:// | ||
| + | | **Live** | %%wss:// | ||
| + | | **Live (Admin)** | %%wss:// | ||
| + | </ | ||
| - | **Framing: | + | Develop |
| - | ===== 2. Log in ===== | ||
| - | The **first** message you send must be 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, the server will send a heartbeat automatically. If the server does not receive |
| - | + | ||
| - | Optionally set '' | + | |
| < | < | ||
| // ClientMessage | // ClientMessage | ||
| - | login_request | + | heartbeat |
| - | api_key: " | + | |
| - | price_format: | + | |
| - | } | + | |
| </ | </ | ||
| - | The server replies with a '' | + | ===== Authentication ===== |
| + | Authentication must be performed **immediately after establishing | ||
| + | - **API Key Authentication** (provide only the `apikey` field). | ||
| + | - **Username/ | ||
| - | | + | **Example LoginRequest (API Key Authentication): |
| - | | + | < |
| - | | + | { |
| - | * '' | + | |
| - | * '' | + | } |
| + | </code> | ||
| - | **Roles matter.** Order routing requires the appropriate role; without it, market data and account subscriptions still work but order submissions are rejected. | + | **Example LoginRequest (Username/ |
| + | < | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| - | ===== 3. Stay connected (heartbeat) ===== | + | If authentication succeeds, |
| - | + | ||
| - | Send a '' | + | |
| + | **Example Successful LoginResponse: | ||
| < | < | ||
| - | // ClientMessage | + | { |
| - | heartbeat | + | " |
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| </ | </ | ||
| - | ===== 4. Authentication token (optional) ===== | + | If authentication fails, the server will return an error message. Some common reasons for failure |
| - | + | ||
| - | '' | + | |
| - | * Send '' | + | ^ LoginResult Code ^ Meaning ^ |
| - | * Receive '' | + | | `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. | | ||
| - | 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. | + | For detailed message formats, refer to the [[developers: |
| - | ===== 5. Reconnecting | + | ===== 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 | + | ===== Next Steps ===== |
| - | | + | Once authenticated, |
| - | | + | * Subscribe |
| + | | ||
| + | | ||
| - | **Maintenance window:** connections are dropped for weekly maintenance (around midnight Friday) and service resumes Sunday morning. Build automatic reconnect-and-resubscribe into your client. | + | ---- |
| + | 💡 **Tip:** Test your WebSocket connection using tools like `wscat` or a sample SDK. | ||