I know that there is an option to get an order book in the api, but that’s not what I’m looking for.
I need to get the exact number of all take profit and stop loss through the bybit api
Is it possible to implement this and if so, how?
Thanks
>Solution :
Brave’s Leo suggested this:
import requests
api_key = "YOUR_API_KEY"
url = f"https://api.bybit.com/v3/public/orders?symbol=BTCUSDT&apikey={api_key}"
response = requests.get(url)
orders = response.json()
take_profit_orders = [order for order in orders if order["status"] == "takeProfit"]
stop_loss_orders = [order for order in orders if order["status"] == "stopLoss"]
print(f"Take profit orders: {len(take_profit_orders)}") print(f"Stop loss orders: {len(stop_loss_orders)}")
This code will retrieve all open orders for the BTCUSDT symbol using the Bybit API, and then filter the results to only include orders with the appropriate status. The len() function is used to get the length of each list, which gives us the exact number of take profit and stop loss orders.
I hope this helps! Let me know if you have any other questions.