fix(trader): trader now gets disabled just after config change (bug #40)
This commit is contained in:
parent
fba1f972c7
commit
ed3779ede4
1 changed files with 22 additions and 5 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue