﻿import MetaTrader5 as mt5
import pandas as pd
from datetime import datetime, timedelta

mt5.initialize()

# Pull a small recent chunk
since = datetime(2026, 5, 1)
until = datetime(2026, 5, 5)
bars = mt5.copy_rates_range("EURUSD", mt5.TIMEFRAME_M15, since, until)

print(f"Type of return: {type(bars)}")
print(f"Length: {len(bars) if bars is not None else None}")
print()

if bars is not None and len(bars) > 0:
    print("Raw structured array first 3 entries:")
    print(bars[:3])
    print()
    print(f"Field names (if structured): {bars.dtype.names if hasattr(bars, 'dtype') else 'N/A'}")
    print()
    
    df = pd.DataFrame(bars)
    print(f"DataFrame columns: {list(df.columns)}")
    print(f"DataFrame dtypes:")
    print(df.dtypes)
    print()
    print("First 3 rows:")
    print(df.head(3))

mt5.shutdown()
