Ejemplo n.º 1
0
from datetime import datetime
import MetaTrader5 as mt5

# 显示有关MetaTrader 5程序包的数据
print("MetaTrader5 package author: ", mt5.__author__)
print("MetaTrader5 package version: ", mt5.__version__)

# 建立与MetaTrader 5程序端的连接
if not mt5.initialize():
    print("initialize() failed, error code =", mt5.last_error())
    quit()

# 获取历史中的交易数量
from_date = datetime(2020, 1, 1)
to_date = datetime.now()
deals = mt5.history_deals_total(from_date, to_date)
if deals > 0:
    print("Total deals=", deals)
# 其他:
# print("Deals not found in history")

# 断开与MetaTrader 5程序端的连接
mt5.shutdown()
Ejemplo n.º 2
0
#____________retriving no of historical trades___________#
fromDate = dt.datetime(2019, 8, 1)
toDate = dt.datetime.now()
historyOrder = mt5.history_orders_total(
    fromDate, toDate)  #retrives number of trades in time range
print("Total history orders:", historyOrder)

#_________retriving historical order information__________#
orerData = mt5.history_orders_get(fromDate, toDate)  #by date range
for i in orerData:
    print(i)

orderData2 = mt5.history_orders_get(ticket=38110138)  #by tickets
for data in orderData2:
    print('\n', data)

#______total no of historical deals(executed orders)_______#
deals = mt5.history_deals_total(fromDate, toDate)
print("\nTotal deals:", deals)

#__________get information of historical deals___________#
deals = mt5.history_deals_get(fromDate, toDate)  #by date range
for i in deals:
    print(i)

deal = mt5.history_deals_get(ticket=17371248)  #by tickets
print(deal[0], '\n')
for i in deal[0]:
    print(i)

mt5.shutdown()