sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.89k stars 2.2k forks source link

futures_get_open_orders() is not working #1323

Closed GozdeKorpe closed 1 year ago

GozdeKorpe commented 1 year ago

This code will loop through all open orders, calculate the profit of each order and cancel it if the profit has reached a certain point. However, the futures_get_open_orders() function returns empty even though ı have an open order. I tried other functions, ı can change the leverages and open orders but can't see the open orders. I read the document and couldn't find anything wrong. What could be the problem? The code: from binance.client import Client import keys

api_key = keys.API_KEY api_secret = keys.SECRET_KEY client = Client(api_key, api_secret)

all_orders = client.futures_get_all_orders()

Loop through each order

while True:

Get all open orders

open_orders = client.futures_get_open_orders()
print(open_orders)

# If there are no open orders, break out of the loop
if not open_orders:
    break

Loop through each open order

for order in open_orders:

symbol = order['symbol']
order_id = order['orderId']

# Get the details of the open order
order = client.futures_get_order(symbol=symbol, orderId=order_id)

# Calculate the current profit of the order
buy_price = float(order['price'])
current_price = float(client.futures_symbol_ticker(symbol=symbol)['price'])
profit = (current_price - buy_price) / buy_price

# Close the order if the profit has reached 50%
if profit >= 0.1:
    client.futures_cancel_order(symbol=symbol, orderId=order_id)
sirfrank commented 1 year ago

what you want to do .... 1/ send your order with uniqueID (and of course save your IDs) 2/ get the position data (quantyity, etc) 3/ set your percent price for SL/TP make a NEW order (based on the received parameters ) against your order (if it was sell -> buy, IF it was Buy -> Sell).

Just finished my very similar application. Doable, but not THAT easy, and futures_cancel_order is different, NOT closing your position.

GozdeKorpe @.***> ezt írta (időpont: 2023. máj. 11., Cs, 21:23):

This code will loop through all open orders, calculate the profit of each order and cancel it if the profit has reached a certain point. However, the futures_get_open_orders() function returns empty even though ı have an open order. I tried other functions, ı can change the leverages and open orders but can't see the open orders. I read the document and couldn't find anything wrong. What could be the problem? The code: from binance.client import Client import keys

api_key = keys.API_KEY api_secret = keys.SECRET_KEY client = Client(api_key, api_secret)

all_orders = client.futures_get_all_orders() Loop through each order

while True:

Get all open orders

open_orders = client.futures_get_open_orders() print(open_orders)

If there are no open orders, break out of the loop

if not open_orders: break

Loop through each open order

for order in open_orders:

symbol = order['symbol'] order_id = order['orderId']

Get the details of the open order

order = client.futures_get_order(symbol=symbol, orderId=order_id)

Calculate the current profit of the order

buy_price = float(order['price']) current_price = float(client.futures_symbol_ticker(symbol=symbol)['price']) profit = (current_price - buy_price) / buy_price

Close the order if the profit has reached 50%

if profit >= 0.1: client.futures_cancel_order(symbol=symbol, orderId=order_id)

— Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/1323, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVKGMYR6IWMO6XHVLHRGI3XFU4BZANCNFSM6AAAAAAX6SABP4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

GozdeKorpe commented 1 year ago

I want to get open orders ID's but can't get them with this function. Do you know how can ı fix this? @sirfrank

GozdeKorpe commented 1 year ago

.