Skip to main content

Kucoin API and websocket client

Project description

Kucoin-Cli: Pandas-oriented REST and Websocket API (alpha release)

A data science focused Python API implementation

Why use this library over python-kucoin or the official SDK?

This package was written by a data analyst for data analysts. Specifically designed for fast, efficient data acquisition and high complexity trades such as HFT, market-making, and long-short strategies. Essentially all REST endpoints output to pandas Dataframes, key data acquisition functions include rich features for acquiring large amounts of historic data easily, and the trading side of the package specializes in the managment of margin where I found other packages to be lacking. Of special note, OHLC(V) acquisition from the KuCoin REST API is a bit of a bear to handle as you can only query a single ticker at a time to a max of 1500 bars. Thanks to the magic of pandas, this package has a one-liner capable of calling as many tickers or bars as desired. Perhaps best of all, the package comes with a fully-built one-line data pipeline able to create and update your very own SQL database with almost no effort.

I have used this package to:

  • Automate the generation of a PSQL database with over 400M rows of OHLC(V) data
  • Take a complex statistical arbitrage trading algorithm live via websockets
  • Feed and train ML/RL algorithms for future deployment into live trading sessions

Disclaimer: This is an unofficial implementation of the KuCoin Rest and Websocket API v2. Use this package at your own risk.

Roadmap

  • Clean-up websocket implemention and improve ease of use
  • Improve logging across the package
  • Write better docstrings and update features for lesser used functions
  • Add stop-loss order capabilities
  • Add schema configuration functionality to data pipeline
  • Add futures API access
  • Develop an asynchronous REST client

Features

  • One-line database pipeline. Open a high stability pipe from kucoin's OHLC(V) endpoint to a database of your creation
    • Automatically creates database or adds to pre-existing db
    • Can handle multi-day data acqusitions sessions through dynamic timeout mechanism
  • Feature rich OHLC(V) acquisition
    • Query multiple currencies simultaneously
    • Obtain clean pandas DataFrame output of paganated data
  • Access to 99%+ of REST and Websocket endpoints
  • Fully implemented margin trading features

Quickstart

  1. Register for an account at KuCoin

  2. Generate an API

  3. Download kucoin-cli using pip

    pip install kucoin-cli

  4. Try out some functions!

import kucoincli.client as Client

# Your own credentials here
api_key = 'api_key' 
api_secret = 'api_secret' 
api_passphrase = 'api_passphrase' 

client = Client(api_key, api_secret, api_passphrase)

# Get recent margin dataflow for Bitcoin
margin_df = client.get_margin_data("BTC")

# Pull buy/sell orders for BTC-USDT
order_df = client.get_order_histories("BTC-USDT")

# Query one month of minutely data for BTC-USDT and ETH-USDT
ohlvc_df = client.get_kline_history(
    tickers=["BTC-USDT", "ETH-USDT"],
    begin="2022-01-01",
    end="2022-02-01",
    interval="1min",
)

# Place a margin limit order to sell 1 BTC good for 10 minutes
order = client.margin_limit_order(
    symbol="BTC-USDT",
    side="sell",
    size=1.0000,
    tif="GTT",
    cancel_after=600,
)

# Buy 0.015 ETH-USDT at market price
order = client.market_order(
    symbol="ETH-USDT",
    side="buy",
    size="0.015",
)

Why KuCoin?

  • For U.S. based customer this is one of the last remaining "chaotic" exchanges
  • Industry low transactions fees
  • High liquidity across coins and a wide offering of shitcoins
  • Frequent additions of speculative coins
  • Among the least regulated exchanges
Distributions & Info:
Consider donating:
  • Etherium Wallet: 0x109CcCCEc0449E80336039c983e969DD23B9CE3E
  • Bitcoin Wallet: 3L47AT1SoLGs65RFHYBdVmbCdtQNxZFry6

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kucoin-cli-1.0.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kucoin_cli-1.0.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file kucoin-cli-1.0.0.tar.gz.

File metadata

  • Download URL: kucoin-cli-1.0.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.1

File hashes

Hashes for kucoin-cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c244cc6905f2e0b7cfd8104ae2223ec22d2abc1f21930b84dbdac53c4b3f3356
MD5 df7e4472f55716b0fd274041a508f27d
BLAKE2b-256 cb3b9ff922c4d2b4d05e41c928feb607261cad1ba75e5f48e48f7dc4ce8952b9

See more details on using hashes here.

File details

Details for the file kucoin_cli-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kucoin_cli-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.1

File hashes

Hashes for kucoin_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 781e8778313d580278d506ff830ebdf9e9bb5a4ece178fc55916be8012739aac
MD5 709d0b3353e93576999cd464d94a37ae
BLAKE2b-256 159aada843a124f0890f446d289e85b9162578b422db98f9c48dce9cefdfc096

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page