import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# установим подключение к терминалу MetaTrader 5if not mt5.initialize():
print("initialize() failed")
mt5.shutdown()
# подключимся к торговому счету с указанием пароля и сервера
authorized=mt5.login(25115284, password="ваш_пароль",server="MetaQuotes-Demo")
if(authorized):
# выведем данные о торговом счете
#print(mt5.account_info())
account_info=mt5.account_info()._asdict()
print(account_info)
print("Вывод каждого свойства отдельно:")
for property in account_info:
print(" ",property,"=",account_info[property])else:
print("failed to connect to trade account 25115284 with password=gqz0lbdm")
mt5.shutdown()
history_deals_get doesn't seem to be in structure sequence ... heh.
deal = mt5.history_deals_get(position=order.position_id)._asdict()
AttributeError: 'tuple' object has no attribute '_asdict'
Just badly missing a construct that will give the attribute names, in the correct order. If forhistory_deals_get_asdict() is not realizable or contradicts the concept - at least an analogue of _fields fromcollections.namedtuple (python), then we can pull the correct order of attributes, not manually in loop, but manually. So far it works out something like:
history_deals_get doesn't seem to fall into structure sequence ... heh.
Just badly missing a construct that will give the attribute names, in the correct order. If forhistory_deals_get_asdict() is not realizable or contradicts the concept - at least an analogue of _fields fromcollections.namedtuple (python), then we can pull the correct order of attributes, not manually in loop, but manually. So far it works out something like:
and the output:
Or noodle code with loops.
history_deals_get always returns a normal Python tuple with a collection of named TradeDeal inside it. In order to make it work, you need to access some index:
r = mt5.history_deals_get(position=544536443)
print(r[0]._asdict())
mt5.symbol_info()._asdict() -big thnx, what we need.
history_deals_get doesn't seem to fall into structure sequence ... heh.
Try it this way:
import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# установим подключение к терминалу MetaTrader 5if not mt5.initialize():
print("initialize() failed")
quit()
# проверим наличие открытых позиций
positions=mt5.positions_total()
if(positions>0):
print("Total positions=",positions)
# выведем все открытые позиции
positions=mt5.positions_get()
count=0for position in positions:
count+=1
print(count,":",position)
position_info=position._asdict()
for property in position_info:
print(" ",property,"=",position_info[property])if count>=5:
breakelse:
print("Positions not found")
# завершим подключение к терминалу MetaTrader 5
mt5.shutdown()
history_deals_get always returns a normal Python tuple with a collection of named TradeDeal inside it. In order to make it work, we need to access some index:
Aha, thank you very much, I've already found this by analogy. Sens.
What if, in future releases, it will be possible not only to select named tuple with history_deals_get(and analogs), but also say list[_asdict()] will be just
Rashid, is there a Product Update Announcement somewhere on the website?
So that you can keep track of what changes have been made and when.
It is a little difficult to plan the refactoring.
I am watching Pypi. Developers are waiting for comments from us for continuation/improvement. But so far we don't see any user activity in this area.
I think, we need to discuss in a separate branch the general infrastructure issues for the complex trading systems (terminal (MT4/МТ5) <-> TS (on different IPs) <_> different databases. Different configurations, problems, difficulties, advantages.
Update to 5.0.27
Backup the script
Result
MetaTrader5 package author: MetaQuotes Software Corp. MetaTrader5 package version: 5.0.27 {'login': 25115284, 'trade_mode': 0, 'leverage': 100, 'limit_orders': 200, 'margin_so_mode': 0, 'trade_allowed': True, 'trade_expert': True, 'margin_mode': 2, 'currency_digits': 2, 'fifo_close': False, 'balance': 97639.46, 'credit': 0.0, 'profit': -178.77, 'equity': 97460.69, 'margin': 704.8, 'margin_free': 96755.89, 'margin_level': 13828.134222474464, 'margin_so_call': 50.0, 'margin_so_so': 30.0, 'margin_initial': 0.0, 'margin_maintenance': 0.0, 'assets': 0.0, 'liabilities': 0.0, 'commission_blocked': 0.0, 'name': 'MetaQuotes Dev Demo', 'server': 'MetaQuotes-Demo', 'currency': 'USD', 'company': 'MetaQuotes Software Corp.'} Вывод каждого свойства отдельно: login = 25115284 trade_mode = 0 leverage = 100 limit_orders = 200 margin_so_mode = 0 trade_allowed = True trade_expert = True margin_mode = 2 currency_digits = 2 fifo_close = False balance = 97639.46 credit = 0.0 profit = -178.77 equity = 97460.69 margin = 704.8 margin_free = 96755.89 margin_level = 13828.134222474464 margin_so_call = 50.0 margin_so_so = 30.0 margin_initial = 0.0 margin_maintenance = 0.0 assets = 0.0 liabilities = 0.0 commission_blocked = 0.0 name = MetaQuotes Dev Demo server = MetaQuotes-Demo currency = USD company = MetaQuotes Software Corp.Can you tell me more about the timer?
I haven't looked into it myself, just a search
5.0.27 already has, all structure sequence (analog of named tuple for C API) added _asdict() method
mt5.symbol_info()._asdict() -big thnx, what we need.
history_deals_get doesn't seem to be in structure sequence ... heh.
Just badly missing a construct that will give the attribute names, in the correct order. If forhistory_deals_get_asdict() is not realizable or contradicts the concept - at least an analogue of _fields fromcollections.namedtuple (python), then we can pull the correct order of attributes, not manually in loop, but manually. So far it works out something like:
and the output:
Well, or noodlecode with loops.
Update to 5.0.27
Backup the script
Results
Sens!
Really comfortable in this part.
mt5.symbol_info()._asdict() -big thnx, that's it.
history_deals_get doesn't seem to fall into structure sequence ... heh.
Just badly missing a construct that will give the attribute names, in the correct order. If forhistory_deals_get_asdict() is not realizable or contradicts the concept - at least an analogue of _fields fromcollections.namedtuple (python), then we can pull the correct order of attributes, not manually in loop, but manually. So far it works out something like:
and the output:
Or noodle code with loops.
history_deals_get always returns a normal Python tuple with a collection of named TradeDeal inside it. In order to make it work, you need to access some index:
mt5.symbol_info()._asdict() -big thnx, what we need.
history_deals_get doesn't seem to fall into structure sequence ... heh.
Try it this way:
Result
history_deals_get always returns a normal Python tuple with a collection of named TradeDeal inside it. In order to make it work, we need to access some index:
Aha, thank you very much, I've already found this by analogy. Sens.
What if, in future releases, it will be possible not only to select named tuple with history_deals_get(and analogs), but also say list[_asdict()] will be just
fantastic. ;) Thanks.
Try it this way:
Result
Thank you! It's working.
Oh, and thank you for responding to :) suggestions to improve the lib.
Update to 5.0.27
Backup the script
Results
Afternoon.
Rashid, is there some kind of Product Update Announcement somewhere on the MetaTrader5 website?
I would like to know when and what changes have been implemented.
It is a bit difficult to plan the refactoring.
Good afternoon.
Rashid, is there a Product Update Announcement somewhere on the website?
So that you can keep track of what changes have been made and when.
It is a little difficult to plan the refactoring.
I am watching Pypi. Developers are waiting for comments from us for continuation/improvement. But so far we don't see any user activity in this area.
I think, we need to discuss in a separate branch the general infrastructure issues for the complex trading systems (terminal (MT4/МТ5) <-> TS (on different IPs) <_> different databases. Different configurations, problems, difficulties, advantages.
Good luck