Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading