@ex-master/core
Advanced tools
Comparing version 0.1.16 to 0.1.17
@@ -57,2 +57,3 @@ import { Decimal } from 'decimal.js'; | ||
private freeAndOrder(market, descriptor, nextUpdates); | ||
private isBalanceSufficient(market, {type, price, size}); | ||
private freeMoney(key, target, updates); | ||
@@ -59,0 +60,0 @@ private freeStock(key, target, updates); |
@@ -210,7 +210,17 @@ "use strict"; | ||
let { active, descriptor } = updates[i]; | ||
if (active) { | ||
await this.cancelOrder(active); | ||
if (active && | ||
descriptor && | ||
this.isBalanceSufficient(market, descriptor)) { | ||
let promises = []; | ||
promises.push(this.cancelOrder(active)); | ||
promises.push(this.order(market, descriptor)); | ||
await Promise.all(promises); | ||
} | ||
if (descriptor) { | ||
await this.freeAndOrder(market, descriptor, updates.slice(i + 1)); | ||
else { | ||
if (active) { | ||
await this.cancelOrder(active); | ||
} | ||
if (descriptor) { | ||
await this.freeAndOrder(market, descriptor, updates.slice(i + 1)); | ||
} | ||
} | ||
@@ -246,10 +256,7 @@ } | ||
} | ||
// private isBalanceSufficient( | ||
// market: Market, | ||
// {type, price, size}: InternalOrderDescriptor, | ||
// ): boolean { | ||
// let target = type === 'ask' ? size : price.mul(size); | ||
// let key = type === 'ask' ? market.stock : market.money; | ||
// return this.account.getBalance(key).available.greaterThanOrEqualTo(target); | ||
// } | ||
isBalanceSufficient(market, { type, price, size }) { | ||
let target = type === 'ask' ? size : price.mul(size); | ||
let key = type === 'ask' ? market.stock : market.money; | ||
return this.account.getBalance(key).available.greaterThanOrEqualTo(target); | ||
} | ||
async freeMoney(key, target, updates) { | ||
@@ -256,0 +263,0 @@ let available; |
{ | ||
"name": "@ex-master/core", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"main": "bld/index.js", | ||
@@ -5,0 +5,0 @@ "types": "bld/index.d.ts", |
32849
770