async syncOrders() { let ordersRaw = []; try { ordersRaw = await this.client.getOrders({ status: 'open' }); } catch (e) { this.logger.error(`Coinbase Pro: orders ${String(e)}`); return; } const orders = {}; CoinbasePro.createOrders(...ordersRaw).forEach(o => { orders[o.id] = o; }); this.orders = orders; }
async order(order) { const payload = Binance.createOrderBody(order); let result; try { result = await this.client.order(payload); } catch (e) { this.logger.error(`Binance: order create error: ${JSON.stringify(e.message, order, payload)}`); if ((e.message && e.message.toLowerCase().includes('insufficient balance')) || (e.code && e.code === -2010)) { return ExchangeOrder.createRejectedFromOrder(order, `${e.code} - ${e.message}`); } return undefined; } const exchangeOrder = Binance.createOrders(result)[0]; this.triggerOrder(exchangeOrder); return exchangeOrder; }
async syncOrders() { const symbols = this.symbols .filter( s => s.trade && ((s.trade.capital && s.trade.capital > 0) || (s.trade.currency_capital && s.trade.currency_capital > 0)) ) .map(s => s.symbol); this.logger.debug(`Binance: Sync orders for symbols: ${symbols.length}`); // false equal to all symbols let openOrders = []; try { openOrders = await this.client.openOrders(false); } catch (e) { this.logger.error(`Binance: error sync orders: ${String(e)}`); return; } this.orderbag.set(Binance.createOrders(...openOrders)); }
async order(order) { const payload = CoinbasePro.createOrderBody(order); let result; try { result = await this.client.placeOrder(payload); } catch (e) { this.logger.error(`Coinbase Pro: order create error: ${JSON.stringify([e.message, order, payload])}`); if ( e.message && (e.message.match(/HTTP\s4\d{2}/i) || e.message.toLowerCase().includes('size is too accurate') || e.message.toLowerCase().includes('size is too small')) ) { return ExchangeOrder.createRejectedFromOrder(order, e.message); } return; } const exchangeOrder = CoinbasePro.createOrders(result)[0]; this.triggerOrder(exchangeOrder); return exchangeOrder; }