bybit-market-maker icon indicating copy to clipboard operation
bybit-market-maker copied to clipboard

InvalidRequestError: Errcode 34040

Open projenix opened this issue 3 years ago • 7 comments

I first get a fill, then moments later I get this error:

2021-07-03 01:28:11.796893 - INFO - Awaiting position. Traceback (most recent call last): File "mm.py", line 191, in s.set_trading_stop( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pybit/init.py", line 909, in set_trading_stop return self._submit_request( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pybit/init.py", line 1497, in _submit_request raise InvalidRequestError( pybit.exceptions.InvalidRequestError: Not modified (ErrCode: 34040) (ErrTime: 01:28:14). Request → POST https://api.bybit.com/v2/private/position/trading-stop: {'api_key': '', 'recv_window': 5000, 'stop_loss': 2194, 'symbol': 'ETHUSD', 'timestamp': 1625275694488, 'sign': ''}.

projenix avatar Jul 03 '21 01:07 projenix

It used to work good with me but for now it has same error

Shimoli avatar Jul 14 '21 06:07 Shimoli

I first get a fill, then moments later I get this error:

2021-07-03 01:28:11.796893 - INFO - Awaiting position. Traceback (most recent call last): File "mm.py", line 191, in s.set_trading_stop( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pybit/init.py", line 909, in set_trading_stop return self._submit_request( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pybit/init.py", line 1497, in _submit_request raise InvalidRequestError( pybit.exceptions.InvalidRequestError: Not modified (ErrCode: 34040) (ErrTime: 01:28:14). Request → POST https://api.bybit.com/v2/private/position/trading-stop: {'api_key': '', 'recv_window': 5000, 'stop_loss': 2194, 'symbol': 'ETHUSD', 'timestamp': 1625275694488, 'sign': ''}.

This suggests that you've already placed a stop and are trying to modify your trading stop, but the stop loss hasn't changed. For example, if you place a limit order with a stop of 2194, then after filling try to modify the trading stop to the same price (2194), you will get this error. Is this your situation?

verata-veritatis avatar Jul 14 '21 16:07 verata-veritatis

This suggests that you've already placed a stop and are trying to modify your trading stop, but the stop loss hasn't changed. For example, if you place a limit order with a stop of 2194, then after filling try to modify the trading stop to the same price (2194), you will get this error. Is this your situation?

No I had actually not placed any stops at all.

projenix avatar Aug 05 '21 20:08 projenix

Oh No!!! It used to work good with me but for now it has same error now! Besides, it is ignored by the bybit support. Dose anyone know a solution ErrCode: 34040?

gone-bad-steel-pipe avatar Feb 14 '22 13:02 gone-bad-steel-pipe

Hi guys here's a solution.

Let's say you opened a 'Buy' position (the position must be already open), here's a simple function to add then a SL.

from pybit import HTTP # version: pybit==1.3.6 USE THIS VERSION

def STOP_LOSS_for_LONG_POSITION():
    session = HTTP('https://api-testnet.bybit.com', api_key=KEY, api_secret=SECRET)
    session.set_trading_stop(
        symbol="SOLUSDT",
        side="Buy", # I opened a position at 38.70
        stop_loss = 38.00) # I set the stop at 38.00

STOP_LOSS_for_LONG_POSITION() # Execute it.

Jessika-Art avatar Jul 17 '22 20:07 Jessika-Art

@Jessika-Art thank you for your response but it doesn't work.

Any another idea?

kamilkuczynski avatar Jul 20 '22 09:07 kamilkuczynski

@Kamkuczpol my friend, I just created a simple repo just for you so you can copy the code that works. To make easier your research the functions you need are in lines 163 and 177 for stop loss for buy and sell and both are called in lines 199 for buy and 210 for sell. I make them easy to read and highly customizable.

https://github.com/Jessika-Art/ByBit-useful-functions/blob/aff18bcbf3d0d81ebad2efcdaffdbbc5ec30d957/ByBit%20usefull%20functions.py

Jessika-Art avatar Jul 20 '22 14:07 Jessika-Art