File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import { ExchangeInstanceService } from './exchange_instance_service';
77export type PrefillJob = [ string , string , string ] ;
88
99const CANDLES_LIMIT = 500 ;
10+ // Delay between API calls to avoid rate limits (ms)
11+ const THROTTLE_MS = 250 ;
1012
1113export class CcxtCandlePrefillService {
1214 private queue : PrefillJob [ ] = [ ] ;
@@ -59,9 +61,18 @@ export class CcxtCandlePrefillService {
5961 } catch ( e : any ) {
6062 this . logger . error ( `[CcxtCandlePrefill] ${ this . key ( job ) } : ${ e . message || String ( e ) } ` , { job } ) ;
6163 }
64+
65+ // Throttle between requests to avoid rate limits
66+ if ( this . queue . length > 0 ) {
67+ await this . sleep ( THROTTLE_MS ) ;
68+ }
6269 }
6370 }
6471
72+ private sleep ( ms : number ) : Promise < void > {
73+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
74+ }
75+
6576 /**
6677 * Fetch 500 candles from the exchange REST API and return them immediately.
6778 * No DB storage — caller uses the candles directly.
You can’t perform that action at this time.
0 commit comments