Virtual stop loss script for Bybit
Budget: £20 – £250 GBP
Virtual stop loss script for Bybit exchange. The script should be written in python and run on CentOS (Linux).
The script will be used to add a “virtual stop loss” to an existing position on the Bybit derivative exchange. It should work for both USDT perpetual (eg. BTCUSDT) and inverse perpetuals (eg. BTCUSD).
Script usage: vsl –symbol BTCUSDT —side [long|short] –triggerprice 19500 —timersecs 60
For long positions, the script will close my position when (a) price drops below a trigger price and (b) remains below that level for a specified number of seconds. If price returns above the trigger price before the timer has finished then do nothing.
For short positions, the script will close the position when (a) price rises above a trigger price and (b) remains above that level for a specified number of seconds. If price returns below the trigger price before the timer has finished then do nothing
Pseudo code:
1. Login to bybit account and check if there is a position open for the specified symbol with the specified side (long or short)
2. Monitor the price of the symbol in real-time using a webhook
3. If the price crosses the trigger price, start a timer for the specified number of seconds, eg. 60 secs
4. Market close the position when the timer finishes, unless price retraces and crosses back to the trigger price
Example
1. I open a long position to buy 1000 USDT contracts on BTCUSDT at $20,000.
2. I execute the script to set my virtual stop loss at $19,500, eg. vsl –symbol BTCUSDT —side long –triggerprice 19500 —timersecs 60
3. The script starts monitoring the price.
4. The price drops to $19510
5. It then drops to $19490.
6. The script starts a 60 sec timer because price has dropped to the trigger price
7. Price stays at $19490 for 10 seconds then rises to $19505
8. The script then stops the timer (because the price has retraced above the trigger price) and returns back to normal monitoring.
9. 1 hour later, the price drops again from $19510 to $19490
10. The script starts the 60 sec timer
11. The price stays below $19500 for several minutes
12. 60 seconds after the timer started, the script closes my position with a market sell of 1000 USDT contracts at the current price
One additional requirement :-
When the script starts up, it should submit a “dummy” order on the bybit exchange at the trigger price (eg. a conditional order that never executes) so that I can see where my virtual stop loss is placed from bybit. I should be able to move this order to a different price level from my bybit account and the script should detect the price change and adjust the trigger price accordingly.
The script will be used to add a “virtual stop loss” to an existing position on the Bybit derivative exchange. It should work for both USDT perpetual (eg. BTCUSDT) and inverse perpetuals (eg. BTCUSD).
Script usage: vsl –symbol BTCUSDT —side [long|short] –triggerprice 19500 —timersecs 60
For long positions, the script will close my position when (a) price drops below a trigger price and (b) remains below that level for a specified number of seconds. If price returns above the trigger price before the timer has finished then do nothing.
For short positions, the script will close the position when (a) price rises above a trigger price and (b) remains above that level for a specified number of seconds. If price returns below the trigger price before the timer has finished then do nothing
Pseudo code:
1. Login to bybit account and check if there is a position open for the specified symbol with the specified side (long or short)
2. Monitor the price of the symbol in real-time using a webhook
3. If the price crosses the trigger price, start a timer for the specified number of seconds, eg. 60 secs
4. Market close the position when the timer finishes, unless price retraces and crosses back to the trigger price
Example
1. I open a long position to buy 1000 USDT contracts on BTCUSDT at $20,000.
2. I execute the script to set my virtual stop loss at $19,500, eg. vsl –symbol BTCUSDT —side long –triggerprice 19500 —timersecs 60
3. The script starts monitoring the price.
4. The price drops to $19510
5. It then drops to $19490.
6. The script starts a 60 sec timer because price has dropped to the trigger price
7. Price stays at $19490 for 10 seconds then rises to $19505
8. The script then stops the timer (because the price has retraced above the trigger price) and returns back to normal monitoring.
9. 1 hour later, the price drops again from $19510 to $19490
10. The script starts the 60 sec timer
11. The price stays below $19500 for several minutes
12. 60 seconds after the timer started, the script closes my position with a market sell of 1000 USDT contracts at the current price
One additional requirement :-
When the script starts up, it should submit a “dummy” order on the bybit exchange at the trigger price (eg. a conditional order that never executes) so that I can see where my virtual stop loss is placed from bybit. I should be able to move this order to a different price level from my bybit account and the script should detect the price change and adjust the trigger price accordingly.