Throttle fetchDaysTraded to once per hour per client

Multiple simultaneous fills were triggering concurrent report API calls
to Tradovate for every account in the firm, causing rate limiting.
Added a 1-hour cooldown — the first call always runs (lastDaysFetch=0),
subsequent calls within the same hour are no-ops.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Senofy
2026-03-12 20:40:17 -05:00
co-authored by Claude Sonnet 4.6
parent 1e1b837cf3
commit 92b929f4ce
+6
View File
@@ -34,6 +34,8 @@ export class TradovateClient {
/** True once fetchDaysTraded() has finished its last full run */
public fetchDaysComplete = false;
/** Timestamp (ms) of the last successful fetchDaysTraded run — throttled to once per hour */
private lastDaysFetch = 0;
/** Last error per account name from fetchDaysTraded() */
public lastFetchErrors: Record<string, string> = {};
/** Raw reports API response sample per account (first 100 chars) for debugging */
@@ -313,6 +315,10 @@ export class TradovateClient {
public async fetchDaysTraded(): Promise<void> {
if (!this.accessInfo?.accessToken) return;
// Throttle to at most once per hour to avoid rate-limiting the reports API
const ONE_HOUR = 60 * 60 * 1_000;
if (Date.now() - this.lastDaysFetch < ONE_HOUR) return;
this.lastDaysFetch = Date.now();
this.fetchDaysComplete = false;
const authHeaders = { Authorization: `Bearer ${this.accessInfo.accessToken}` };