From 0d0bfd3dbb4c91772c3f78a164bcbe59187f1661 Mon Sep 17 00:00:00 2001 From: defkev Date: Mon, 23 Apr 2018 11:38:12 +0200 Subject: [PATCH] Completely rework --buy_max_amt (#1494) * Completely rework --buy_max_amt As much as i like the --buy_max_amt feature i was never a fan of how it was implemented, leave alone the naming being confusing at best as it simply doesn't just account for the amount the bot can buy but how much he is actually able to trade. * Renames --buy_max_amt to --deposit for sake of clarification * Using --buy_max_amt will still work but print a deprecated warning * Instead of using --deposit to size buy orders use it to limit the balance available to the bot * This allows us to use it together with --buy_pct * --deposit will still account for asset held to calculate the available currency balance * So if the asset held is covering --deposit the bot will have 0 currency (0% of currency balance) available, if not currency will be filled to the point it compensates for the difference (up to 100% of currency balance) * If deposit is exceeding asset + currency the bot will also use 100% of currency balance held * Deposit will be updated on each price change and new period to ensure the bot always only trades the amount as defined by --deposit * Profit calculation will no longer go havoc as long as currency balance doesn't fall below whats currently deposited into the bot * If enabled this will add two new columns to the output displaying the total currency balance (in green) as well as how much percentage (gray) of currency balance (0 - 100%) is currently used by the bot * Works in Live, Paper & Sim mode * Profit * Fix profit calculation for stats and API * Add deposit to Web GUI's capital row * Profit starts at 100% on reset * WebUI Print deposit only if enabled * Add deposit to sim/exchange * Less invasive profit fix * Use deposit for profit/stats in sim if enabled * Remove prev_trades dashboard sorting * Restore prev_trades dashboard sorting * Resolve upstream conflicts * Update engine.test to match changes As deposit no longer overrides buy_pct this is kinda expected... * Update engine.test to match changes #2 With deposit set order would be below minimum with asset on hold * Reset profit on deposit change --- README.md | 2 +- commands/sim.js | 2 +- commands/trade.js | 13 ++-- extensions/exchanges/sim/exchange.js | 1 + extensions/output/api.js | 1 + lib/engine.js | 74 ++++++++++++----------- templates/dashboard.ejs | 12 +++- test/lib/engine.test.js | 90 ++++++++++++++-------------- 8 files changed, 106 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 1e9a9a67ba..4bcb535ee4 100644 --- a/README.md +++ b/README.md @@ -264,7 +264,7 @@ zenbot trade --help --asset_capital for paper trading, amount of start capital in asset --avg_slippage_pct avg. amount of slippage to apply to paper trades --buy_pct buy with this % of currency balance - --buy_max_amt buy with up to this amount of currency balance + --deposit absolute initial capital (in currency) at the bots disposal (previously --buy_max_amt) --sell_pct sell with this % of asset balance --markdown_buy_pct % to mark down buy price --markup_sell_pct % to mark up sell price diff --git a/commands/sim.js b/commands/sim.js index e6ef106152..9c38369eec 100644 --- a/commands/sim.js +++ b/commands/sim.js @@ -125,7 +125,7 @@ module.exports = function (program, conf) { time: s.period.time }) } - s.balance.currency = n(s.balance.currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') + s.balance.currency = n(s.net_currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') s.balance.asset = 0 s.lookback.unshift(s.period) diff --git a/commands/trade.js b/commands/trade.js index 2a2c272aef..4d5af3eada 100644 --- a/commands/trade.js +++ b/commands/trade.js @@ -30,7 +30,7 @@ module.exports = function (program, conf) { .option('--asset_capital ', 'for paper trading, amount of start capital in asset', Number, conf.asset_capital) .option('--avg_slippage_pct ', 'avg. amount of slippage to apply to paper trades', Number, conf.avg_slippage_pct) .option('--buy_pct ', 'buy with this % of currency balance', Number, conf.buy_pct) - .option('--buy_max_amt ', 'buy with up to this amount of currency balance', Number, conf.buy_max_amt) + .option('--deposit ', 'absolute initial capital (in currency) at the bots disposal (previously --buy_max_amt)', Number, conf.deposit) .option('--sell_pct ', 'sell with this % of asset balance', Number, conf.sell_pct) .option('--markdown_buy_pct ', '% to mark down buy price', Number, conf.markdown_buy_pct) .option('--markup_sell_pct ', '% to mark up sell price', Number, conf.markup_sell_pct) @@ -82,6 +82,10 @@ module.exports = function (program, conf) { so.debug = cmd.debug so.stats = !cmd.disable_stats so.mode = so.paper ? 'paper' : 'live' + if (so.buy_max_amt) { + console.log(('--buy_max_amt is deprecated, use --deposit instead!\n').red) + so.deposit = so.buy_max_amt + } so.selector = objectifySelector(selector || conf.selector) var engine = engineFactory(s, conf) @@ -149,7 +153,7 @@ module.exports = function (program, conf) { /* Implementing statistical Exit */ function printTrade (quit, dump, statsonly = false) { - var tmp_balance = n(s.balance.currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') + var tmp_balance = n(s.net_currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') if (quit) { if (s.my_trades.length) { s.my_trades.push({ @@ -276,7 +280,7 @@ module.exports = function (program, conf) { if(!shouldSaveStats) return var output_lines = [] - var tmp_balance = n(s.balance.currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') + var tmp_balance = n(s.net_currency).add(n(s.period.close).multiply(s.balance.asset)).format('0.00000000') var profit = s.start_capital ? n(tmp_balance).subtract(s.start_capital).divide(s.start_capital) : n(0) output_lines.push('last balance: ' + n(tmp_balance).format('0.00000000').yellow + ' (' + profit.format('0.00%') + ')') @@ -453,7 +457,7 @@ module.exports = function (program, conf) { if (err) throw err var prev_session = prev_sessions[0] if (prev_session && !cmd.reset_profit) { - if (prev_session.orig_capital && prev_session.orig_price && ((so.mode === 'paper' && !raw_opts.currency_capital && !raw_opts.asset_capital) || (so.mode === 'live' && prev_session.balance.asset == s.balance.asset && prev_session.balance.currency == s.balance.currency))) { + if (prev_session.orig_capital && prev_session.orig_price && prev_session.deposit === so.deposit && ((so.mode === 'paper' && !raw_opts.currency_capital && !raw_opts.asset_capital) || (so.mode === 'live' && prev_session.balance.asset == s.balance.asset && prev_session.balance.currency == s.balance.currency))) { s.orig_capital = session.orig_capital = prev_session.orig_capital s.orig_price = session.orig_price = prev_session.orig_price if (so.mode === 'paper') { @@ -565,6 +569,7 @@ module.exports = function (program, conf) { session.start_capital = s.start_capital session.start_price = s.start_price session.num_trades = s.my_trades.length + if (so.deposit) session.deposit = so.deposit if (!session.orig_capital) session.orig_capital = s.start_capital if (!session.orig_price) session.orig_price = s.start_price if (s.period) { diff --git a/extensions/exchanges/sim/exchange.js b/extensions/exchanges/sim/exchange.js index 8ea84ba026..ed3c6e5914 100644 --- a/extensions/exchanges/sim/exchange.js +++ b/extensions/exchanges/sim/exchange.js @@ -52,6 +52,7 @@ module.exports = function sim (conf, s) { getBalance: function (opts, cb) { setTimeout(function() { + s.sim_asset = balance.asset return cb(null, balance) }, latency) }, diff --git a/extensions/output/api.js b/extensions/output/api.js index 6aab20ac30..65d9d2129b 100644 --- a/extensions/output/api.js +++ b/extensions/output/api.js @@ -33,6 +33,7 @@ module.exports = function api () { app.get('/', function (req, res) { app.locals.moment = moment + app.locals.deposit = tradeObject.options.deposit let datas = JSON.parse(JSON.stringify(objectWithoutKey(tradeObject, 'options'))) // deep copy to prevent alteration res.render('dashboard', datas) }) diff --git a/lib/engine.js b/lib/engine.js index f969e4770f..b3d45c400a 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -62,10 +62,10 @@ module.exports = function (s, conf) { s.exchange.setFees({asset: s.asset, currency: s.currency}) } if (so.mode === 'sim' || so.mode === 'paper') { - s.balance = {asset: so.asset_capital, currency: so.currency_capital} + s.balance = {asset: so.asset_capital, currency: so.currency_capital, deposit: 0} } else { - s.balance = {asset: 0, currency: 0} + s.balance = {asset: 0, currency: 0, deposit: 0} } function memDump () { @@ -85,6 +85,7 @@ module.exports = function (s, conf) { } let asset_col_width = 0 + let deposit_col_width = 0 let currency_col_width = 0 s.lookback = [] s.day_count = 1 @@ -211,20 +212,31 @@ module.exports = function (s, conf) { } function syncBalance (cb) { + let pre_asset = so.mode === 'sim' ? s.sim_asset : s.balance.asset s.exchange.getBalance({currency: s.currency, asset: s.asset}, function (err, balance) { if (err) return cb(err) + let diff_asset = n(pre_asset).subtract(balance.asset) s.balance = balance getQuote(function (err, quote) { if (err) return cb(err) + let post_currency = n(diff_asset).multiply(quote.ask) + s.asset_capital = n(s.balance.asset).multiply(quote.ask).value() + let deposit = so.deposit ? Math.max(0, n(so.deposit).subtract(s.asset_capital)) : s.balance.currency // zero on negative + s.balance.deposit = n(deposit < s.balance.currency ? deposit : s.balance.currency).value() if (!s.start_capital) { s.start_price = n(quote.ask).value() - s.start_capital = n(s.balance.currency).add(n(s.balance.asset).multiply(quote.ask)).value() + s.start_capital = n(s.balance.deposit).add(s.asset_capital).value() + s.real_capital = n(s.balance.currency).add(s.asset_capital).value() + s.net_currency = s.balance.deposit - pushMessage('Balance ' + s.exchange.name.toUpperCase(), 'sync balance ' + s.start_capital + ' ' + s.currency + '\n') + if (so.mode !== 'sim') { + pushMessage('Balance ' + s.exchange.name.toUpperCase(), 'sync balance ' + s.real_capital + ' ' + s.currency + '\n') + } + } else { + s.net_currency = n(s.net_currency).add(post_currency).value() } - s.asset_capital = n(s.balance.asset).multiply(quote.ask).value() cb(null, { balance, quote }) }) }) @@ -352,7 +364,7 @@ module.exports = function (s, conf) { } if (is_reorder && s[signal + '_order']) { if (signal === 'buy') { - reorder_pct = n(size).multiply(s.buy_order.price).add(s.buy_order.fee).divide(s.balance.currency).multiply(100) + reorder_pct = n(size).multiply(s.buy_order.price).add(s.buy_order.fee).divide(s.balance.deposit).multiply(100) } else { reorder_pct = n(size).divide(s.balance.asset).multiply(100) } @@ -372,13 +384,6 @@ module.exports = function (s, conf) { } else { buy_pct = so.buy_pct } - if (so.buy_max_amt) { // account for held assets as buy_max - let adjusted_buy_max_amt = n(so.buy_max_amt).subtract(s.asset_capital).value() - if(adjusted_buy_max_amt < s.balance.currency){ - let buy_max_as_pct = n(adjusted_buy_max_amt).divide(s.balance.currency).multiply(100).value() - buy_pct = buy_max_as_pct - } - } if (so.use_fee_asset) { fee = 0 } else if (so.order_type === 'maker' && (buy_pct + s.exchange.takerFee < 100 || !s.exchange.makerBuy100Workaround)) { @@ -386,8 +391,8 @@ module.exports = function (s, conf) { } else { fee = s.exchange.takerFee } - trade_balance = n(s.balance.currency).divide(100).multiply(buy_pct) - tradeable_balance = n(s.balance.currency).divide(100 + fee).multiply(buy_pct) + trade_balance = n(s.balance.deposit).divide(100).multiply(buy_pct) + tradeable_balance = n(s.balance.deposit).divide(100 + fee).multiply(buy_pct) expected_fee = n(trade_balance).subtract(tradeable_balance).format('0.00000000', Math.ceil) // round up as the exchange will too if (buy_pct + fee < 100) { size = n(tradeable_balance).divide(price).format(s.product.asset_increment ? s.product.asset_increment : '0.00000000') @@ -416,8 +421,8 @@ module.exports = function (s, conf) { return cb(err) } } - if (n(s.balance.currency).subtract(s.balance.currency_hold || 0).value() < n(price).multiply(size).value() && s.balance.currency_hold > 0) { - msg('buy delayed: ' + formatPercent(n(s.balance.currency_hold || 0).divide(s.balance.currency).value()) + ' of funds (' + formatCurrency(s.balance.currency_hold, s.currency) + ') on hold') + if (n(s.balance.deposit).subtract(s.balance.currency_hold || 0).value() < n(price).multiply(size).value() && s.balance.currency_hold > 0) { + msg('buy delayed: ' + formatPercent(n(s.balance.currency_hold || 0).divide(s.balance.deposit).value()) + ' of funds (' + formatCurrency(s.balance.currency_hold, s.currency) + ') on hold') return setTimeout(function () { if (s.last_signal === signal) { executeSignal(signal, cb, size, true) @@ -726,14 +731,21 @@ module.exports = function (s, conf) { let asset_col = n(s.balance.asset).format(s.asset === 'BTC' ? '0.00000' : '0.00000000') + ' ' + s.asset asset_col_width = Math.max(asset_col.length + 1, asset_col_width) process.stdout.write(z(asset_col_width, asset_col, ' ').white) - let currency_col = n(s.balance.currency).format(isFiat() ? '0.00' : '0.00000000') + ' ' + s.currency - currency_col_width = Math.max(currency_col.length + 1, currency_col_width) - process.stdout.write(z(currency_col_width, currency_col, ' ').yellow) - let consolidated = n(s.balance.currency).add(n(s.period.close).multiply(s.balance.asset)).value() - let profit = (consolidated - orig_capital) / orig_capital + let deposit_col = n(s.balance.deposit).format(isFiat() ? '0.00' : '0.00000000') + ' ' + s.currency + deposit_col_width = Math.max(deposit_col.length + 1, deposit_col_width) + process.stdout.write(z(deposit_col_width, deposit_col, ' ').yellow) + if (so.deposit) { + let currency_col = n(s.balance.currency).format(isFiat() ? '0.00' : '0.00000000') + ' ' + s.currency + currency_col_width = Math.max(currency_col.length + 1, currency_col_width) + process.stdout.write(z(currency_col_width, currency_col, ' ').green) + let circulating = s.balance.currency > 0 ? n(s.balance.deposit).divide(s.balance.currency) : n(0) + process.stdout.write(z(8, n(circulating).format('0.00%'), ' ').grey) + } + let consolidated = n(s.net_currency).add(n(s.balance.asset).multiply(s.period.close)) + let profit = n(consolidated).divide(orig_capital).subtract(1).value() process.stdout.write(z(8, formatPercent(profit), ' ')[profit >= 0 ? 'green' : 'red']) - let buy_hold = s.period.close * (orig_capital / orig_price) - let over_buy_hold_pct = (consolidated - buy_hold) / buy_hold + let buy_hold = n(orig_capital).divide(orig_price).multiply(s.period.close) + let over_buy_hold_pct = n(consolidated).divide(buy_hold).subtract(1).value() process.stdout.write(z(8, formatPercent(over_buy_hold_pct), ' ')[over_buy_hold_pct >= 0 ? 'green' : 'red']) } if (!is_progress) { @@ -749,16 +761,6 @@ module.exports = function (s, conf) { if (so.mode !== 'live') s.exchange.processTrade(trade) - if (so.mode !== 'live' && !s.start_capital) { - s.start_capital = 0 - s.start_price = trade.price - if (so.asset_capital) { - s.start_capital += so.asset_capital * s.start_price - } - if (so.currency_capital) { - s.start_capital += so.currency_capital - } - } if (!so.manual) { executeStop() @@ -805,7 +807,7 @@ module.exports = function (s, conf) { } syncBalance(function () { let on_hold - if (type === 'buy') on_hold = n(s.balance.currency).subtract(s.balance.currency_hold || 0).value() < n(order.price).multiply(order.remaining_size).value() + if (type === 'buy') on_hold = n(s.balance.deposit).subtract(s.balance.currency_hold || 0).value() < n(order.price).multiply(order.remaining_size).value() else on_hold = n(s.balance.asset).subtract(s.balance.asset_hold || 0).value() < n(order.remaining_size).value() if (on_hold && s.balance.currency_hold > 0) { @@ -965,7 +967,7 @@ module.exports = function (s, conf) { z(10, 'VOL', ' ').grey, z(8, 'RSI', ' ').grey, z(32, 'ACTIONS', ' ').grey, - z(25, 'BAL', ' ').grey, + z(so.deposit ? 38 : 25, 'BAL', ' ').grey, z(22, 'PROFIT', ' ').grey ].join('') + '\n') }, diff --git a/templates/dashboard.ejs b/templates/dashboard.ejs index 1f45a82990..e9566e1f75 100644 --- a/templates/dashboard.ejs +++ b/templates/dashboard.ejs @@ -97,13 +97,21 @@

Capital

-
+
  • Asset
  • <%= new Intl.NumberFormat("en-US", {useGrouping: false, minimumFractionDigits: 2, maximumFractionDigits: 8}).format(balance.asset) %> <%= asset.toUpperCase() %>
-
+ <% if (typeof deposit != "undefined") { %> +
+
    +
  • Deposit
  • +
  • <%= new Intl.NumberFormat("en-US", {useGrouping: false, minimumFractionDigits: 2, maximumFractionDigits: 8}).format(balance.deposit) %> <%= currency.toUpperCase() %>
  • +
+
+ <% } %> +
  • Currency
  • <%= new Intl.NumberFormat("en-US", {useGrouping: false, minimumFractionDigits: 2, maximumFractionDigits: 8}).format(balance.currency) %> <%= currency.toUpperCase() %>
  • diff --git a/test/lib/engine.test.js b/test/lib/engine.test.js index c695152b26..ace327ee77 100644 --- a/test/lib/engine.test.js +++ b/test/lib/engine.test.js @@ -3,68 +3,68 @@ var EventEmitter = require('events') describe('Engine', function() { describe('executeSignal', function() { describe('when maker in live mode', function(){ - describe('with buy_max set', function(){ - it('and no held assets should use raw buy_max_amt', function(){ + describe('with deposit set', function(){ + it('and no held assets should use raw deposit', function(){ // arrange var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'maker' var held_asset = 0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert - var expected = '2.77500277' + var expected = '1.38750138' var buyArgs = buy_spy.calls.mostRecent().args[0] expect(buyArgs.size).toBe(expected) }) - it('and held assets should use adjusted buy_max_amt', function(){ + it('and held assets should use adjusted deposit', function(){ // arrange var signal_type = 'buy' - var currency_amount = 3.0 + var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'maker' - var held_asset = 0.75 + var held_asset = 0.25 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert - var expected = '1.85925185' + var expected = '1.23487623' var buyArgs = buy_spy.calls.mostRecent().args[0] expect(buyArgs.size).toBe(expected) }) - it('and held assets so large adjusted buy_max_amt is below order minimum should not place order', function(){ + it('and held assets so large adjusted deposit is below order minimum should not place order', function(){ // arrange var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'maker' var held_asset = 2.0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert expect(buy_spy).not.toHaveBeenCalled() }) }) - describe('with no buy_max set', function(){ + describe('with no deposit set', function(){ it('and no held assets should use raw buy_pct', function(){ // arrange var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'maker' var held_asset = 0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -79,11 +79,11 @@ describe('Engine', function() { var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'maker' var held_asset = 0.5 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -96,11 +96,11 @@ describe('Engine', function() { var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'maker' var held_asset = 10.25 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -111,70 +111,70 @@ describe('Engine', function() { }) describe('when taker in live mode', function(){ - describe('with buy_max_amt set',function(){ - it('and no held assets should use raw buy_max_amt', function(){ + describe('with deposit set',function(){ + it('and no held assets should use raw deposit', function(){ // arrange var signal_type = 'buy' var currency_amount = 1 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'taker' var held_asset = 0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert - var expected = '2.77223331' + var expected = '1.38611665' var buyArgs = buy_spy.calls.mostRecent().args[0] expect(buyArgs.size).toBe(expected) }) - it('and held assets should use adjusted buy_max_amt', function(){ + it('and held assets should use adjusted deposit', function(){ // arrange var signal_type = 'buy' - var currency_amount = 3.0 + var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'taker' - var held_asset = 0.75 + var held_asset = 0.25 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert - var expected = '1.85739631' + var expected = '1.23364382' var buyArgs = buy_spy.calls.mostRecent().args[0] expect(buyArgs.size).toBe(expected) }) - it('and held assets so large adjusted buy_max_amt is below order minimum should not place order', function(){ + it('and held assets so large adjusted deposit is below order minimum should not place order', function(){ // arrange var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = 0.25 + var deposit = 0.25 var order_type = 'taker' var held_asset = 2.0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert expect(buy_spy).not.toHaveBeenCalled() }) }) - describe('with no buy_max_amt set',function(){ - it('with no buy_max_amt set and no held assets should use raw buy_pct', function(){ + describe('with no deposit set',function(){ + it('with no deposit set and no held assets should use raw buy_pct', function(){ // arrange var signal_type = 'buy' var currency_amount = 1 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'taker' var held_asset = 0 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -188,11 +188,11 @@ describe('Engine', function() { var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'taker' var held_asset = 0.5 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -205,11 +205,11 @@ describe('Engine', function() { var signal_type = 'buy' var currency_amount = 1.0 var buy_pct = 50 - var buy_max_amt = undefined + var deposit = undefined var order_type = 'taker' var held_asset = 5.25 var buy_spy = jasmine.createSpy('buy') - var sut = createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy) + var sut = createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy) // act sut.executeSignal(signal_type) // assert @@ -224,7 +224,7 @@ describe('Engine', function() { var mock = require('mock-require') var path = require('path') -function createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_asset, buy_spy){ +function createEngine(currency_amount, buy_pct, deposit, order_type, held_asset, buy_spy){ var fake_asset = 'test_asset' var fake_currency = 'BTC' var fake_exchange = 'test_exchange' @@ -280,7 +280,7 @@ function createEngine(currency_amount, buy_pct, buy_max_amt, order_type, held_as mode:'live', order_type: order_type, buy_pct:buy_pct, - buy_max_amt:buy_max_amt + deposit:deposit } } var engine = require('../../lib/engine')