@ex-master/core
Advanced tools
Comparing version 0.1.42 to 0.1.43
@@ -27,2 +27,3 @@ import { Decimal } from 'decimal.js'; | ||
pendingUpdates: number; | ||
canceling: number | false; | ||
becomeInactive: Promise<void>; | ||
@@ -29,0 +30,0 @@ becomeInactiveResolver(): void; |
@@ -10,2 +10,3 @@ "use strict"; | ||
const debug = Debug('ex-master:core:exchange'); | ||
const ORDER_CANCELING_TIMEOUT = 1000; | ||
class Exchange { | ||
@@ -62,2 +63,3 @@ constructor(client, dashboard, { pendingUpdatesPriorityScale = 2 } = {}) { | ||
let activeOrders = Array.from(activeOrderMap.values()); | ||
let now = Date.now(); | ||
let orders = activeOrders.length | ||
@@ -90,2 +92,6 @@ ? await this.client.getOrders(activeOrders) | ||
} | ||
let ordersToReCancel = Array.from(activeOrderMap.values()).filter(order => order.canceling && order.canceling + ORDER_CANCELING_TIMEOUT < now); | ||
if (ordersToReCancel.length) { | ||
await this.cancelOrders(ordersToReCancel); | ||
} | ||
}); | ||
@@ -346,2 +352,3 @@ } | ||
pendingUpdates: 0, | ||
canceling: false, | ||
becomeInactive, | ||
@@ -355,4 +362,5 @@ becomeInactiveResolver, | ||
async cancelOrder(order) { | ||
let { group, label, becomeInactive } = order; | ||
let { group, id, label, becomeInactive } = order; | ||
this.dashboard.info(`cancel order [${group}] "${label}"`); | ||
this.activeOrderMap.set(id, { ...order, canceling: Date.now() }); | ||
await this.client.cancelOrder(order); | ||
@@ -372,2 +380,6 @@ await becomeInactive; | ||
this.dashboard.info(`cancel orders ${ordersStr}`); | ||
let now = Date.now(); | ||
for (let order of orders) { | ||
this.activeOrderMap.set(order.id, { ...order, canceling: now }); | ||
} | ||
await this.client.cancelOrders(orders); | ||
@@ -374,0 +386,0 @@ await Promise.all(orders.map(order => order.becomeInactive)); |
{ | ||
"name": "@ex-master/core", | ||
"version": "0.1.42", | ||
"version": "0.1.43", | ||
"main": "bld/index.js", | ||
@@ -5,0 +5,0 @@ "types": "bld/index.d.ts", |
57114
1608