how to cancel binance future order

import hmac
import time
import hashlib
import requests
import json
from urllib.parse import urlencode

KEY = ‘xxx’
SECRET = ‘xxx’
BASE_URL = ‘https://fapi.binance.com
def hashing(query_string):
return hmac.new(SECRET.encode(‘utf-8’), query_string.encode(‘utf-8’), hashlib.sha256).hexdigest()

def get_timestamp():
return int(time.time() * 1000)

def dispatch_request(http_method):
session = requests.Session()
session.headers.update({
‘Content-Type’: ‘application/json;charset=utf-8’,
‘X-MBX-APIKEY’: KEY
})
return {
‘GET’: session.get,
‘DELETE’: session.delete,
‘PUT’: session.put,
‘POST’: session.post,
}.get(http_method, ‘GET’)

used for sending request requires the signature

def send_signed_request(http_method, url_path, payload={}):
query_string = urlencode(payload)
# replace single quote to double quote
query_string = query_string.replace(’%27’, ‘%22’)
if query_string:
query_string = “{}&timestamp={}”.format(query_string, get_timestamp())
else:
query_string = ‘timestamp={}’.format(get_timestamp())

url = BASE_URL + url_path + '?' + query_string + '&signature=' + hashing(query_string)
print("{} {}".format(http_method, url))
params = {'url': url, 'params': {}}
response = dispatch_request(http_method)(**params)
return response.json()

used for sending public data request

def send_public_request(url_path, payload={}):
query_string = urlencode(payload, True)
url = BASE_URL + url_path
if query_string:
url = url + ‘?’ + query_string
print("{}".format(url))
response = dispatch_request(‘GET’)(url=url)
return response.json()

params = {
“symbol”: “LTCUSDT”,
“orderId”: 16135555493
}

response = send_signed_request(‘DELETE’, ‘/fapi/v1/order’, params)
print(response)
########### out put #######
{‘code’: -2011, ‘msg’: ‘Unknown order sent.’}

In theory your flow is correct. (Pass order Id obtained when placing an order to the DELETE /fapi/v1/order endpoint). However, this forum is for Binance API related issues, not to debug code for users. I suggest going through your script and try to diagnose the issue.

Binance Terms of Use
Cancellation :

For Orders initiated through Binance Services, you may only cancel them before they have been matched with other Users’ Orders. Once your Order has been matched with another user’s Order, you may not change, revoke or cancel Binance’s authorization to complete the Order. For any partially matched Order, you may cancel the unmatched part of the Order unless such portion has been matched. Binance reserves the right to reject any cancellation request related to the Order you have submitted. If your account does not have sufficient amount of Digital Currencies to execute an Order, Binance may cancel the entire Order, or execute part of the Order with the amount of Digital Currencies you have in your account