Using the Kucoin API with Python

Hoss@Hossapp /

Using the Kucoin API with Python

In this tutorial, we will demonstrate how to make some basic requests with the Kucoin API using Python.

Installing and Importing Libraries

Before you start using the API, you will need to install a few libraries. Run ‘pip install python-kucoin’ in your terminal. If you want to sign up for Hoss - which provides you with deep visibility into API performance, alerts you of errors before your customers notice, and reduces the amount of time spent debugging integrations - you can do so here. Run ‘pip install hoss’ in order to install the Hoss SDK.

At the top of your file, include the following snippet.

from kucoin.client import Client
import hoss_agent

Integrate the Hoss SDK

Here, we integrated the Hoss SDK. Obtain your Hoss keys in your settings here. We will use the development key for this tutorial.

hoss_client = hoss_agent.init('<HOSS API KEY>')

Getting Started With Kucoin

If you haven’t done so already, you will need to create a Kucoin Developer account here. This is where you can find the documentation and your API credentials.

Configure the Client

In order to make requests, we will have to create a Client object. This requires the API key, API secret, and API passphrase.

api_key = '<api_key>'
api_secret = '<api_secret>'
api_passphrase = '<api_passphrase>'

client = Client(api_key, api_secret, api_passphrase)

Getting a List of Currencies

You can get a list of cryptocurrencies with the get_currencies() method.

# get currencies
currencies = client.get_currencies()

You can view the response as follows.

        "currency": "BTC",
        "name": "BTC",
        "fullName": "Bitcoin",
        "precision": 8,
        "withdrawalMinSize": "0.002",
        "withdrawalMinFee": "0.0005",
        "isWithdrawEnabled": true,   
        "isDepositEnabled": true,
        "isMarginEnabled": true,
       "isDebitEnabled": true


Get Market Depth

You can get the market depth with the getorderbook() method.

# get market depth
depth = client.get_order_book('KCS-BTC')

You can view the response as follows.

    "sequence": "3262786978",
    "time": 1550653727731,
    "bids": [["6500.12", "0.45054140"],
             ["6500.11", "0.45054140"]],  //[price,size]
    "asks": [["6500.16", "0.57753524"],
             ["6500.15", "0.57753524"]]   

View your Request History in Hoss

To view the request log, simply click on requests at the top. You can filter out requests by API by also clicking on a specific API labeled on the sidebar.

Set Up Alarms

You can configure alarms to notify you of any API integration errors or failures. Hoss also provides integrations with Slack and Pagerduty.

Masking Fields

It should be noted that when developing with the Kucoin API, you may receive PII from the API responses. You can use Hoss’ masking feature to help comply with data protection regulations. Learn more about it here.

Next Steps

That’s it! You can access the full Kucoin API documentation here and get started building your application!

Subscribe to Hoss ModeA weekly newsletter with curated articles, community discussions, news and trends.

Using the Alpaca API with Node.js

Read more
In this tutorial, we’ll show you how to get started with the Alpaca API when developing in Node.js. We’ll cover downloading the important libraries, integrating the Hoss SDK, and executing trades.
Back to blog

Copyright © Hoss Technologies, Inc. 2021 - All rights reserved. Terms of Service & Privacy Policy