python-binance
python-binance copied to clipboard
BinanceAPIException: APIError(code=-1022): Signature for this request is not valid. - when trying to cancel order
Hi, i'm trying to cancel an active order, i get the list of orders with
futures_get_open_orders()
and i try to cancel order like this : futures_cancel_order(symbol='EGLDUSDT', origClientOrderIdList=["asdasda"], timestamp=client.get_server_time()) or: .futures_cancel_order(symbol='EGLDUSDT', orderIdList=[1231321], timestamp=client.get_server_time())
but all the time i get this error:
Traceback (most recent call last):
File "cancel_order.py", line 69, in
i have to mention that buy/get/userdata etc works.
Any suggestions?
thanks
Dear liviuancas,
Method client.get_server_time() returns dictionary {'server Time': 1611500979032}, but timestamp supposed to be int.
Doc says that these type of requests must be signed in a particular way https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#signed-endpoint-examples-for-post-apiv3order
SIGNED (TRADE and USER_DATA) Endpoint security SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body. Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation. The signature is not case sensitive. totalParams is defined as the query string concatenated with the request body.
But i can't find a way for launch these requests through the python library instead of using an external one, like requests
I have the same issue here with futures_cancel_orders. Does anyone have any clue how to solve this?
I have a similar problem with this: Please help!!! I get the same error when sending the order from a Heroku server as a response from a webhook triggered in Tradingview.
order = client_Binance.futures_create_order(
symbol="BTCUSDT",
side="BUY",
type="LIMIT",
timeInForce="GTC",
quantity="0.029",
price="28000.0",
recvWindow=6000000,
newClientOrderId = "LongTrd 1C5BTC2L",
timestamp = 1653043804435
)
However, if I send the webhook from my Mac (to the Heroku server) I do not get the same error.
It only occurs when the Heroku server tries to place the order in Binance as a result of a webhook coming from Tradingview and not my local Mac.
Doc says that these type of requests must be signed in a particular way https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#signed-endpoint-examples-for-post-apiv3order
SIGNED (TRADE and USER_DATA) Endpoint security SIGNED endpoints require an additional parameter, signature, to be sent in the query string or request body. Endpoints use HMAC SHA256 signatures. The HMAC SHA256 signature is a keyed HMAC SHA256 operation. Use your secretKey as the key and totalParams as the value for the HMAC operation. The signature is not case sensitive. totalParams is defined as the query string concatenated with the request body.
But i can't find a way for launch these requests through the python library instead of using an external one, like requests
I have the same question. How to include signature información inside the python library??
You just need to remove spaces and encode the string. Do this:
from urllib.parse import quote
from json import dumps
order_id_str = dumps(order_id).replace(" ", "")
order_id_str = quote(order_id_str)
self.client.cancel_order(symbol=pare, orderIdList=order_id_str)
@sammchardy I have a similar problem with this: Please help!!!