sammchardy / python-kucoin

Kucoin REST and Websocket API python implementation
https://python-kucoin.readthedocs.io/en/latest/
MIT License
352 stars 148 forks source link

KucoinAPIException UNAUTH: Invalid nonce when executing certain commands #12

Closed Chriane closed 6 years ago

Chriane commented 6 years ago

Hello there,

I am receiving a KucoinAPIException whenever I try to execute certain commands; other commands, like get_languages() or get_historical_klines_tv() work fine.

I created a simple script:

 from kucoin.client import Client
 from kucoin.exceptions import KucoinAPIException

 try:
    client = Client(API_KEY, SECRET_KEY)
    clientLanguages = client.get_languages()
    print(clientLanguages)
    clientActiveOrders = client.get_active_orders('KCS-BTC', True)
    print(clientActiveOrders)
 except KucoinAPIException as e:
    print('your exception was due to {}'.format(e) )
    print('error code {}'.format(e.code) )  # UNAUTH
    print('error message {}'.format(e.message) )  # Not Found

This returns the following output:

[['en_US', 'English', True], ['ru_RU', 'русский', True], ['ko_KR', '한국어', True], ['ja_JP', '日本語', True], ['pt_PT', 'Portugues', True], ['zh_CN', '中文简体', True], ['nl_NL', 'Nederlands', True], ['zh_HK', '中文繁体', True], ['de_DE', 'Deutsch', True], ['fr_FR', 'Français', True], ['es_ES', 'Español', True]]
your exception was due to KucoinAPIException UNAUTH: Invalid nonce
error code UNAUTH
error message Invalid nonce

So the first command is executing fine, but the second one is not... Anyone can tell me what I am doing incorrectly?

Thanks in advance!

Chriane commented 6 years ago

Fixed the problem; had to set the Timezone to UTC:

from kucoin.client import Client
from kucoin.exceptions import KucoinAPIException
import os

os.environ['TZ']='UTC'

try:
    client = Client(API_KEY, SECRET_KEY)
    clientLanguages = client.get_languages()
    print(clientLanguages)
    clientActiveOrders = client.get_active_orders('KCS-BTC', True)
    print(clientActiveOrders)
except KucoinAPIException as e:
    print('your exception was due to {}'.format(e) )
    print('error code {}'.format(e.code) )  # UNAUTH
    print('error message {}'.format(e.message) )  # Not Found