aio_kraken_ws package

Module to collect ohlc candles from Kraken using websockets.

Submodules

aio_kraken_ws.kraken_ws module

Module with the interface to interact with Kraken websocket API. https://www.kraken.com/features/websocket-api

class aio_kraken_ws.kraken_ws.KrakenWs(callback, url='wss://ws.kraken.com', 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://ws.kraken.com', reset_period=60)[source]

Create and returns a running instance of KrakenWs.

Parameters
  • 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.

Returns

KrakenWs instance

property datasets

Datasets currently streamed.

Returns

List of pair name, interval

Return type

list((str,int))

async start()[source]

Start the stream.

subscribe(datasets)[source]

Stream datasets.

Parameters

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

unsubscribe(datasets)[source]

Stop streams.

Parameters

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