MetaTrader 5 Python 사용자 그룹 - Metatrader에서 Python을 사용하는 방법 - 페이지 54

 

5.0.27로 업데이트

  pip install --upgrade MetaTrader5

스크립트 업로드

import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print( "MetaTrader5 package author: " ,mt5.__author__)
print( "MetaTrader5 package version: " ,mt5.__version__)

# установим подключение к терминалу MetaTrader 5
if 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()

결과

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.

 
Vladimir Perervenko :

타이머에 대해 자세히 설명해 주시겠습니까?

혼자 공부한게 아니라 그냥 검색해봐

 
Almaz :

5.0.27에서 이미 모든 구조 시퀀스(C API의 명명된 튜플과 유사)에는 _asdict() 메서드가 추가되었습니다.

mt5. symbol_info() ._asdict() -big thnx가 필요한 것입니다.

history_deals_get은 구조 순서에 속하지 않는 것 같습니다... 흐흐.

    deal = mt5.history_deals_get(position=order.position_id)._asdict()
AttributeError: 'tuple' object has no attribute '_asdict'

속성 이름을 올바른 순서로 반환하는 구조가 부족할 뿐입니다. history_deals_get _asdict() 가 구현되지 않았거나 개념과 모순되는 경우 최소한 collections 의 _fields 와 유사 합니다. namedtuple (python) 을 사용하면 속성의 올바른 순서를 가져올 수 있지만 주기에서 손으로가 아니라 인간적으로 가져올 수 있습니다. 지금까지는 다음과 같습니다.

       orders_deal = mt5.history_deals_get(from_date, to_date)
        orders_deal_frame = pd.DataFrame(orders_deal)
        print(orders_deal_frame.head())

그리고 출력에서:

           0            1            2                3    4    5    6    ...   11    12        13    14        15          16    17
0    519632807            0    1583873757    1583873757976    2    0    0   ...   0.0    0.0    1000.0    0.0
1    519653875    541985093    1583875090    1583875090615    1    0    0   ...   0.0    0.0      0.0    0.0   EURUSD   541984991
2    519654046    541985264    1583875102    1583875102086    0    0    0   ...   0.0    0.0      0.0    0.0   USDCHF   541984999
3    519654270    541985482    1583875116    1583875116676    0    0    0   ...   0.0    0.0      0.0    0.0   USDJPY   541985006
4    519654761    541985971    1583875151    1583875151725    1    0    0   ...   0.0    0.0      0.0    0.0   EURUSD   541985807

[ 5 rows x 18 columns]

음, 또는 사이클이 있는 국수.

 
Rashid Umarov :

5.0.27로 업데이트

스크립트 업로드

결과

센크스!

이 부분에서 정말 더 편리해졌습니다.

 
Дмитрий Прокопьев :

mt5.symbol_info()._asdict() -big thnx가 필요한 것입니다.

history_deals_get은 구조 순서에 속하지 않는 것 같습니다... 흐흐.

속성 이름을 올바른 순서로 반환하는 구조가 부족할 뿐입니다. history_deals_get _asdict() 가 구현되지 않았거나 개념과 모순되는 경우 최소한 collections 의 _fields 와 유사 합니다. namedtuple (python) 을 사용하면 속성의 올바른 순서를 가져올 수 있지만 주기에서 손으로가 아니라 인간적으로 가져올 수 있습니다. 지금까지는 다음과 같습니다.

그리고 출력에서:

음, 또는 사이클이 있는 국수.

history_deals_get 은 항상 일반 Python 튜플을 반환하며 내부에는 TradeDeals라는 이름의 컬렉션이 있습니다. 작동하려면 일부 색인에 액세스해야 합니다.

r = mt5.history_deals_get(position= 544536443 )
print(r[ 0 ]._asdict())
 
Дмитрий Прокопьев :

mt5.symbol_info()._asdict() -big thnx가 필요한 것입니다.

history_deals_get 구조 순서에 속하지 않는 것 같습니다 ... ㅎ.


다음과 같이 시도하십시오.

import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print( "MetaTrader5 package author: " ,mt5.__author__)
print( "MetaTrader5 package version: " ,mt5.__version__)

# установим подключение к терминалу MetaTrader 5
if not mt5.initialize():
    print( "initialize() failed" )
    quit()

# проверим наличие открытых позиций
positions=mt5.positions_total()
if (positions> 0 ):
    print( "Total positions=" ,positions)
     # выведем все открытые позиции
    positions=mt5.positions_get()
    count= 0
     for 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 :
             break
else :
    print( "Positions not found" )

# завершим подключение к терминалу MetaTrader 5
mt5.shutdown()

결과

MetaTrader5 package author:  MetaQuotes Software Corp.
MetaTrader5 package version:  5.0.27
Total positions= 80
1 : TradePosition(ticket=543426097, time=1584009003, time_msc=1584009003243, time_update=1584009003, time_update_msc=1584009003243, type=1, magic=0, identifier=543426097, reason=3, volume=0.01, price_open=1.12686, sl=1.14372, tp=1.10328, price_current=1.10665, swap=-0.01, profit=20.21, symbol='EURUSD', comment='', external_id='')
    ticket = 543426097
    time = 1584009003
    time_msc = 1584009003243
    time_update = 1584009003
    time_update_msc = 1584009003243
    type = 1
    magic = 0
    identifier = 543426097
    reason = 3
    volume = 0.01
    price_open = 1.12686
    sl = 1.14372
    tp = 1.10328
    price_current = 1.10665
    swap = -0.01
    profit = 20.21
    symbol = EURUSD
    comment = 
    external_id = 
