[#34] Verarbeitung von balance change events

This commit is contained in:
darkeye 2025-01-15 14:59:36 +01:00
parent c98ac43d52
commit 2b3a0e3102
2 changed files with 17 additions and 16 deletions

View File

@ -238,8 +238,7 @@ export default class TradingBot {
handleAccountUpdate(accountUpdateEvent) { handleAccountUpdate(accountUpdateEvent) {
switch (accountUpdateEvent.eventType) { switch (accountUpdateEvent.eventType) {
case APIEventType.BALANCE_CHANGE: case APIEventType.BALANCE_CHANGE:
this.#logger.info("Balance update: ", accountUpdateEvent); this.#accountInfo.updateBalances(accountUpdateEvent);
// TODO update changed balances
break; break;
case APIEventType.TRANSACTION_UPDATE: case APIEventType.TRANSACTION_UPDATE:
this.#updateTransaction(accountUpdateEvent); this.#updateTransaction(accountUpdateEvent);

View File

@ -1,3 +1,4 @@
import BalanceChangeEvent from "../../../apiwrapper/event/BalanceChangeEvent.js";
import AccountRights from "./AccountRights.js"; import AccountRights from "./AccountRights.js";
import AccountStatus from "./AccountStatus.js"; import AccountStatus from "./AccountStatus.js";
@ -23,9 +24,14 @@ export default class AccountInfo {
*/ */
#balances = new Map(); #balances = new Map();
/**
* @type {number}
*/
#lastBalanceUpdate = 0;
constructor() { constructor() {
//super();
this.#updateTime = Date.now(); this.#updateTime = Date.now();
this.#lastBalanceUpdate = Date.now();
} }
/** /**
@ -84,23 +90,19 @@ export default class AccountInfo {
} }
/** /**
* @param {AccountInformation} accountInfo * @param {BalanceChangeEvent} balanceEvent
*/ */
update(accountInfo) { updateBalances(balanceEvent){
// TODO if(balanceEvent.timestamp < this.#lastBalanceUpdate){
/*if (accountInfo == null) {
return; return;
} }
this.#updateTime = accountInfo.updateTime; balanceEvent.changedBalances.forEach((balance, symbol) => {
this.#canDeposit = accountInfo.canDeposit; if(balance > 0 || this.#balances.has(symbol)){
this.#canTrade = accountInfo.canTrade; this.#balances.set(symbol, balance);
this.#canWithdraw = accountInfo.canWithdraw;
for (let balance of accountInfo.balances) {
if (balance.free > 0) {
this.#balances.set(balance.asset, balance.free);
} }
}*/ });
this.#lastBalanceUpdate = balanceEvent.timestamp;
} }
} }