Kucoin WebSockets#

class kucoincli.sockets.Socket(socket=None)#

Manage channel subscriptions for KuCoin socket connection

async subscribe(channels: str, ticker: str | None = None, market: str | None = None, currency: str | None = None, interval: str | None = None, ack=False) None#

Select set of endpoints and submit authenticated subscriptions

Parameters:
  • channels (str or list) – Channel or list of channels to submit subscriptions for. Channel endpoints can be accessed through .endpoint attribute. List of channels: * orderbook: Access Level 2 orderbook updates. This will only push

    order book updates to the user and as such it is geared towards live orderbook maintenance, not obtaining bid-ask spreads. Pushes updates in real time.

    • 5book: Access top 5 best bid-ask spreads for a single trading pair. Pushes updates at 100ms frequency.

    • 50book: Access top 50 best bid-ask spreads for a single trading pair. Pushes at 100ms frequency.

    • kline: Access live updates to kline data for a single trading pair with candles keyed to specified interval (see interval below for valid intervals). Messages pushed on an as needed basis.

    • trades: [PRIVATE] Receive status update messages related to trades the user has placed on orderbook. Pushes whenever trade event occurs.

    • balance: [PRIVATE] Receive status update messages whenever any account balance changes across the users accounts. Pushes whenever balanace change event occurs.

    • debt: [PRIVATE] Receive pings with margin debt information including margin balances per asset and current debt ratios. Pushes periodically when a margin balance is present.

    • snapshot:

    • market: Subscribe to this channel for summary statistical information related to a single currency, group of currencyies or, all currencies. Pushes new data per trading pair every 100ms or full market currency updates every 2s. Leverages tickers argument to obtain list of currencies to subscribe to for information.

    • indicator:

    • mark:

    • funding:

    • loan:

    • stoporder:

  • ticker (None or str or list, optional) – Many endpoints require the user to specify a ticker or list of ticker for subscription. If ticker=None and a channel does require a ticker, a ValueError will be raised. Note that the market endpoint also allows for subscription to all ticker. Set ticker=”all” or include “all” in list of ticker alongside a market channel subscription to access the all ticker subscription.

  • market (None or str or list, optional) – Market argument only used by snapshot endpoint. Allows users to query whole snapshots by whole market rather individual ticker. Available markets are [BTC, KCS, ETH, ALT]. Subscribe to multiple markets by passing a list.

  • currency (None or str or list, optional) – Some endpoints are queriable by currency rather than trading pair (e.g. BTC). If a user attempts to subscribe to an endpoint that requires a currency specification while currency=None, a ValueError will be raised

  • interval (None or str, optional) – Interval argument only used for kline endpoint. Valid intervals are: [“1min”, “3min”, “15min”, “30min”, “1hour”, “2hour”, “4hour”, “6hour”, “8hour”, “12hour”, “1day”, “1week”]

  • ack (bool, optional) – If ack=True, the server will send an ack response confirming a successful subscription request. ack=False by default.