[#31] Limit für Anzahl offener Transaktionen pro Worker eingeführt
This commit is contained in:
parent
2b3a0e3102
commit
83d22f970d
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user