refactor: replace custom field function with const and move update trade logic inside a function
This commit is contained in:
parent
f45c783876
commit
8567b7887c
6 changed files with 25 additions and 19 deletions
|
|
@ -13,14 +13,15 @@ function trade (side, account, cryptoAtoms, fiatCode, cryptoCode, exchangeName,
|
|||
const exchangeConfig = ALL[exchangeName]
|
||||
if (!exchangeConfig) throw Error('Exchange configuration not found')
|
||||
|
||||
const { loadTradeId, loadOptions, loadConfig = _.noop, REQUIRED_CONFIG_FIELDS, ORDER_TYPE, AMOUNT_PRECISION } = exchangeConfig
|
||||
const { CUSTOM_KEY, 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)
|
||||
const amount = toUnit(cryptoAtoms, cryptoCode).toFixed(precision)
|
||||
const accountOptions = _.isFunction(loadOptions) ? loadOptions(account) : {}
|
||||
const options = loadTradeId(accountOptions, tradeId)
|
||||
const withCustomKey = CUSTOM_KEY ? { [CUSTOM_KEY]: tradeId } : {}
|
||||
const options = _.assign(accountOptions, withCustomKey)
|
||||
const exchange = new ccxt[exchangeName](loadConfig(account))
|
||||
|
||||
if (ORDER_TYPE === ORDER_TYPES.MARKET) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue