From 9edb0d502748535fb1be48bea6464e0b25409f70 Mon Sep 17 00:00:00 2001 From: rainfu Date: Wed, 12 Jul 2023 11:55:20 +0800 Subject: [PATCH] bug fix --- extensions/exchanges/ccxt/exchange.js | 10 ++++-- extensions/exchanges/defi/exchange.js | 50 +++++++++++++-------------- lib/engine.js | 23 +++++++++--- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/extensions/exchanges/ccxt/exchange.js b/extensions/exchanges/ccxt/exchange.js index 428f7c8..0f22213 100644 --- a/extensions/exchanges/ccxt/exchange.js +++ b/extensions/exchanges/ccxt/exchange.js @@ -844,9 +844,13 @@ module.exports = function container(conf, so, inOptions) { }, updateSymbols(symbols) { products = this.getProducts(); - return symbols.filter((sy) => { - return products.find((p) => p.normalized === sy.normalized); - }); + if (symbols) { + return symbols.filter((sy) => { + return products.find((p) => p.normalized === sy.normalized); + }); + } else { + return []; + } }, }; so.symbols = exchange.updateSymbols(so.symbols); diff --git a/extensions/exchanges/defi/exchange.js b/extensions/exchanges/defi/exchange.js index b0ebbfa..3b32728 100644 --- a/extensions/exchanges/defi/exchange.js +++ b/extensions/exchanges/defi/exchange.js @@ -847,32 +847,30 @@ module.exports = function container(conf, so, inOptions) { target, JSON.stringify(filterProducts, null, 2) ); - console.log( - "filterProducts from".cyan, - oldProducts.length, - "to".cyan, - filterProducts.length - ); - return symbols - .filter((sy) => { - return filterProducts.find((p) => p.normalized === sy.normalized); - }) - .map((sy) => { - let product = filterProducts.find( - (p) => p.normalized === sy.normalized - ); - return { - asset: product.asset, - currency: product.currency, - symbol: product.symbol, - csymbol: product.csymbol, - id: product.id, - decimals: product.decimals, - exchange_id: product.exchagne_id, - product_id: product.product_id, - normalized: product.normalized, - }; - }); + if (symbols) { + return symbols + .filter((sy) => { + return filterProducts.find((p) => p.normalized === sy.normalized); + }) + .map((sy) => { + let product = filterProducts.find( + (p) => p.normalized === sy.normalized + ); + return { + asset: product.asset, + currency: product.currency, + symbol: product.symbol, + csymbol: product.csymbol, + id: product.id, + decimals: product.decimals, + exchange_id: product.exchagne_id, + product_id: product.product_id, + normalized: product.normalized, + }; + }); + } else { + return []; + } }, }; so.symbols = exchange.updateSymbols(so.symbols); diff --git a/lib/engine.js b/lib/engine.js index 60caebc..173f7d8 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -583,13 +583,26 @@ module.exports = function (s, conf, core) { } if (!balance.assets) return cb(null, [], balance); delete balance.assets["NFT"]; - let exitSymbols = Object.keys(balance.assets).map((key) => { + // console.log("balance.assets", so.symbols, balance); + let exitSymbols = []; + Object.keys(balance.assets).map((key) => { let sy = so.symbols.find((s) => s.asset === key); - return Object.assign(balance.assets[key], { - product_id: sy.product_id, - normalized: sy.normalized, - }); + if (sy) { + exitSymbols.push( + Object.assign(balance.assets[key], { + product_id: sy.product_id, + normalized: sy.normalized, + }) + ); + } /* else {//not watch symbol is ignored + return Object.assign(balance.assets[key], { + product_id: key + "-" + symbol.currency, + normalized: + symbol.exchange_id + "." + key + "-" + symbol.currency, + }); + } */ }); + // console.log("exitSymbols", exitSymbols); if (s.options.future) { exitSymbols = exitSymbols.filter( (xs) => xs.positionSide === position_side