Not updating list of open orders on MT5 API Python
Not updating list of open orders on MT5 API Python
Loading saved threads...
Emanuele Ricco · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Emanuele Ricco
Original post: https://stackoverflow.com/questions/78477417
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I need to see the list of my open orders updated each minute.
Launching this code:
to_date = datetime.now(pytz.timezone('Europe/Rome'))
from_date = to_date - timedelta(days = 1)
deals = mt5.history_orders_get(from_date, to_date, group=f"*{ticker}*")
df=pd.DataFrame(list(deals),columns=deals[0]._asdict().keys())
df['time_setup'] = pd.to_datetime(df['time_setup'], unit='s')
df['time_done'] = pd.to_datetime(df['time_done'], unit='s')
I see that the dataframe resulting considers only those positions closed on the previous day, and not also those on the current day.
dataframe not updated
Could you help me?
I tried changing the start date and to date, also modifying the timezones (utc) but the list does not update and remains qual to the one of the previous day
Quote
Report
Ebrahim Pasbani · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Ebrahim Pasbani
Original post: https://stackoverflow.com/a/78614667
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
The API
history_orders_get
is for getting orders that are in history. That means the orders that are closed.
You need to use
orders_get
to get pending orders.
Quote
Report
Pablo Brunetti · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: Pablo Brunetti
Original post: https://stackoverflow.com/a/78627319
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
You need to use the
orders_get
method. In the example below, all open orders on the XAUUSD asset are searched:
orders=mt5.orders_get(symbol="XAUUSD")
while(len(orders) != 0):
orders=mt5.orders_get(symbol="XAUUSD")
if orders is None:
print("No orders on XAUUSD, error code={}".format(mt5.last_error()))
else:
print("Total orders on XAUUSD:",len(orders))
# display all active orders
for order in orders:
print(order)
Quote
Report
Post Reply
Checking account access…