Not able to update SL, TP using pybit sdk

1k views Asked by At

I am trying to change the Stop_loss and take_profit for my open order. I am using this method to update my SL. When I run the code, I get this error:

2022-06-04:14:39:12,782 DEBUG    [connectionpool.py:465] https://api-testnet.bybit.com:443 "POST /private/linear/position/trading-stop HTTP/1.1" 200 209

Traceback (most recent call last):
  File "app.py", line 135, in <module>
    trailing_stop=0.5,
  
  File "/home/v1p3r/.local/lib/python3.6/site-packages/pybit/usdt_perpetual.py", line 477, in set_trading_stop
    auth=True
  
  File "/home/v1p3r/.local/lib/python3.6/site-packages/pybit/_http_manager.py", line 326, in _submit_request
    time=dt.utcnow().strftime("%H:%M:%S")

pybit.exceptions.InvalidRequestError: 
Position status is not normal (ErrCode: 130003) (ErrTime: 09:09:12).

Request → POST https://api-testnet.bybit.com/private/linear/position/trading-stop: 
{'api_key': 'cYWvW99NAb2ZSGZG1S', 
'recv_window': 5000, 
'side': 'Sell', 
'symbol': 'KAVAUSDT', 
'timestamp': 1654333752542, 
'trailing_stop': 0.5, 
'sign': '56a8a7555d76626838cf21c0176885d8f7565faaaf3ca6d0b733eca2661bc8a3'}.

Can someone help me fix this error?

This is my code:

     try:
        ret = session.set_trading_stop(
            symbol=symbol,
            side=side,
            stop_loss=new_sl,
            # sl_size=10000000
        )
        pprint(ret)
        res = ret['ret_code']
    except:
        log.error("Failed changing the stop_loss")

I get this error message when this method is executed. I keep getting the failed message.

1

There are 1 answers

0
Acuna On

You're trying to edit the position stop loss value in one way mode, in that case position_idx param with value 0 (for one way mode) is required.