aio_kraken_ws package

Module to collect ohlc candles from Kraken using websockets.


aio_kraken_ws.kraken_ws module

Module with the interface to interact with Kraken websocket API.

class aio_kraken_ws.kraken_ws.KrakenWs(callback, url='wss://', reset_period=60)[source]

Bases: object

Interface to handle Kraken ws.

kraken = await KrakenWs.create(callback)
# or
# kraken = KrakenWs(callback)
# await kraken.start()

await kraken.subscribe([("XBT/EUR", 1)]) # start subscription for interval 1 minute
# → await callback("XBT/EUR",  # pair
#                  1,  # interval
#                  1568315100,  # open timestamp
#                  8000.0,  # open price
#                  8001.0,  # high price
#                  7999.0,  # low price
#                  8000.0,  # close price
#                  15)  # volume
await kraken.subscribe([("ETH/EUR", 1)]) # new subscription, doesn't stop the previsous one

await kraken.unsubscribe([("XBT/EUR", 1), ("ETH/EUR", 1)]) # end of subscriptions

await kraken.close() # shutdown → close ws
async close()[source]

Stop all streams.

async classmethod create(callback, url='wss://', reset_period=60)[source]

Create and returns a running instance of KrakenWs.

  • callback – coroutine call on new candle. Arguments are coroutine(pair: str, o: float, h: float, l: float, c: float, v: float, interval: int)

  • url (str) – Kraken ws endpoint

  • reset_period (int) – time in seconds. The ws connection is reset periodically.


KrakenWs instance

property datasets

Datasets currently streamed.


List of pair name, interval

Return type


async start()[source]

Start the stream.


Stream datasets.


datasets (list((str,int))) – list of (pair name, interval), interval is a time period in minute


Stop streams.


datasets (list((str,int))) – list of (pair name, interval), interval is a time period in minute