Closed brenoperucchi closed 3 years ago
Will check this, is it MT4 or MT5 ? For MT4 you can only retrieve the closed trades available in the MT4 terminal. As you know you can set the history of closed orders starting from day and so on. If in the terminal history you see only 12 closed orders, the python api can give back only this 12 closed orders, independent of your start date in the call,
BR
Will check this, is it MT4 or MT5 ? For MT4 you can only retrieve the closed trades available in the MT4 terminal. As you know you can set the history of closed orders starting from day and so on. If in the terminal history you see only 12 closed orders, the python api can give back only this 12 closed orders, independent of your start date in the call,
BR
Pytrader_MT5_EA_V2.02.ex5
I did i try to, got the next return.
Used the following code
timezone = pytz.timezone("Etc/UTC") AllClosedPositions = MT.Get_all_closed_positions( date_from=datetime(2021, 1, 1, tzinfo=timezone), date_to=datetime.now())
Anyway i will do some more testing.
BR
Hi,
The date comparision with now has an item. From to is it including this day or not. I will adapt this and make an update. Used the following code: timezone = pytz.timezone("Etc/UTC") AllClosedPositions = MT.Get_all_closed_positions( date_from=datetime(2021, 1, 1, tzinfo=timezone), date_to=datetime(2021, 1, 20, tzinfo=timezone))
Got this result now:
BR
Hi,
If your broker has a difference in time with your local time, this can happen. I tested on ICM broker and had the same problem.
timezone = pytz.timezone("Etc/UTC") AllClosedPositions = MT.Get_all_closed_positions( date_from=datetime(2021, 1, 1, tzinfo=timezone), date_to=datetime.now() + timedelta(hours=1))
For this broker just added 1 hour to local time
BR
Hi Branly, I was thinking about server time too but your solution or mine doesn't solved the problem. Maybe the server is delaying the information about history? For testing, I will change my broker to the ICM.
To use your API I need to obtain closed positions to finish the operation on my system.
meta.Get_all_closed_positions(date_from=datetime(2020, 1, 19, 0, tzinfo=timezone),date_to=datetime.now())
I closed the trade operation in a new demo account on MetaTrader 5 and after that, I try to get all closed positions from the API and I receive nothing.
(Pdb) meta.Get_all_closed_positions(date_from=datetime(2021, 1, 1, tzinfo=timezone), date_to=datetime.now() + timedelta(hours=1))
Empty DataFrame
Columns: [position_ticket, instrument, order_ticket, position_type, magic_number, volume, open_price, open_time, close_price, close_time, comment, profit, swap, commission]
Index: []
(Pdb)
ps: I woke up this morning and yesterday's results changes from 14 records to 40 without changing anything in the code. ps: I'm using ActivTrades as a broker.
Regards, Breno
I'm using ActivTrades https://www.activtrades.com/
Hi,
This can be the case depending on time difference between broker server time, which are the open/close times and your local time. I did a test with 20 trades and closed them directly. I was missing them all in the call. I went out for a while and tried again and yes they were there. Then i tried again and all not there. Then i changed/added the extra hour, and all where there again.
Will see if i can try with your broker too.
BR
You was right!
My time zone is 3 ahead of UTC but the server was 5 hours from me. When trying your suggested I changed to 3 hours and not verify the date-time of server information.
(date_from=datetime(2021, 1, 1, tzinfo=timezone), date_to=datetime.now() + timedelta(hours=3))
Sorry for this issue! BR
But one record was left out
HI,
Yep i know why. Iteration one to short. I changed already, will upload new version later.
BR
Version 2.03 is available
BR
Has some limitations about the number of information you could request?
I only get 14 most recent pieces of information but have more than 30 records.
Suggest: