diff --git a/lib/plugins.js b/lib/plugins.js index 9e8b2601..1ebbfdfc 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -106,7 +106,8 @@ function loadOrConfigPlugin(pluginHandle, pluginType, currency, onChangeCallback var currentName = cachedConfig.exchanges.plugins.current[pluginType]; var pluginChanged = currentlyUsedPlugins[pluginType] !== currentName; - if (currentName) { // some plugins may be disabled + if (!currentName) pluginHandle = null; + else { // some plugins may be disabled var pluginConfig = cachedConfig.exchanges.plugins.settings[currentName] || {}; if (currency) pluginConfig.currency = currency; @@ -115,7 +116,7 @@ function loadOrConfigPlugin(pluginHandle, pluginType, currency, onChangeCallback else pluginHandle = loadPlugin(currentName, pluginConfig); } - if (typeof onChangeCb === 'function') onChangeCb(pluginHandle, currency); + if (typeof onChangeCallback === 'function') onChangeCallback(pluginHandle, currency); return pluginHandle; } @@ -154,7 +155,13 @@ exports.configure = function configure(config) { // TRADER [optional] configure (or load) traderPlugin = loadOrConfigPlugin( traderPlugin, - 'trade' + 'trade', + null, + function onTraderChange(newTrader) { + traderPlugin = newTrader; + if (newTrader === null) stopTrader(); + else startTrader(); + } ); // ID VERIFIER [optional] configure (or load) @@ -276,17 +283,27 @@ exports.startPolling = function startPolling() { rateInterval = setInterval(pollRate, POLLING_RATE); } + startTrader(); +}; + +function startTrader() { // Always start trading, even if we don't have a trade exchange configured, // since configuration can always change in `Trader#configure`. // `Trader#executeTrades` returns early if we don't have a trade exchange // configured at the moment. - if (!tradeInterval) { + if (traderPlugin && !tradeInterval) { tradeInterval = setInterval( executeTrades, cachedConfig.exchanges.settings.tradeInterval ); } -}; +} +function stopTrader() { + if (tradeInterval) { + clearInterval(tradeInterval); + tradeInterval = null; + } +} function pollBalance(callback) {