[Python] Constantly getting "TRADE_RETCODE_REQUOTE" error but can't see the problem w/my JSON would fail?

 

I'm getting a constant error with the MT5 Python implementation. My "order request" looks like this:


order_json = {

    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": 0.1,
    "type": mt5.ORDER_TYPE_BUY_LIMIT,
    "price": round(mt5.symbol_info_tick(symbol).bid - (point * 10), 5),
    "sl": round(mt5.symbol_info_tick(symbol).bid - (100 * point), 5),
    "tp": round(mt5.symbol_info_tick(symbol).bid + (100 * point), 5),
    "deviation": 20,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}


While I get back correct errors when the market is closed or I don't have enough margin, the only other error that comes back is: TRADE_RETCODE_REQUOTE. The only order I'm able to successfully submit is a market order. When I Google this error I don't get any satisfactory solutions. Can you tell me where my JSON is going wrong?

Any help appreciated!

 
aimzieslol:

I'm getting a constant error with the MT5 Python implementation. My "order request" looks like this:


order_json = {

    "action": mt5.TRADE_ACTION_DEAL,
    "symbol": symbol,
    "volume": 0.1,
    "type": mt5.ORDER_TYPE_BUY_LIMIT,
    "price": round(mt5.symbol_info_tick(symbol).bid - (point * 10), 5),
    "sl": round(mt5.symbol_info_tick(symbol).bid - (100 * point), 5),
    "tp": round(mt5.symbol_info_tick(symbol).bid + (100 * point), 5),
    "deviation": 20,
    "comment": "python script open",
    "type_time": mt5.ORDER_TIME_GTC,
    "type_filling": mt5.ORDER_FILLING_RETURN,
}


While I get back correct errors when the market is closed or I don't have enough margin, the only other error that comes back is: TRADE_RETCODE_REQUOTE. The only order I'm able to successfully submit is a market order. When I Google this error I don't get any satisfactory solutions. Can you tell me where my JSON is going wrong?

Any help appreciated!

Couple things... First, the action is wrong. You are trying to place a market order (TRADE_ACTION_DEAL) with pending order parameters. Use TRADE_ACTION_PENDING instead. Next, you're wasting valuable resources by constantly calling symbol_info_tick. Assign it to a variable after the first call. Finally since all of the keys meet the python variable naming conventions you can simplify your code by passing them as kwargs to the dict constructor instead. 

buy_limit = dict( action=mt5.TRADE_ACTION_PENDING, type=mt5.ORDER_TYPE_BUY_LIMIT, symbol=symbol, volume=0.1, price=round((bid := mt5.symbol_info_tick(symbol).bid) - (point * 10), 5), sl=round(bid - (100 * point), 5), tp=round(bid + (100 * point), 5), deviation=20, comment="python script open", type_time=mt5.ORDER_TIME_GTC, type_filling=mt5.ORDER_FILLING_RETURN, )

 
nicholi shen:

Couple things... First, the action is wrong. You are trying to place a market order (TRADE_ACTION_DEAL) with pending order parameters. Use TRADE_ACTION_PENDING instead. Next, you're wasting valuable resources by constantly calling symbol_info_tick. Assign it to a variable after the first call. Finally since all of the keys meet the python variable naming conventions you can simplify your code by passing them as kwargs to the dict constructor instead. 

BINGO! Thank you sooooooo much!

Reason: