Persist one browser user agent for Axios and WebSockets

This commit is contained in:
Brandon Li
2026-10-19 06:08:23 -05:00
parent 13e03c3d0f
commit ed56e306d1
21 changed files with 380 additions and 64 deletions
+3 -4
View File
@@ -22,7 +22,7 @@
* all zeros; a blown account shows up as canTrade=false → active=false.
*/
import axios from 'axios';
import axios from './http-client';
import * as signalR from '@microsoft/signalr';
import { currentTradeDateCT, FUND_EVENT_MIN, fundReconcileStep, type FundSighting } from './trading-logic';
import { getCachedContract } from './contract-resolver';
@@ -676,14 +676,13 @@ export class TopstepXClient implements PlatformClient {
// everything the hub does, just slower).
// With skipNegotiation the hub is a single websocket to a broker
// endpoint, so it follows the operator's proxy like the REST calls do.
const proxiedWs = signalrWebSocket();
const configuredWs = signalrWebSocket();
const hub = new signalR.HubConnectionBuilder()
.withUrl(USER_HUB, {
skipNegotiation: true,
transport: signalR.HttpTransportType.WebSockets,
accessTokenFactory: () => this.token ?? '',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...(proxiedWs ? { WebSocket: proxiedWs as any } : {}),
...{ WebSocket: configuredWs },
})
.withAutomaticReconnect()
.configureLogging(signalR.LogLevel.Warning)