Reputation: 69
How do I check if my order is filled? I cant get what I really want, I need a responce that will indicate that the order has been filled. here is my code
# CHECKING IF ORDER IS FILLED
now5 = int(time.time() * 1000)
urlFill = 'https://api.kucoin.com/api/v1/fills'
params5 = {"orderId": OrderID, "side": "sell", "symbol": "AFK-USDT", "type": "limit"}
data_json5 = json.dumps(params5)
sign5 = str(now5) + 'GET' + '/api/v1/fills' + data_json5
signature5 = base64.b64encode(hmac.new(api_secret.encode('utf-8'), sign5.encode('utf-8'), hashlib.sha256).digest())
passphrase5 = base64.b64encode(hmac.new(api_secret.encode('utf-8'), api_passphrase.encode('utf-8'), hashlib.sha256).digest())
headers5 = {"KC-API-SIGN": signature5, "KC-API-TIMESTAMP": str(now5), "KC-API-KEY": api_key, "KC-API-PASSPHRASE": passphrase5, "KC-API-KEY-VERSION": "2", "Content-Type": "application/json"}
response5 = requests.request('get', urlFill, headers=headers5, data=data_json5)
#print(response.status_code)
ORDFLD = (response5.json())
print(ORDFLD)
print(response5.__dict__)
Respond 2:
{'_content': b'{"code":"200000","data":{"currentPage":1,"pageSize":50,"totalNum":0,"totalPage":0,"items":[]}}', '_content_consumed': True, '_next': None, 'status_code': 200, 'headers': {'Date': 'Thu, 07 Jul 2022 23:51:02 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': 'AWSALB=8tMVQE53aj8t24B+W51NkG0sWW21D11T/dhZ4zve5DOcSguLbzMoosUQH6/lAsQwcBCR6dhkGGOAOrVWvVfcrBnruwKPTw7rKJxPT9ynPaB6HL9/4zWNu4VWBumY; Expires=Thu, 14 Jul 2022 23:51:02 GMT; Path=/, AWSALBCORS=8tMVQE53aj8t24B+W51NkG0sWW21D11T/dhZ4zve5DOcSguLbzMoosUQH6/lAsQwcBCR6dhkGGOAOrVWvVfcrBnruwKPTw7rKJxPT9ynPaB6HL9/4zWNu4VWBumY; Expires=Thu, 14 Jul 2022 23:51:02 GMT; Path=/; SameSite=None; Secure, __cfruid=b4a23d97c7f50a8d3bcfba85a03076479ed8f439-1657237862; path=/; domain=.kucoin.com; HttpOnly; Secure; SameSite=None', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Expires': '0', 'X-Frame-Options': 'DENY', 'Strict-Transport-Security': 'max-age=9800; includeSubDomains; preload', 'CF-Cache-Status': 'DYNAMIC', 'Expect-CT': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"', 'Server': 'cloudflare', 'CF-RAY': '72747c5e4aacb872-AMS', 'Content-Encoding': 'gzip'}, 'raw': <urllib3.response.HTTPResponse object at 0x000001E2CEA7A250>, 'url': 'https://api.kucoin.com/api/v1/fills', 'encoding': 'utf-8', 'history': [], 'reason': 'OK', 'cookies': <RequestsCookieJar[Cookie(version=0, name='__cfruid', value='b4a23d97c7f50a8d3bcfba85a03076479ed8f439-1657237862', port=None, port_specified=False, domain='.kucoin.com', domain_specified=True, domain_initial_dot=True, path='/', path_specified=True, secure=True, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None, 'SameSite': 'None'}, rfc2109=False), Cookie(version=0, name='AWSALB', value='8tMVQE53aj8t24B+W51NkG0sWW21D11T/dhZ4zve5DOcSguLbzMoosUQH6/lAsQwcBCR6dhkGGOAOrVWvVfcrBnruwKPTw7rKJxPT9ynPaB6HL9/4zWNu4VWBumY', port=None, port_specified=False, domain='api.kucoin.com', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=1657842662, discard=False, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='AWSALBCORS', value='8tMVQE53aj8t24B+W51NkG0sWW21D11T/dhZ4zve5DOcSguLbzMoosUQH6/lAsQwcBCR6dhkGGOAOrVWvVfcrBnruwKPTw7rKJxPT9ynPaB6HL9/4zWNu4VWBumY', port=None, port_specified=False, domain='api.kucoin.com', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=True, expires=1657842662, discard=False, comment=None, comment_url=None, rest={'SameSite': 'None'}, rfc2109=False)]>, 'elapsed': datetime.timedelta(microseconds=786296), 'request': <PreparedRequest [GET]>, 'connection': <requests.adapters.HTTPAdapter object at 0x000001E2CE9E4670>}
Upvotes: 0
Views: 684
Reputation: 1
Based on the talk with KuCoin Api moderator in telegram, these 2 fields need to be checked in order to get the status of the order:
$isActive = $orderDetails['isActive'];
$cancelExist = $orderDetails['cancelExist'];
if ($cancelExist) {
return 'canceled';
}
return $isActive ? 'pending' : 'filled';
Upvotes: 0
Reputation: 3857
The endpoint fills
will get you all fills for an order. I.e. when the order was too large to be filled with a single trade, it will get you a list of all fills.
What the endpoint will not return, but what you obviously need, is whether your order has been filled completely.
In order to get that information, you should use endpoint
/api/v1/orders/{order-id}
Where order-id
is the id of the order you are interested in.
It will return a JSON with a field called isActive
.
isActive
is true iff if the order is still active and false iff the order has been filled (or canceled).
Upvotes: 0