File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,9 @@ export class BybitUnified {
4343 this . positions = { } ;
4444 this . orders = { } ;
4545
46- const exchange = new ccxt . pro . bybit ( { newUpdates : false } ) ;
46+ // newUpdates: true ensures ccxt.pro only keeps the latest update, not all historical data
47+ // This prevents unbounded memory growth from accumulated websocket messages
48+ const exchange = new ccxt . pro . bybit ( { newUpdates : true } ) ;
4749
4850 setTimeout ( async ( ) => {
4951 const result = ( await exchange . fetchMarkets ( ) ) . filter ( i => i . type === 'swap' && i . quote === 'USDT' ) ;
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ export interface SymbolInstance {
3131
3232export class TickListener {
3333 private readonly notified : Record < string , Date > = { } ;
34+ private cleanupInterval : NodeJS . Timeout | null = null ;
3435
3536 constructor (
3637 private tickers : Tickers ,
@@ -283,6 +284,24 @@ export class TickListener {
283284 } ) ;
284285 } ) ;
285286 } ) ;
287+
288+ // Cleanup old notified entries every hour to prevent memory leak
289+ // Entries older than 1 hour are no longer needed for signal slowdown logic
290+ if ( ! this . cleanupInterval ) {
291+ this . cleanupInterval = setInterval ( ( ) => {
292+ const cutoff = moment ( ) . subtract ( 1 , 'hour' ) . toDate ( ) ;
293+ let cleaned = 0 ;
294+ for ( const key in this . notified ) {
295+ if ( this . notified [ key ] < cutoff ) {
296+ delete this . notified [ key ] ;
297+ cleaned ++ ;
298+ }
299+ }
300+ if ( cleaned > 0 ) {
301+ this . logger . debug ( `TickListener: Cleaned ${ cleaned } old notified entries` ) ;
302+ }
303+ } , 60 * 60 * 1000 ) ; // Run every hour
304+ }
286305 }
287306
288307 getFirstTimeoutAndInterval ( period : string ) : [ number , number ] {
You can’t perform that action at this time.
0 commit comments