python-binance
python-binance copied to clipboard
Cancel all orders
Just wondering if there is a plan to implement this feature from the binance-official-api: Cancel All Open Orders on a Symbol (TRADE) - Cancels all active orders on a symbol. This includes OCO orders.
This would be a really useful feature and save working with Order ID's. Thanks for your hard work.
I want to clarify - I know we can use OCO to cancel our trades but the amount of trades possible appears to be heavily limited when placing OCO orders. I can only place 6 at a time which really isn't enough for me. If we could cancel all orders on a pair it would allow us to control our stops manually and keep up a high volume of orders.
The API call for this on Binance is documented here: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-all-open-orders-on-a-symbol-trade
in client.py:
def cancel_orders(self, **params):
return self._delete('openOrders', True, data=params)
Then client.cancel_orders(symbol='BNBBTC')
I noticed that this function is not available anymore, or am I wrong?
When I use: client.cancel_orders(symbol='BTCUSDT')
I get: Unresolved attribute reference 'cancel_orders' for class 'Client'
I noticed that this function is not available anymore, or am I wrong?
When I use: client.cancel_orders(symbol='BTCUSDT')
I get: Unresolved attribute reference 'cancel_orders' for class 'Client'
As @iterums mentioned, 'cancel_orders' new function should be in 'client' and you re-open your project and re-try. It works for me.
PLEASE HELP NOT WORC close my all orders ((
from binance.client import Client from binance.websockets import BinanceSocketManager import time import math api_key = 'IIIIIIIIIIIIIIIIIIII' api_secret = 'IIIIIIIIIIIIIIIIIIII' client = Client(api_key, api_secret) ASSET = 'ZECUSDT' CURRENCY = 'ZEC' CRYPTOCURRENCY = 'USDT' def balance(symbol): balance = client.get_asset_balance(asset=symbol) balance = {'free': balance['free'], 'locked':balance['locked']} return balance def history(symbol): history = client.get_my_trades(symbol=symbol) return history def price(symbol): price = client.get_avg_price(symbol=symbol)['price'] return float(price) def order_market_buy(quantity): order = client.order_market_buy(symbol=ASSET, quantity=quantity) def order_market_sell(quantity): order = client.order_market_sell(symbol=ASSET, quantity=quantity) #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOT WORC! def cancel_orders(self, **params): return self._delete('openOrders', True, data=params) ################# PRICE = price(ASSET) def main(FIRST_PRICE): print('СЕЙЧАС ЦЕНА',int(PRICE)) nteu = PRICE numbermu = 12 rezultae = nteu - numbermu okruglenie = round(rezultae, 2) print('ЗА СКОЛЬКО КУПИТЬ!', + okruglenie ) nteuz = PRICE numbermuz = 14 rezultaez = nteuz + numbermuz okrugleniez = round(rezultaez, 2) print('ЗА СКОЛЬКО ПРОДАТЬ!', + okrugleniez ) rtytrr = 170 print(okrugleniez) ######################################
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOT WORC! client.cancel_orders(symbol='ZECUSDT')
###################################### START_PRICE = price(ASSET) main(START_PRICE)
[PLEASE HELP NOT WORK!] def cancel_orders(self, **params): return self._delete('openOrders', True, data=params)
You must add that code to the Client class in the client.py file itself, which is located wherever your python-binance is installed.
(In VSCode with the right setup, you can right-click 'Client' on the line 'from binance.client import Client', select "Go to Definition", and that opens client.py.)
[PLEASE HELP NOT WORK!] def cancel_orders(self, **params): return self._delete('openOrders', True, data=params)
You must add that code to the Client class in the client.py file itself, which is located wherever your python-binance is installed.
(In VSCode with the right setup, you can right-click 'Client' on the line 'from binance.client import Client', select "Go to Definition", and that opens client.py.)
how to cancel all sell or buy individually? it's possible?
It's not possible?
@G34567 > how to cancel all sell or buy individually? it's possible?
Your questions are inappropriate here: python-binance is only a Python wrapper around the Binance API, so in this repository you should only post about issues with the wrapper itself. As for the Binance API and what that can or cannot do, you should refer to the official Binance documentation: https://binance-docs.github.io/apidocs/
Hope that helps.
[PLEASE HELP NOT WORK!] def cancel_orders(self, **params): return self._delete('openOrders', True, data=params)
You must add that code to the Client class in the client.py file itself, which is located wherever your python-binance is installed.
(In VSCode with the right setup, you can right-click 'Client' on the line 'from binance.client import Client', select "Go to Definition", and that opens client.py.)
Guys, listen to this. It works! shiftclick "Client" from import Client. Then input the code with the other defs and then save!
The API call for this on Binance is documented here: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-all-open-orders-on-a-symbol-trade
in client.py:
def cancel_orders(self, **params): return self._delete('openOrders', True, data=params)
Then
client.cancel_orders(symbol='BNBBTC')
I'm getting "TypeError: cancel_orders() got an unexpected keyword argument 'symbol'"
Fairly new to python, but I've got a little experience programming as a student. Wondering if the key is something to do with the double asterisk params and its relationship to the data=params passed in to the self._delete function
The API call for this on Binance is documented here: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#cancel-all-open-orders-on-a-symbol-trade in client.py:
def cancel_orders(self, **params): return self._delete('openOrders', True, data=params)
Then
client.cancel_orders(symbol='BNBBTC')
I'm getting "TypeError: cancel_orders() got an unexpected keyword argument 'symbol'"
Fairly new to python, but I've got a little experience programming as a student. Wondering if the key is something to do with the double asterisk params and its relationship to the data=params passed in to the self._delete function
hi, can you post your code here so we can figure out?
@pufferwockey you have to use the following syntax: cancel_orders(symbol='ETHUSDT')
When I try client.cancel_orders(symbol="BTCUSDT")
, I get the following error:
APIError(code=-2011): Unknown order sent.
@jhogg11 have you found a solution yet? I'm encountering the same problem.
All,
Looks like method cancel_orders
is not implemented yet by the current version of library.
The direct call worked for me
binance_client._delete('openOrders', True, data={'symbol': 'DOGEBTC'})
I'm trying what dmitry-ee says ... I have another q: is it possible tu modify a tp? or to cancel only the last tp? how?
you can extend the Client as workaround:
class ExtendedClient(Client):
def cancel_open_orders(self, **params):
return self._delete('openOrders', True, data=params)
and use
client = ExtendedClient(APIKEY, APISECRET)
client.cancel_open_orders('BTCUSDT')
All,
Looks like method
cancel_orders
is not implemented yet by the current version of library. The direct call worked for mebinance_client._delete('openOrders', True, data={'symbol': 'DOGEBTC'})
I'm getting this error when calling this method
APIError(code=-2011): Unknown order sent.
def clearOrders(self):
order = self.client.futures_cancel_all_open_orders(
symbol="BNBUSDT")
binance_client._delete('openOrders', True, data={'symbol': 'DOGEBTC'})
All,
Looks like method
cancel_orders
is not implemented yet by the current version of library. The direct call worked for mebinance_client._delete('openOrders', True, data={'symbol': 'DOGEBTC'})
This worked for me too, Thank you so much dmitry-ee!
This solution:
binance_client._delete('openOrders', True, data={'symbol': 'DOGEBTC'})
works well as long as there is at least one open order to cancel. However, if you try this when there are no open orders, then you will still get an exception with the message:
Unknown order sent.
which some others have mentioned above. One possible workaround (not necessarily a good one) is to edit the client.py file directly. At the moment, the relevant exception is raised at line 367. You can change it to something like this:
if response.status_code == 400:
print(f"WARNING: code 400 (probably Unknown order sent.). I'm just going to ignore it")
return response.text
else:
raise BinanceAPIException(response, response.status_code, response.text)
This isn't a great solution, but it worked for me.
I suggest this code:
orders = client.get_open_orders(symbol='BTCUSDT')
df_orders = pd.DataFrame(orders)
open_orders_count = len(df_orders.index)
for i in range(open_orders_count):
client.cancel_order(symbol='BTCUSDT, orderId=orders[i].get('orderId'))
It counts open orders with symbol BTCUSDT in data frame (number of rows). For me works fine