From 4747e0b7f69f9fcde29d523d3addd5a3763d5258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Tue, 19 Apr 2022 12:43:54 +0100 Subject: [PATCH] refactor: save CCXT ticker instance --- lib/plugins/ticker/ccxt.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/plugins/ticker/ccxt.js b/lib/plugins/ticker/ccxt.js index 6c495a1c..09d8dbd7 100644 --- a/lib/plugins/ticker/ccxt.js +++ b/lib/plugins/ticker/ccxt.js @@ -6,8 +6,13 @@ const { getRate } = require('../../../lib/forex') const RETRIES = 2 +const tickerObjects = {} + function ticker (fiatCode, cryptoCode, tickerName) { - const ticker = new ccxt[tickerName]({ timeout: 3000 }) + const ticker = tickerObjects[tickerName] ? + tickerObjects[tickerName] : + tickerObjects[tickerName] = new ccxt[tickerName]({ timeout: 3000 }) + if (verifyFiatSupport(fiatCode, tickerName)) { return getCurrencyRates(ticker, fiatCode, cryptoCode) }