Skip to content

generate_account_report shows inconsistent results as it keeps mutable AccountBalance as reference #2701

@DeirhX

Description

@DeirhX

Bug Report

I've noticed strange behaviour of engine.trader.generate_account_report() as it often contains repeated values and doesn't show all movements compared to the logs. After implementing it in my strategy, I found out that it likely keeps AccountBalance instances as references, so they often change after the events (I assume strategy.cache.account_for_venue().events) are emitted.

TLDR: The AccountState event doesn't do a deep copy of the AccountBalance object, so it often gets shared and mutated after the event was emitted.

Expected Behavior

engine.trader.generate_account_report() shows correct history of account movements

Actual Behavior

engine.trader.generate_account_report() often hides events if there are some movements that haven't created a new AccountBalance object. However, if I gather the events myself and call deepcopy on the AccountBalance object, I see correct values. Without the deepcopy, I see the same values as generate_account_report() returns and I've confirmed them changing in the debugger.

Steps to Reproduce the Problem

I can create a repro if needed, but it might not be trivial.

  • OS platform: Windows 11 WSL 1
  • Python version: 3.12.3
  • nautilus_trader version: beta v1.218.0, also 77d28a1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions