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:
co-authored by
Claude Sonnet 4.6
parent
1e1b837cf3
commit
92b929f4ce
@@ -34,6 +34,8 @@ export class TradovateClient {
|
|||||||
|
|
||||||
/** True once fetchDaysTraded() has finished its last full run */
|
/** True once fetchDaysTraded() has finished its last full run */
|
||||||
public fetchDaysComplete = false;
|
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() */
|
/** Last error per account name from fetchDaysTraded() */
|
||||||
public lastFetchErrors: Record<string, string> = {};
|
public lastFetchErrors: Record<string, string> = {};
|
||||||
/** Raw reports API response sample per account (first 100 chars) for debugging */
|
/** Raw reports API response sample per account (first 100 chars) for debugging */
|
||||||
@@ -313,6 +315,10 @@ export class TradovateClient {
|
|||||||
|
|
||||||
public async fetchDaysTraded(): Promise<void> {
|
public async fetchDaysTraded(): Promise<void> {
|
||||||
if (!this.accessInfo?.accessToken) return;
|
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;
|
this.fetchDaysComplete = false;
|
||||||
|
|
||||||
const authHeaders = { Authorization: `Bearer ${this.accessInfo.accessToken}` };
|
const authHeaders = { Authorization: `Bearer ${this.accessInfo.accessToken}` };
|
||||||
|
|||||||
Reference in New Issue
Block a user