Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<coroutine object Client.get_kline_data at 0x00000111C02ADE40> #118

Open
hammerjoe opened this issue Jun 26, 2022 · 2 comments
Open

<coroutine object Client.get_kline_data at 0x00000111C02ADE40> #118

hammerjoe opened this issue Jun 26, 2022 · 2 comments

Comments

@hammerjoe
Copy link

I am trying to get a 1hour Kline for a token and I cant get it to work.

from kucoin.client import Client as kucoin_client
kucoin_api_key = '6cccc1f'
kucoin_api_secret = '96912bcccc47b'
kucoin_api_passphrase = 'Voccccccc!'

kucoin_client = kucoin_client(kucoin_api_key, kucoin_api_secret, kucoin_api_passphrase)
symbol = 'ETH-BTC'
interval = '1hour'
x = {'symbol': symbol}
y = {'kline_type': interval}
try:
getkline = kucoin_client.get_kline_data(**x, **y)
getkline = kucoin_client.get_kline_data(symbol, interval)
except Exception as e:
error_call = e

getkline gets the result: '<coroutine object Client.get_kline_data at 0x00000111C02ADE40>' which obviosuly not what I want.
What am I doing wrong?

@Alireza-Pourreza
Copy link

I think your problem is in the following line:

kucoin_client = kucoin_client(kucoin_api_key, kucoin_api_secret, kucoin_api_passphrase)

try one of them:
1.
from kucoin.client import Client
kucoin_client = Client(kucoin_api_key, kucoin_api_secret, kucoin_api_passphrase)

client = kucoin_client(kucoin_api_key, kucoin_api_secret, kucoin_api_passphrase)

@hammerjoe
Copy link
Author

I was able to solve it.
The call requires a start date and a end date. The docs make it seem its not mandatory.

def date_to_seconds(date_str):
"""Convert UTC date to seconds

If using offset strings add "UTC" to date string e.g. "now UTC", "11 hours ago UTC"

See dateparse docs for formats http://dateparser.readthedocs.io/en/latest/

:param date_str: date in readable format, i.e. "January 01, 2018", "11 hours ago UTC", "now UTC"
:type date_str: str
"""
# get epoch value in UTC
epoch = datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
# parse our date string
d = dateparser.parse(date_str)
# if the date is not timezone aware apply UTC timezone
if d.tzinfo is None or d.tzinfo.utcoffset(d) is None:
    d = d.replace(tzinfo=pytz.utc)

# return the difference in time
return int((d - epoch).total_seconds())

and in the main code:

            start_str = '260 hours ago UTC'
            end_str = None
            start_ts = date_to_seconds(start_str)
            if end_str is None:
                end_str = 'now UTC'
            end_ts = date_to_seconds(end_str)

            try:
                kline2 = kucoin_client.get_kline_data(symbol, interval, start_ts, end_ts)
                frame = pd.DataFrame(kline2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants