0

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.

asked Jun 6, 2024 at 16:58
3
  • maybe you have wrong time. Maybe you use local time and it may need UTC Commented Jun 7, 2024 at 2:10
  • thanks for your answer. but i change my local time to utc.the problem is still not resolved Commented Jun 7, 2024 at 5:19
  • Have you confirmed that the contents of rates contains the data you expect? Commented Jun 7, 2024 at 14:01

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.