From 92b929f4ce6a025b9cd31f15751c16371a4f492f Mon Sep 17 00:00:00 2001 From: Senofy <63175905+Senofy@users.noreply.github.com> Date: Thu, 12 Mar 2026 20:40:17 -0500 Subject: [PATCH] Throttle fetchDaysTraded to once per hour per client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/tradovate-class.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/tradovate-class.ts b/lib/tradovate-class.ts index 832c21e..aaaecf3 100644 --- a/lib/tradovate-class.ts +++ b/lib/tradovate-class.ts @@ -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 = {}; /** Raw reports API response sample per account (first 100 chars) for debugging */ @@ -313,6 +315,10 @@ export class TradovateClient { public async fetchDaysTraded(): Promise { 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}` };