diff options
author | uvok | 2025-04-18 19:35:55 +0200 |
---|---|---|
committer | uvok | 2025-04-18 19:35:55 +0200 |
commit | e090067631255ddfeb042545f62a8e95c26c7946 (patch) | |
tree | c3738c21eaac78d4c7ea33de3673a8f9b1a22486 /ledger_process.py | |
parent | 3efd930dcb0f42ed0484a08011de039386e2c38b (diff) |
Get rid of premature sorting
trade queue handles itself.
Deposit and withdrawal can be handles afterwards.
Diffstat (limited to 'ledger_process.py')
-rw-r--r-- | ledger_process.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/ledger_process.py b/ledger_process.py index d6b31fa..8b7a614 100644 --- a/ledger_process.py +++ b/ledger_process.py @@ -21,14 +21,11 @@ class LedgerProcess: # don't make any assumtptions about ledger sorting # groupby requires sorted inputs actions_sorted = sorted(read_actions, key=lambda a: (a.refid, a.timestamp)) - _grouped_actions = groupby(actions_sorted, lambda a: a.refid) - _list_tuple_actions = [(k, list(v)) for k, v in _grouped_actions] - # finally, sort groupy by first available timestamp - sorted_grouped_actions = sorted( - _list_tuple_actions, key=lambda a: a[1][0].timestamp - ) + grouped_actions = groupby(actions_sorted, lambda a: a.refid) + + process_after: List[LedgerAction] = [] - for refid, actions in sorted_grouped_actions: + for refid, actions in grouped_actions: actions = list(actions) if len(actions) == 0: @@ -40,12 +37,18 @@ class LedgerProcess: if action.type == "trade": self._process_trade(refid, actions) - elif action.type == "deposit" and action.asset != "EUR": + elif action.asset == "EUR": + continue + + elif action.type == "deposit" or action.type == "withdrawal": assert len(actions) == 1 + process_after.append(action) + + for action in sorted(process_after, key=lambda a: a.timestamp): + if action.type == "deposit" and action.asset != "EUR": self._process_deposit(action) elif action.type == "withdrawal" and action.asset != "EUR": - assert len(actions) == 1 self._process_withdrawal(action) def _process_deposit(self, action: LedgerAction): |