order_calc_margin

返回预付款(用账户货币表示)来执行指定的交易操作。

order_calc_margin(

   action,      // 订单类型 (ORDER_TYPE_BUY or ORDER_TYPE_SELL)

   symbol,      // 交易品种名称

   volume,      // 交易量

   price        // 开盘价

   )

参数

action

[in]  从ORDER_TYPE枚举中获取值的订单类型。所需的未命名参数。

symbol

[in]  交易品种名称。所需的未命名参数。

volume

[in]  交易操作的交易量。所需的未命名参数。

price

[in]  开盘价。所需的未命名参数。

返回值

如果成功返回真实值,否则返回None。可以使用last_error()获取错误信息。

注意

该功能允许评估当前账户和当前市场环境中指定订单类型所需的预付款,而无需考虑当前挂单和未结持仓。该函数类似于OrderCalcMargin

ORDER_TYPE

ID 描述
ORDER_TYPE_BUY 市价买单
ORDER_TYPE_SELL 市价卖单
ORDER_TYPE_BUY_LIMIT Buy Limit挂单
ORDER_TYPE_SELL_LIMIT Sell Limit挂单
ORDER_TYPE_BUY_STOP Buy Stop挂单
ORDER_TYPE_SELL_STOP Sell Stop挂单
ORDER_TYPE_BUY_STOP_LIMIT 在达到订单价格时,以StopLimit价格下单Buy Limit挂单
ORDER_TYPE_SELL_STOP_LIMIT 在达到订单价格时,以StopLimit价格下单Sell Limit挂单
ORDER_TYPE_CLOSE_BY 用于反向平仓的订单

例如:

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

另见

order_calc_profitorder_check