mirror of
https://github.com/discountry/ritmex-bot.git
synced 2026-09-11 09:18:08 +00:00
add presist
This commit is contained in:
@@ -4,8 +4,8 @@ export interface TradeLogEntry {
|
||||
detail: string;
|
||||
}
|
||||
|
||||
export function createTradeLog(maxEntries: number) {
|
||||
const entries: TradeLogEntry[] = [];
|
||||
export function createTradeLog(maxEntries: number, seed: TradeLogEntry[] = []) {
|
||||
const entries: TradeLogEntry[] = seed.slice(-maxEntries);
|
||||
function push(type: string, detail: string) {
|
||||
entries.push({ time: new Date().toLocaleString(), type, detail });
|
||||
if (entries.length > maxEntries) {
|
||||
@@ -15,5 +15,8 @@ export function createTradeLog(maxEntries: number) {
|
||||
function all() {
|
||||
return entries;
|
||||
}
|
||||
return { push, all };
|
||||
function replace(next: TradeLogEntry[]) {
|
||||
entries.splice(0, entries.length, ...next.slice(-maxEntries));
|
||||
}
|
||||
return { push, all, replace };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user