From 54a231ab60b7fca65348992f6831cd68e53084a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Mon, 18 Jan 2021 21:20:51 +0000 Subject: [PATCH] Restructured long lines of code --- lib/plugins/exchange/ccxt/ccxt.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/plugins/exchange/ccxt/ccxt.js b/lib/plugins/exchange/ccxt/ccxt.js index 679d3db6..cf768477 100644 --- a/lib/plugins/exchange/ccxt/ccxt.js +++ b/lib/plugins/exchange/ccxt/ccxt.js @@ -11,7 +11,8 @@ function trade (side, account, cryptoAtoms, fiatCode, cryptoCode, exchangeName) if (exchangeName === 'itbit') { return exchange.fetchOrderBook(symbol) .then(orderBook => { - return exchange.createOrder(symbol, 'limit', side, amount, calculatePrice(side, amount, orderBook), { walletId: account.walletId }) + const price = calculatePrice(side, amount, orderBook) + return exchange.createOrder(symbol, 'limit', side, amount, price, { walletId: account.walletId }) }) } return exchange.createOrder(symbol, 'market', side, amount) @@ -28,17 +29,32 @@ function setUpExchange (account, exchangeName) { switch (exchangeName) { case 'itbit': - if (!account.clientKey || !account.clientSecret || !account.userId || !account.walletId) + if (!account.clientKey || !account.clientSecret || !account.userId || !account.walletId) { throw new Error('Must provide user ID, wallet ID, client key, and client secret') - return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'clientKey' ? 'apiKey' : key === 'clientSecret' ? 'secret' : key === 'userId' ? 'uid' : key }, _.omit(['walletId'], account))) + } + return new ccxt[exchangeName](_.mapKeys((key) => { + if (key === 'clientKey') return 'apiKey' + if (key === 'clientSecret') return 'secret' + if (key === 'userId') return 'uid' + return key + }, _.omit(['walletId'], account))) case 'kraken': - if (!account.apiKey || !account.privateKey) + if (!account.apiKey || !account.privateKey) { throw new Error('Must provide key and private key') - return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'privateKey' ? 'secret' : key }, account)) + } + return new ccxt[exchangeName](_.mapKeys((key) => { + if (key === 'privateKey') return 'secret' + return key + }, account)) case 'bitstamp': - if (!account.key || !account.secret || !account.clientId) + if (!account.key || !account.secret || !account.clientId) { throw new Error('Must provide key, secret and client ID') - return new ccxt[exchangeName](_.mapKeys((key) => { return key === 'key' ? 'apiKey' : key === 'clientId' ? 'uid' : key }, account)) + } + return new ccxt[exchangeName](_.mapKeys((key) => { + if (key === 'key') return 'apiKey' + if (key === 'clientId') return 'uid' + return key + }, account)) default: throw new Error(`Exchange ${exchangeName} not supported.`) }