login

지정된 매개 변수를 사용하여 거래 계정에 연결합니다.

login(
   login,                    // 계정 번호
   password="PASSWORD",      // password
   server="SERVER",          // 터미널에 지정된 서버 이름
   timeout=TIMEOUT           // timeout
   )

Parameters

login

[in]  거래 계정 번호. 이름이 지정되지 않은 필수 매개 변수.

password

[in]  거래 계정 비밀번호 선택적 지명 파라미터. 비밀번호가 설정되어 있지 않으면 터미널 데이터베이스에 저장된 비밀번호가 자동으로 적용됩니다.

server

[in]  거래 서버명 선택적 지명 파라미터. 서버가 설정되지 않은 경우 마지막으로 사용한 서버가 자동으로 적용됩니다.

timeout=TIMEOUT

[in]  연결 시간 제한(밀리초). 선택적 지명 파라미터. 지정하지 않으면 값이 60000(60초)로 적용됩니다. 지정된 시간 내에 연결이 설정되지 않으면 통화가 강제로 종료되고 예외가 생성됩니다.

반환 값

거래 계정에 성공적으로 연결된 경우 True이며, 그렇지 않은 경우 False입니다.

예:

import MetaTrader5 as mt5
# MetaTrader 5 패키지에 데이터 표시
print("MetaTrader5 패키지 작성자: ",mt5.__author__)
print("MetaTrader5 패키지 버전: ",mt5.__version__)
 
# MetaTrader 5 터미널과의 연결 설정
if not mt5.initialize():
    print("initialize() 실패, 오류 코드 =",mt5.last_error())
    quit()
 
# MetaTrader 5 버전에서 데이터 표시
print(mt5.version())
# 비밀번호와 서버를 지정하지 않고 거래 계정에 연결합니다.
account=17221085
authorized=mt5.login(account)  # 터미널 데이터베이스 비밀번호가 연결 데이터를 기억하도록 설정된 경우 적용됩니다.
if authorized:
    print("다음 계정에 연결 #{}".format(account))
else:
    print("계정 연결 실패 #{}, 오류 코드: {}".format(account, mt5.last_error()))
 
# 이제 비밀번호를 지정하는 다른 거래 계정에 연결합니다.
account=25115284
authorized=mt5.login(accountpassword="gqrtz0lbdm")
if authorized:
    # 거래 계정 데이터를 "있는 그대로" 표시
    print(mt5.account_info())
    # 거래 계정 데이터를 목록 형식으로 표시
    print("Show account_info()._asdict():")
    account_info_dict = mt5.account_info()._asdict()
    for prop in account_info_dict:
        print("  {}={}".format(prop, account_info_dict[prop]))
else:
    print("계정 연결 실패 #{}, 오류 코드: {}".format(account, mt5.last_error()))
 
# MetaTrader 5 터미널 연결 종료
mt5.shutdown()
 
 
Result:
MetaTrader5 패키지 작성자:  MetaQuotes Software Corp.
MetaTrader5 패키지 버전:  5.0.29
[500, 2367, '23 Mar 2020']
 
계정 #17221085에 연결
 
계정 #25115284에 연결
AccountInfo(login=25115284, trade_mode=0, leverage=100, limit_orders=200, margin_so_mode=0, ...
계정 속성:
   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=99588.33
   credit=0.0
   profit=-45.23
   equity=99543.1
   margin=54.37
   margin_free=99488.73
   margin_level=183084.6054809638
   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=James Smith
   server=MetaQuotes-Demo
   currency=USD
   company=MetaQuotes Software Corp.

더 보기

initialize, shutdown