Read Closed Trades

Ask the terminal its own history. Keep only what closed.

On every pass the journal queries a rolling window of the terminal's own history and rebuilds each finished trade from the raw deals it left behind.

HistoryReader.py
# rolling window of finished deals
deals = history_deals("-30d", now)

for d in deals:
    if d.magic != STRATEGY_MAGIC:
        continue            # not ours
    book[d.position_id].add(d)

trades = pair_open_close(book)

Two deals become one trade

A position leaves two footprints: the deal that opened it and the deal that closed it. Same position id, same magic. Paired, they collapse into a single closed trade.

OPEN DEAL position #48213 · magic 77 entry price · entry time CLOSE DEAL position #48213 · magic 77 exit price · exit time same id CLOSED TRADE entry → exit · result stop · target read from orders

Only ours, fully reconstructed

The magic number is the filter. The stop and the target are pulled straight from the orders, so the trade lands complete.

Filter by magickeep only the strategy's deals
Pair by position idopen deal meets close deal
Stop and target from the orders

Written once, never twice

A trade already on the sheet is skipped on sight. The reading is safe to run again and again.

Read window Pair deals Skip if already written New closed trade