fix: verify config field existance and content

This commit is contained in:
José Oliveira 2021-05-13 16:13:27 +01:00 committed by Josh Harvey
parent a8085f3f1d
commit 0c0ca09b4e
5 changed files with 15 additions and 25 deletions

View file

@ -1,7 +1,7 @@
const _ = require('lodash/fp')
const ccxt = require('ccxt')
const { toUnit } = require('../../coin-utils')
const { toUnit, isConfigValid } = require('../../coin-utils')
const { buildMarket, ALL } = require('../common/ccxt')
const { ORDER_TYPES } = require('./consts')
@ -13,8 +13,8 @@ function trade (side, account, cryptoAtoms, fiatCode, cryptoCode, exchangeName)
const exchangeConfig = ALL[exchangeName]
if (!exchangeConfig) throw Error('Exchange configuration not found')
const { loadOptions, loadConfig = _.noop, isConfigValid, ORDER_TYPE, AMOUNT_PRECISION } = exchangeConfig
if (_.isFunction(isConfigValid) && !isConfigValid(account)) throw Error('Invalid config')
const { loadOptions, loadConfig = _.noop, REQUIRED_CONFIG_FIELDS, ORDER_TYPE, AMOUNT_PRECISION } = exchangeConfig
if (!isConfigValid(account, REQUIRED_CONFIG_FIELDS)) throw Error('Invalid config')
const symbol = buildMarket(fiatCode, cryptoCode, exchangeName)
const precision = _.defaultTo(DEFAULT_AMOUNT_PRECISION, AMOUNT_PRECISION)