[Python] Trying to extract live data from mt5 to my python script but getting data 10 hours...

Discussão em 'Python' iniciado por Stack, Junho 19, 2025.

  1. Stack

    Stack Membro Participativo

    # Fetch historical bars for a specific symbol and time range
    def get_bars(symbol, timeframe, start_date, end_date):
    if not mt5.symbol_select(symbol, True):
    print(f"Failed to select symbol: {symbol}")
    return None

    rates = mt5.copy_rates_range(symbol, timeframe, start_date, end_date)



    output generated by code

    Date: 2024-07-23 08:30:00, Type: Bullish, Gap: 31.44, First High: 66655.37, Third Low: 66686.81
    Date: 2024-07-23 08:33:00, Type: Bullish, Gap: 105.20, First High: 66741.48, Third Low: 66846.68
    Date: 2024-07-23 09:30:00, Type: Bullish, Gap: 3.41, First High: 66917.66, Third Low: 66921.07
    Date: 2024-07-23 09:33:00, Type: Bullish, Gap: 25.20, First High: 66974.76, Third Low: 66999.96
    Date: 2024-07-23 10:48:00, Type: Bearish, Gap: 24.62, First Low: 66936.30, Third High: 66911.68
    Date: 2024-07-23 11:03:00, Type: Bearish, Gap: 79.14, First Low: 66829.84, Third High: 66750.70
    Date: 2024-07-23 11:24:00, Type: Bearish, Gap: 40.32, First Low: 66610.38, Third High: 66570.06
    Date: 2024-07-23 11:33:00, Type: Bullish, Gap: 37.54, First High: 66613.56, Third Low: 66651.10

    if rates is None:
    print(f"Failed to get rates for symbol: {symbol}")
    return None

    df = pd.DataFrame(rates)
    df['time'] = pd.to_datetime(df['time'], unit='s') # Convert Unix timestamp to datetime
    return df


    also this is in the main function

    while True:
    now = datetime.now() # Get the current time
    end_date = now # Use current time as end_date
    start_date = now - timedelta(days=1) # Look back 1 day for data


    this is the snippet of data extractions but its only extracting data which 5-10 hours not the realtime please help me outa here

    please help me if i am doing something wrong

    Continue reading...

Compartilhe esta Página