import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
print("initialize() failed, error code =",mt5.last_error())
quit()
# get account currency
account_currency=mt5.account_info().currency
print("Account сurrency:",account_currency)
# arrange the symbol list
symbols=("EURUSD","GBPUSD","USDJPY", "USDCHF","EURJPY","GBPJPY")
print("Symbols to check margin:", symbols)
action=mt5.ORDER_TYPE_BUY
lot=0.1
for symbol in symbols:
symbol_info=mt5.symbol_info(symbol)
if symbol_info is None:
print(symbol,"not found, skipped")
continue
if not symbol_info.visible:
print(symbol, "is not visible, trying to switch on")
if not mt5.symbol_select(symbol,True):
print("symbol_select({}}) failed, skipped",symbol)
continue
ask=mt5.symbol_info_tick(symbol).ask
margin=mt5.order_calc_margin(action,symbol,lot,ask)
if margin != None:
print(" {} buy {} lot margin: {} {}".format(symbol,lot,margin,account_currency));
else:
print("order_calc_margin failed: , error code =", mt5.last_error())
# 断开与MetaTrader 5程序端的连接
mt5.shutdown()
Result:
MetaTrader5 package author: MetaQuotes Software Corp.
MetaTrader5 package version: 5.0.29
Account сurrency: USD
Symbols to check margin: ('EURUSD', 'GBPUSD', 'USDJPY', 'USDCHF', 'EURJPY', 'GBPJPY')
EURUSD buy 0.1 lot margin: 109.91 USD
GBPUSD buy 0.1 lot margin: 122.73 USD
USDJPY buy 0.1 lot margin: 100.0 USD
USDCHF buy 0.1 lot margin: 100.0 USD
EURJPY buy 0.1 lot margin: 109.91 USD
GBPJPY buy 0.1 lot margin: 122.73 USD
|