<code># 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)
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
</code>
<code># 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)
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
</code>
# 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)
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
<code> 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
</code>
<code> 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
</code>
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
New contributor
Vishu singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1