Skip to content

Commit 5835da6

Browse files
committed
reduce memory usage
1 parent 8e1939f commit 5835da6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/exchange/bybit_unified.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff 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');

src/modules/listener/tick_listener.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface SymbolInstance {
3131

3232
export 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] {

0 commit comments

Comments
 (0)