INNER CODE UNIT · Python

get_history

flukelaster/ai-trading-agent · mt5_bridge/main.py:463

async def get_history(days: int = 1, symbol: str | None = None):
    """Get closed deals (trades) from the last N days, optionally filtered by symbol."""
    if not ensure_connected():
        return mt5_response(False, error="MT5 not connected")

    from_date = datetime.now() - timedelta(days=days)
    to_date = datetime.now() + timedelta(days=1)

    deals = mt5.history_deals_get(from_date, to_date)
    if deals is None:
        return mt5_response(True, data=[])

    result = []
    for deal in deals:
        if deal.entry == 1 and deal.type in (0, 1):  # entry=1 means exit, type 0=buy 1=sell
            if symbol and deal.symbol != symbol:
                continue
            result.append({

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…