import MetaTrader5 as mt5
import pandas as pd
pd.set_option('display.max_columns', 500) # 표시될 칼럼 수
pd.set_option('display.width', 1500) # 표시될 최대 표 너비
# MetaTrader 5 패키지에 데이터 표시
print("MetaTrader5 패키지 작성자: ",mt5.__author__)
print("MetaTrader5 패키지 버전: ",mt5.__version__)
print()
# MetaTrader 5 터미널과의 연결 설정
if not mt5.initialize():
print("initialize() 실패, 오류 코드 =",mt5.last_error())
quit()
# GBPUSD에서 활성 주문의 데이터 표시
orders=mt5.orders_get(symbol="GBPUSD")
if orders is None:
print("GBPUSD에 새 주문 없음, 에러 코드={}".format(mt5.last_error()))
else:
print("GBPUSD에 대한 총 주문:",len(orders))
# 모든 활성 주문 표시
for order in orders:
print(order)
print()
# 이름에 "*GBP*"가 포함된 심볼에 대한 주문 목록을 가져옵니다
gbp_orders=mt5.orders_get(group="*GBP*")
if gbp_orders is None:
print("group=\"*GBP*\"인 주문 없음, 오류 코드={}".format(mt5.last_error()))
else:
print("orders_get(group=\"*GBP*\")={}".format(len(gbp_orders)))
# pandas를 이용해 이 주문들을 표로 표시.DataFrame
df=pd.DataFrame(list(gbp_orders),columns=gbp_orders[0]._asdict().keys())
df.drop(['time_done', 'time_done_msc', 'position_id', 'position_by_id', 'reason', 'volume_initial', 'price_stoplimit'], axis=1, inplace=True)
df['time_setup'] = pd.to_datetime(df['time_setup'], unit='s')
print(df)
# MetaTrader 5 터미널 연결 종료
mt5.shutdown()
결과:
MetaTrader5 패키지 작성자: MetaQuotes Software Corp.
MetaTrader5 패키지 버전: 5.0.29
Total orders on GBPUSD: 2
TradeOrder(ticket=554733548, time_setup=1585153667, time_setup_msc=1585153667718, time_done=0, time_done_msc=0, time_expiration=0, type=3, type_time=0, ...
TradeOrder(ticket=554733621, time_setup=1585153671, time_setup_msc=1585153671419, time_done=0, time_done_msc=0, time_expiration=0, type=2, type_time=0, ...
orders_get(group="*GBP*")=4
ticket time_setup time_setup_msc time_expiration type type_time type_filling state magic volume_current price_open sl tp price_current symbol comment external_id
0 554733548 2020-03-25 16:27:47 1585153667718 0 3 0 2 1 0 0.2 1.25379 0.0 0.0 1.16803 GBPUSD
1 554733621 2020-03-25 16:27:51 1585153671419 0 2 0 2 1 0 0.2 1.14370 0.0 0.0 1.16815 GBPUSD
2 554746664 2020-03-25 16:38:14 1585154294401 0 3 0 2 1 0 0.2 0.93851 0.0 0.0 0.92428 EURGBP
3 554746710 2020-03-25 16:38:17 1585154297022 0 2 0 2 1 0 0.2 0.90527 0.0 0.0 0.92449 EURGBP
|