question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query kucoin for all past user trades returns nothing

See original GitHub issue
  • OS: Linux
  • Programming Language version: Python v3.7.9
  • CCXT version: 1.41.87

Hello. I have been trying to use ccxt to fetch all past Kucoin closed orders of some user’s api key. I read some relevant past closed issues, and noticed that you must query the endpoint in increments of 1 week as per this example in your docs.

I tried to do that with a slightly modified version as the original failed. The "endAt" has to be no more than a week after "startAt" so the max had to be switched to a min, or an error is returned. Also I start since the founding of Kucoin (09/2017 according to google).

# -*- coding: utf-8 -*-

import os
import sys

root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(root + '/python')

import ccxt  # noqa: E402

exchange = ccxt.kucoin({
    "apiKey": "KEY",
    "secret": "SECRET",
    "password": "PASSWORD",
    'enableRateLimit': True,
})
exchange.load_markets()
# exchange.verbose = True  # enable verbose mode after loading the markets

symbol = None  # all orders
now = exchange.milliseconds()
day = 24 * 3600 * 1000
week = 7 * day
since = 1504224000000 # founding of kucoin in ms 
limit = 20
found_orders_num = 0

while since < now:

    end = min(since + week, now)
    params = {'endAt': end}
    orders = exchange.fetch_closed_orders(symbol, since, limit, params)
    print(exchange.iso8601(since), '-', exchange.iso8601(end), len(orders), 'orders')
    found_orders_num += len(orders)
    if len(orders) == limit:
        since = orders[-1]['timestamp']
    else:
        since += week

print(f'Found {found_orders_num} orders')

This returns 0 closed orders. Even though essentially the since parameters starts at the founding of Kucoin and the user does have closed trades in their account.

What am I doing wrong? Am I missing something? Shouldn’t the above return any trades the user has completed in their account since they started using the exchange?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
kroitorcommented, Feb 14, 2021

@LefterisJP i’ve tested it on my side – works for me:

Screenshot 2021-02-14 at 20 21 49
from pprint import pprint
import ccxt

print('CCXT Version:', ccxt.__version__)
exchange = ccxt.kucoin({
    'apiKey': 'YOUR_API_KEY',
    'secret': 'YOUR_SECRET',
    'password': 'YOUR_PASSWORD',
    'enableRateLimit': True,
    'options': {'fetchMyTradesMethod':'private_get_hist_orders'}
})

since = exchange.parse8601('2018-01-01T00:00:00Z')
trades = exchange.fetch_my_trades(None, since)
pprint(trades)
1reaction
LefterisJPcommented, Feb 14, 2021

Hey @kroitor thank you. The key then was 'options': {'fetchMyTradesMethod':'private_get_hist_orders'} and that this one underneath deals in seconds not milliseconds.

Thank you for your time and quick responses.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KuCoin API Documentation: General
General. Introduction. Welcome to KuCoin's trader and developer documentation. These documents outline the exchange functionality, market details, and APIs.
Read more >
Market Endpoints — python-kucoin 0.2.0 documentation
Get a list of all bids and asks aggregated by price for a symbol. This call is generally used by professional traders because...
Read more >
python-kucoin Documentation - Read the Docs
python-kucoin Documentation, Release 0.2.0 ... For each query, the system would return at most 1500 pieces of data. ... last trade price.
Read more >
KuCoin review 2022 | Features, fees and more - Finder.com
The exchange currently has more than 10 million users worldwide and does almost US$750 billion in daily trading volume. Listed KuCoin crypto exchange...
Read more >
KuCoin Review (2022) - Crypto News
It offers bank-level security, slick interface, beginner-friendly UX, and a wide range of crypto services: margin and futures trading, a built-in P2P exchange, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found