diff --git a/src/js/tradingbot/TradingBot.js b/src/js/tradingbot/TradingBot.js index a0e898c..91bb182 100644 --- a/src/js/tradingbot/TradingBot.js +++ b/src/js/tradingbot/TradingBot.js @@ -268,7 +268,7 @@ export default class TradingBot { this.#worker.forEach(worker => { if (worker.getTradingPair().getKey() === assetUpdateEvent.tradingPair.getKey()) { - worker.onUpdate(this.#dataCollector.getAssetData(worker.getTradingPair()), this.#transactions.filter(t => t.initiator = worker.getId())); + worker.onUpdate(this.#dataCollector.getAssetData(worker.getTradingPair()), this.#transactions.filter(t => t.initiator = worker.getId()), this.#config.getMaxTransactionsPerWorker()); } }); } diff --git a/src/js/tradingbot/config/BotConfig.js b/src/js/tradingbot/config/BotConfig.js index d5fffb4..a9a384f 100644 --- a/src/js/tradingbot/config/BotConfig.js +++ b/src/js/tradingbot/config/BotConfig.js @@ -44,6 +44,11 @@ export default class BotConfig extends Serializable { */ #maxUSDPerTrade = 50.0; + /** + * @type {number} max amount of active transactions per worker + */ + #maxTransactionsPerWorker = 6; + /** * @type {boolean} if rest interface should be enabled */ @@ -219,6 +224,20 @@ export default class BotConfig extends Serializable { this.#rampupTime = chronoString; } + /** + * @returns {number} + */ + getMaxTransactionsPerWorker(){ + return this.#maxTransactionsPerWorker; + } + + /** + * @param {number} max + */ + setMaxTransactionsPerWorker(max){ + this.#maxTransactionsPerWorker = max; + } + /** * @returns {string} string representation of this object */ @@ -234,6 +253,7 @@ export default class BotConfig extends Serializable { obj.restInterfaceEnabled = this.#enableRestInterface; obj.restInterfacePort = this.#restInterfacePort; obj.rampupTime = this.#rampupTime; + obj.maxTransactionsPerWorker = this.#maxTransactionsPerWorker; return JSON.stringify(obj); } @@ -256,6 +276,7 @@ export default class BotConfig extends Serializable { conf.#enableRestInterface = obj.restInterfaceEnabled; conf.#restInterfacePort = obj.restInterfacePort; conf.#rampupTime = obj.rampupTime; + conf.#maxTransactionsPerWorker = obj.maxTransactionsPerWorker; return conf; } diff --git a/src/js/tradingbot/worker/AbstractWorker.js b/src/js/tradingbot/worker/AbstractWorker.js index 3766d07..603ef87 100644 --- a/src/js/tradingbot/worker/AbstractWorker.js +++ b/src/js/tradingbot/worker/AbstractWorker.js @@ -139,8 +139,9 @@ export default class AbstractWorker extends Serializable { /** * @param {AssetData} assetData * @param {Transaction[]} transactions + * @param {number} transactionlimit */ - onUpdate(assetData, transactions){ + onUpdate(assetData, transactions, transactionlimit){ // TODO implement update } diff --git a/src/js/tradingbot/worker/DefaultWorker.js b/src/js/tradingbot/worker/DefaultWorker.js index 55c1176..661b3ae 100644 --- a/src/js/tradingbot/worker/DefaultWorker.js +++ b/src/js/tradingbot/worker/DefaultWorker.js @@ -25,12 +25,13 @@ export default class DefaultWorker extends AbstractWorker{ /** * @param {AssetData} assetData * @param {Transaction[]} transactions + * @param {number} transactionlimit */ - onUpdate(assetData, transactions){ + onUpdate(assetData, transactions, transactionlimit){ this.getStrategy().setAssetData(assetData); const price = parseFloat(this.getStrategy().getAssetData().getOrderBook().getBestBid().price); - if(this.getStrategy().shouldBuy()){ + if(transactionlimit > transactions.length && this.getStrategy().shouldBuy()){ this.getApiProvider().requestBuy(this, Math.round(50 / price), price); } diff --git a/src/js/tradingbot/worker/StatisticWorker.js b/src/js/tradingbot/worker/StatisticWorker.js index 66c6652..78c60d5 100644 --- a/src/js/tradingbot/worker/StatisticWorker.js +++ b/src/js/tradingbot/worker/StatisticWorker.js @@ -103,8 +103,9 @@ export default class StatisticWorker extends AbstractWorker { /** * @param {AssetData} assetData * @param {Transaction[]} transactions + * @param {number} transactionlimit */ - onUpdate(assetData, transactions) { + onUpdate(assetData, transactions, transactionlimit) { const strategy = this.getStrategy(); if(strategy != null){ strategy.setAssetData(assetData);