I want to get stock data from mt5 in Python, but the last 12 candles aren't available.
My code is like below:
from_date = datetime.now()
# Extract n Ticks before now
rates = mt5.copy_rates_from(symbol, timeframe, from_date, number_of_data)
# Transform Tuple into a DataFrame
df_rates = pd.DataFrame(rates)
# Convert number format of the date into date format
df_rates["time"] = pd.to_datetime(df_rates["time"], unit="s")
df_rates = df_rates.set_index("time")
print(df_rates)
print(datetime.now)
when print the exit is like below:
0 2024年05月30日 21:45:00 1.08385 1.08390 ... 339 2
1 2024年05月30日 22:00:00 1.08368 1.08368 ... 322 1
2 2024年05月30日 22:15:00 1.08354 1.08364 ... 362 1
3 2024年05月30日 22:30:00 1.08352 1.08354 ... 357 2
4 2024年05月30日 22:45:00 1.08296 1.08316 ... 528 2
.. ... ... ... ... ... ... ...
495 2024年06月07日 03:00:00 1.08917 1.08917 ... 245 2
496 2024年06月07日 03:15:00 1.08888 1.08908 ... 230 2
497 2024年06月07日 03:30:00 1.08878 1.08889 ... 167 2
498 2024年06月07日 03:45:00 1.08885 1.08925 ... 281 2
499 ***2024年06月07日 04:00:00*** 1.08895 1.08908 ... 300 2
[500 rows x 8 columns]
***2024年06月07日 07:44:35.858691***
Please help me.
lang-py
ratescontains the data you expect?