import MetaTrader5 as mt5
from datetime import datetime, timedelta

mt5.initialize()

# Pull ALL deals in the last 3 days, no filter
deals = mt5.history_deals_get(datetime.now() - timedelta(days=3), datetime.now())
print(f"Total deals returned: {len(deals) if deals else 0}")
print("=" * 80)

if deals:
    for d in deals:
        if d.symbol == "EURUSD":
            entry_label = {0: "IN", 1: "OUT", 2: "INOUT", 3: "OUT_BY"}.get(d.entry, str(d.entry))
            print(f"  deal_ticket={d.ticket}  pos_id={d.position_id}  "
                  f"type={'BUY' if d.type==0 else 'SELL' if d.type==1 else d.type}  "
                  f"entry={entry_label}  vol={d.volume}  price={d.price}  "
                  f"profit={d.profit}  swap={d.swap}  "
                  f"time={datetime.fromtimestamp(d.time)}")

print("=" * 80)

# Also check orders history for that position
orders = mt5.history_orders_get(datetime.now() - timedelta(days=3), datetime.now())
print(f"Total orders returned: {len(orders) if orders else 0}")
if orders:
    for o in orders:
        if o.symbol == "EURUSD":
            print(f"  order_ticket={o.ticket}  pos_id={o.position_id}  "
                  f"type={o.type}  state={o.state}  "
                  f"price_open={o.price_open}  vol={o.volume_initial}  "
                  f"time_setup={datetime.fromtimestamp(o.time_setup)}")

mt5.shutdown()
