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}` };