How to fetch whether a symbol currently accepts orders via MT5 Python API?

 

As in the title, I want to have realtime information via MT5 in Python whether a given symbol currently allows trading or not. I want to have the same real-time information as what I have when opening MetaTrader and attempting to buy/sell a given instrument. The UI will not allow me do that for Forex pairs in weekends, for instance. But I don't see how to get that same information programmatically.

First I attempted this:

import MetaTrader5 as mt5

def check_symbol_details(symbol):

    info = mt5.symbol_info(symbol)
    if not info:
        return f"Symbol {symbol} not found"

    return {
        "trade_mode": info.trade_mode,  # 0 = SYMBOL_TRADE_MODE_DISABLED, 1 = SYMBOL_TRADE_MODE_LONGONLY, 2 = SYMBOL_TRADE_MODE_SHORTONLY, 3 = SYMBOL_TRADE_MODE_CLOSEONLY, 4 = SYMBOL_TRADE_MODE_FULL
        "trade_exemode": info.trade_exemode,  # 0 = SYMBOL_TRADE_EXECUTION_REQUEST, 1 = SYMBOL_TRADE_EXECUTION_INSTANT, 2 = SYMBOL_TRADE_EXECUTION_MARKET, 3 = SYMBOL_TRADE_EXECUTION_EXCHANGE
        "filling_mode": info.filling_mode,
        "order_mode": info.order_mode,
        "bid": info.bid,
        "ask": info.ask,
        "spread": info.spread,
    }

mt5.initialize()

for symbol in ["BITCOIN", "EURUSD", 'USDTRY']:
    print(f"Symbol details for {symbol}:{check_symbol_details(symbol)}")
    print("-"*50)

which prints:

Symbol details for BITCOIN:

{'trade_mode': 4, 'trade_exemode': 2, 'filling_mode': 2, 'order_mode': 127, 'bid': 85600.67, 'ask': 85686.43, 'spread': 8576}

--------------------------------------------------

Symbol details for EURUSD:

{'trade_mode': 4, 'trade_exemode': 2, 'filling_mode': 2, 'order_mode': 127, 'bid': 1.08317, 'ask': 1.08317, 'spread': 0}

--------------------------------------------------

Symbol details for USDTRY:

{'trade_mode': 3, 'trade_exemode': 2, 'filling_mode': 2, 'order_mode': 127, 'bid': 36.40255, 'ask': 36.52256, 'spread': 12001}

At the moment of writing this, it is weekend, hence I know for certain that BITCOIN is the only one tradeable out of the three. But based on the above output alone, I see that trade_mode is 4 for both BITCOIN and EURUSD while USDTRY only allows order close. I'm not ahead either by checking exemode and filling mode, nor the spread value. So I tried another approach:

def check_order(symbol):
    request = {
        "action": mt5.TRADE_ACTION_DEAL,
        "symbol": symbol,
        "volume": 0.1,
        "type": mt5.ORDER_TYPE_BUY,
        "price": mt5.symbol_info_tick(symbol).ask,
        "deviation": 10,
        "magic": 0,
        "comment": "test order",
        "type_time": mt5.ORDER_TIME_GTC,
        "type_filling": mt5.ORDER_FILLING_IOC,
    }

    result = mt5.order_check(request)
    return result._asdict()

which, when feeding the same three symbol strings, prints the following:

Order check for BITCOIN:

 {'retcode': 0, 'balance': 9903.9, 'equity': 9903.9, 'profit': 0.0, 'margin': 17.1, 'margin_free': 9886.8, 'margin_level': 57917.543859649115, 'comment': 'Done', 'request': 

TradeRequest(action=1, magic=0, order=0, symbol='BITCOIN', volume=0.1, price=85516.84, stoplimit=0.0, sl=0.0, tp=0.0, deviation=10, type=0, type_filling=1, type_time=0, expiration=0, comment='test order', position=0, position_by=0)}

--------------------------------------------------

Order check for EURUSD:

 {'retcode': 0, 'balance': 9903.9, 'equity': 9903.9, 'profit': 0.0, 'margin': 361.06, 'margin_free': 9542.84, 'margin_level': 2743.006702487121, 'comment': 'Done', 'request': TradeRequest(action=1, magic=0, order=0, symbol='EURUSD', volume=0.1, price=1.08317, stoplimit=0.0, sl=0.0, tp=0.0, deviation=10, type=0, type_filling=1, type_time=0, expiration=0, comment='test order', position=0, position_by=0)}

--------------------------------------------------

Order check for USDTRY:

 {'retcode': 10044, 'balance': 0.0, 'equity': 0.0, 'profit': 0.0, 'margin': 0.0, 'margin_free': 0.0, 'margin_level': 0.0, 'comment': 'Only position closing is allowed', 'request': TradeRequest(action=1, magic=0, order=0, symbol='USDTRY', volume=0.1, price=36.52256, stoplimit=0.0, sl=0.0, tp=0.0, deviation=10, type=0, type_filling=1, type_time=0, expiration=0, comment='test order', position=0, position_by=0)}

Again, I see no indication from either 3 outputs that BITCOIN is open and actively tradeable while the other two are not. I find the `'comment': 'Done'` in case of EURUSD particularly confusing as when I attempt to send a real order for the same pair, it'll fail as the market is closed.

How can I get real time information whether a given instrument is open and tradeable at a given time?

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each...
 
Is this not possible?