2 : TradePosition(ticket=543438758, time=1584009602, time_msc=1584009602982, time_update=1584009602, time_update_msc=1584009602982, type=1, magic=0, identifier=543438758, reason=3, volume=0.01, price_open=1.1261700000000001, sl=1.14566, tp=1.09924, price_current=1.10665, swap=-0.01, profit=19.52, symbol='EURUSD', comment='', external_id='')
    ticket = 543438758
    time = 1584009602
    time_msc = 1584009602982
    time_update = 1584009602
    time_update_msc = 1584009602982
    type = 1
    magic = 0
    identifier = 543438758
    reason = 3
    volume = 0.01
    price_open = 1.1261700000000001
    sl = 1.14566
    tp = 1.09924
    price_current = 1.10665
    swap = -0.01
    profit = 19.52
    symbol = EURUSD
    comment = 
    external_id = 
3 : TradePosition(ticket=543438858, time=1584009610, time_msc=1584009610242, time_update=1584009610, time_update_msc=1584009610242, type=1, magic=0, identifier=543438858, reason=3, volume=0.02, price_open=1.12622, sl=1.14531, tp=1.09973, price_current=1.10665, swap=-0.02, profit=39.14, symbol='EURUSD', comment='', external_id='')
    ticket = 543438858
    time = 1584009610
    time_msc = 1584009610242
    time_update = 1584009610
    time_update_msc = 1584009610242
    type = 1
    magic = 0
    identifier = 543438858
    reason = 3
    volume = 0.02
    price_open = 1.12622
    sl = 1.14531
    tp = 1.09973
    price_current = 1.10665
    swap = -0.02
    profit = 39.14
    symbol = EURUSD
    comment = 
    external_id = 
4 : TradePosition(ticket=543521116, time=1584014410, time_msc=1584014410921, time_update=1584014410, time_update_msc=1584014410921, type=1, magic=0, identifier=543521116, reason=3, volume=0.02, price_open=1.1245, sl=1.14334, tp=1.09808, price_current=1.10665, swap=-0.02, profit=35.7, symbol='EURUSD', comment='', external_id='')
    ticket = 543521116
    time = 1584014410
    time_msc = 1584014410921
    time_update = 1584014410
    time_update_msc = 1584014410921
    type = 1
    magic = 0
    identifier = 543521116
    reason = 3
    volume = 0.02
    price_open = 1.1245
    sl = 1.14334
    tp = 1.09808
    price_current = 1.10665
    swap = -0.02
    profit = 35.7
    symbol = EURUSD
    comment = 
    external_id = 
5 : TradePosition(ticket=543686473, time=1584024008, time_msc=1584024008400, time_update=1584024008, time_update_msc=1584024008400, type=1, magic=0, identifier=543686473, reason=3, volume=0.01, price_open=1.12238, sl=1.13967, tp=1.09793, price_current=1.10665, swap=-0.01, profit=15.73, symbol='EURUSD', comment='', external_id='')
    ticket = 543686473
    time = 1584024008
    time_msc = 1584024008400
    time_update = 1584024008
    time_update_msc = 1584024008400
    type = 1
    magic = 0
    identifier = 543686473
    reason = 3
    volume = 0.01
    price_open = 1.12238
    sl = 1.13967
    tp = 1.09793
    price_current = 1.10665
    swap = -0.01
    profit = 15.73
    symbol = EURUSD
    comment = 
    external_id = 
 
Almaz :

history_deals_get은 항상 일반 Python 튜플을 반환하며 내부에는 TradeDeals라는 이름의 컬렉션이 있습니다. 작동하려면 다음 색인을 참조해야 합니다.

네, 감사합니다. 이미 비유로 찾았습니다. 센크스.

그리고 향후 릴리스에서 history_deals_get (및 유사체)으로 명명된 튜플을 선택하는 것이 가능할 뿐만 아니라 list[_asdict()]가 단순히

환상적이다. ;) 감사해요.

 
Rashid Umarov :

다음과 같이 시도하십시오.

결과

고맙습니다! 모든 것이 잘됩니다.

예, 그리고 둘 중 하나의 완료에 대한 :) 소원에 응답해 주셔서 감사합니다.

 
Rashid Umarov :

5.0.27로 업데이트

스크립트 업로드

결과

안녕하세요.

Rashid, 사이트 어딘가에 MetaTrader5에 대한 제품 업데이트 발표 같은 것이 있습니까?

언제 어떤 변경 사항이 발생했는지 추적할 수 있습니다.

그리고 리팩토링을 계획하는 것은 약간 어렵습니다.


 
Дмитрий Прокопьев :

안녕하세요.

Rashid, 사이트 어딘가에 MetaTrader5에 대한 제품 업데이트 발표 같은 것이 있습니까?

언제 어떤 변경 사항이 발생했는지 추적할 수 있습니다.

그리고 리팩토링을 계획하는 것은 약간 어렵습니다.


피피를 보고 있습니다. 개발자들은 우리의 의견이 계속/개선되기를 기다리고 있습니다. 그러나 지금까지는 이 영역에서 사용자 활동이 없습니다.

별도의 스레드에서 복잡한 거래 시스템(터미널(MT4/MT5) <-> TS(다른 언어) <_> 데이터베이스에 대한 일반적인 인프라 문제에 대해 논의할 필요가 있다고 생각합니다. 다양한 구성, 문제, 어려움, 제가 준비한 방법을 포스팅하겠습니다.

행운을 빕니다