Skip to content

Fix exchange order double-counting in financial log#3281

Merged
TaprootFreak merged 1 commit intodevelopfrom
fix/exchange-order-double-counting
Feb 27, 2026
Merged

Fix exchange order double-counting in financial log#3281
TaprootFreak merged 1 commit intodevelopfrom
fix/exchange-order-double-counting

Conversation

@TaprootFreak
Copy link
Collaborator

Summary

  • Fixes double-counting of exchange order inputAmount in saveTradingLog() when funds arrive at the destination exchange before the order is marked complete
  • For transfer/deposit commands between exchanges, the destination balance (updated via WebSocket/API) already includes the transferred funds, but the IN_PROGRESS order's inputAmount was also added — causing alternating valid/invalid log entries
  • Now only counts exchangeOrder when action.system matches the target asset's exchange (funds leaving this exchange), skipping when funds arrive from another exchange

Root cause

When a transfer order moves funds from exchange A to exchange B (e.g. Kraken → Scrypt):

  1. action.system = source exchange (Kraken)
  2. targetAsset = managed asset on destination (Scrypt/USDT)
  3. Scrypt balance updates immediately (WebSocket subscription)
  4. Order stays IN_PROGRESS until deposit confirmed in Scrypt's deposit list
  5. saveTradingLog counts both liquidity (updated balance) and exchangeOrder (pending order) → double-count

Test plan

  • Verify financial log entries no longer alternate between valid/invalid
  • Verify Scrypt/USDT exchangeOrder is 0 when transfer order has already been reflected in balance
  • Verify withdrawal orders (exchange → blockchain) still correctly compensate for decreased exchange balance
  • Verify redundancy transfer orders (funds leaving target exchange) are still counted

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.
@TaprootFreak TaprootFreak marked this pull request as ready for review February 26, 2026 22:15
@TaprootFreak TaprootFreak merged commit f58cdc9 into develop Feb 27, 2026
8 checks passed
@TaprootFreak TaprootFreak deleted the fix/exchange-order-double-counting branch February 27, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants