INNER CODE UNIT · Python

get_ohlcv

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

async def get_ohlcv(symbol: str, timeframe: str = "M15", count: int = 100):
    if not ensure_connected():
        return mt5_response(False, error="MT5 not connected")
    tf = TIMEFRAMES.get(timeframe.upper())
    if tf is None:
        return mt5_response(False, error=f"Invalid timeframe: {timeframe}")
    rates = mt5.copy_rates_from_pos(symbol, tf, 0, count)
    if rates is None or len(rates) == 0:
        return mt5_response(False, error=f"No OHLCV data for {symbol}")
    data = []
    for r in rates:
        data.append({
            "time": datetime.fromtimestamp(r["time"]).isoformat(),
            "open": float(r["open"]),
            "high": float(r["high"]),
            "low": float(r["low"]),
            "close": float(r["close"]),
            "tick_volume": int(r["tick_volume"]),

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…