[#31] Limit für Anzahl offener Transaktionen pro Worker eingeführt

This commit is contained in:
darkeye 2025-01-15 15:16:47 +01:00
parent 2b3a0e3102
commit 83d22f970d
5 changed files with 29 additions and 5 deletions

View File

@ -268,7 +268,7 @@ export default class TradingBot {
this.#worker.forEach(worker => { this.#worker.forEach(worker => {
if (worker.getTradingPair().getKey() === assetUpdateEvent.tradingPair.getKey()) { 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());
} }
}); });
} }

View File

@ -44,6 +44,11 @@ export default class BotConfig extends Serializable {
*/ */
#maxUSDPerTrade = 50.0; #maxUSDPerTrade = 50.0;
/**
* @type {number} max amount of active transactions per worker
*/
#maxTransactionsPerWorker = 6;
/** /**
* @type {boolean} if rest interface should be enabled * @type {boolean} if rest interface should be enabled
*/ */
@ -219,6 +224,20 @@ export default class BotConfig extends Serializable {
this.#rampupTime = chronoString; this.#rampupTime = chronoString;
} }
/**
* @returns {number}
*/
getMaxTransactionsPerWorker(){
return this.#maxTransactionsPerWorker;
}
/**
* @param {number} max
*/
setMaxTransactionsPerWorker(max){
this.#maxTransactionsPerWorker = max;
}
/** /**
* @returns {string} string representation of this object * @returns {string} string representation of this object
*/ */
@ -234,6 +253,7 @@ export default class BotConfig extends Serializable {
obj.restInterfaceEnabled = this.#enableRestInterface; obj.restInterfaceEnabled = this.#enableRestInterface;
obj.restInterfacePort = this.#restInterfacePort; obj.restInterfacePort = this.#restInterfacePort;
obj.rampupTime = this.#rampupTime; obj.rampupTime = this.#rampupTime;
obj.maxTransactionsPerWorker = this.#maxTransactionsPerWorker;
return JSON.stringify(obj); return JSON.stringify(obj);
} }
@ -256,6 +276,7 @@ export default class BotConfig extends Serializable {
conf.#enableRestInterface = obj.restInterfaceEnabled; conf.#enableRestInterface = obj.restInterfaceEnabled;
conf.#restInterfacePort = obj.restInterfacePort; conf.#restInterfacePort = obj.restInterfacePort;
conf.#rampupTime = obj.rampupTime; conf.#rampupTime = obj.rampupTime;
conf.#maxTransactionsPerWorker = obj.maxTransactionsPerWorker;
return conf; return conf;
} }

View File

@ -139,8 +139,9 @@ export default class AbstractWorker extends Serializable {
/** /**
* @param {AssetData} assetData * @param {AssetData} assetData
* @param {Transaction[]} transactions * @param {Transaction[]} transactions
* @param {number} transactionlimit
*/ */
onUpdate(assetData, transactions){ onUpdate(assetData, transactions, transactionlimit){
// TODO implement update // TODO implement update
} }

View File

@ -25,12 +25,13 @@ export default class DefaultWorker extends AbstractWorker{
/** /**
* @param {AssetData} assetData * @param {AssetData} assetData
* @param {Transaction[]} transactions * @param {Transaction[]} transactions
* @param {number} transactionlimit
*/ */
onUpdate(assetData, transactions){ onUpdate(assetData, transactions, transactionlimit){
this.getStrategy().setAssetData(assetData); this.getStrategy().setAssetData(assetData);
const price = parseFloat(this.getStrategy().getAssetData().getOrderBook().getBestBid().price); 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); this.getApiProvider().requestBuy(this, Math.round(50 / price), price);
} }

View File

@ -103,8 +103,9 @@ export default class StatisticWorker extends AbstractWorker {
/** /**
* @param {AssetData} assetData * @param {AssetData} assetData
* @param {Transaction[]} transactions * @param {Transaction[]} transactions
* @param {number} transactionlimit
*/ */
onUpdate(assetData, transactions) { onUpdate(assetData, transactions, transactionlimit) {
const strategy = this.getStrategy(); const strategy = this.getStrategy();
if(strategy != null){ if(strategy != null){
strategy.setAssetData(assetData); strategy.setAssetData(assetData);