ByBit Api: how can i get all tokens tp/sl orders

239 views Asked by At

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?

1

There are 1 answers

1
Magic Thighs On

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.