From f2ccf0aca3fbadddc900d5d4b887f756c26b81a2 Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Thu, 26 Feb 2026 23:14:20 +0100 Subject: [PATCH] Fix exchange order double-counting in saveTradingLog For transfer/deposit commands between exchanges, the destination exchange balance updates (via WebSocket/API) before the order is marked complete. This caused inputAmount to be counted twice: once in liquidity (updated balance) and once in exchangeOrder (IN_PROGRESS order). Now only counts exchangeOrder when the action system matches the target asset's exchange (funds leaving), skipping when funds arrive from another exchange where the balance already reflects those funds. --- src/subdomains/supporting/log/log-job.service.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/subdomains/supporting/log/log-job.service.ts b/src/subdomains/supporting/log/log-job.service.ts index dc6e98587a..0ff2287301 100644 --- a/src/subdomains/supporting/log/log-job.service.ts +++ b/src/subdomains/supporting/log/log-job.service.ts @@ -454,10 +454,16 @@ export class LogJobService { const cryptoInput = [Blockchain.MONERO, Blockchain.LIGHTNING, Blockchain.ZANO].includes(curr.blockchain) ? 0 : pendingPayIns.reduce((sum, tx) => sum + (tx.asset.id === curr.id ? tx.amount : 0), 0); - const exchangeOrder = pendingExchangeOrders.reduce( - (sum, tx) => sum + (tx.pipeline.rule.targetAsset.id === curr.id ? tx.inputAmount : 0), - 0, - ); + const exchangeOrder = pendingExchangeOrders.reduce((sum, tx) => { + if (tx.pipeline.rule.targetAsset.id !== curr.id) return sum; + + // for transfer/deposit: only count when action.system matches the target asset's exchange + // (funds leaving this exchange, balance decreased). Skip when funds arrive from another + // exchange, as the destination balance already reflects those funds before order completion. + if (tx.action.command !== 'withdraw' && tx.action.system !== (curr.blockchain as string)) return sum; + + return sum + tx.inputAmount; + }, 0); const bridgeOrder = pendingBridgeOrders.reduce( (sum, tx) => sum + (tx.pipeline.rule.targetAsset.id === curr.id ? tx.inputAmount : 0), 0,