diff --git a/lib/exchange.js b/lib/exchange.js index 3df23e3f..0431a7d5 100644 --- a/lib/exchange.js +++ b/lib/exchange.js @@ -19,25 +19,25 @@ function fetchExchange (settings, cryptoCode) { }) } -function buy (settings, tradeEntry, tradeId) { +function buy (settings, tradeEntry) { const { cryptoAtoms, fiatCode, cryptoCode } = tradeEntry return fetchExchange(settings, cryptoCode) .then(r => { if (r.exchangeName === 'mock-exchange') { return mockExchange.buy(cryptoAtoms, fiatCode, cryptoCode) } - return ccxt.trade('buy', r.account, cryptoAtoms, fiatCode, cryptoCode, r.exchangeName, tradeId) + return ccxt.trade('buy', r.account, tradeEntry, r.exchangeName) }) } -function sell (settings, tradeEntry, tradeId) { +function sell (settings, tradeEntry) { const { cryptoAtoms, fiatCode, cryptoCode } = tradeEntry return fetchExchange(settings, cryptoCode) .then(r => { if (r.exchangeName === 'mock-exchange') { return mockExchange.sell(cryptoAtoms, fiatCode, cryptoCode) } - return ccxt.trade('sell', r.account, cryptoAtoms, fiatCode, cryptoCode, r.exchangeName, tradeId) + return ccxt.trade('sell', r.account, tradeEntry, r.exchangeName) }) } diff --git a/lib/plugins.js b/lib/plugins.js index ea95e272..985f7365 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -517,8 +517,9 @@ function plugins (settings, deviceId) { const execute = tradeEntry.type === 'buy' ? exchange.buy : exchange.sell return recordTrade(tradeEntry) - .then(newEntry => - execute(settings, tradeEntry, newEntry.id) + .then(newEntry => { + tradeEntry.tradeId = newEntry.id + return execute(settings, tradeEntry) .catch(err => { updateTradeEntry(tradeEntry, newEntry, err) .then(() => { @@ -526,7 +527,7 @@ function plugins (settings, deviceId) { throw err }) }) - ) + }) } function updateTradeEntry (tradeEntry, newEntry, err) { diff --git a/lib/plugins/exchange/ccxt.js b/lib/plugins/exchange/ccxt.js index bceaef31..087d3d6c 100644 --- a/lib/plugins/exchange/ccxt.js +++ b/lib/plugins/exchange/ccxt.js @@ -8,7 +8,8 @@ const { ORDER_TYPES } = require('./consts') const DEFAULT_PRICE_PRECISION = 2 const DEFAULT_AMOUNT_PRECISION = 8 -function trade (side, account, cryptoAtoms, fiatCode, cryptoCode, exchangeName, tradeId) { +function trade (side, account, tradeEntry, exchangeName) { + const { cryptoAtoms, fiatCode, cryptoCode, tradeId } = tradeEntry try { const exchangeConfig = ALL[exchangeName] if (!exchangeConfig) throw Error('Exchange configuration not found')