Start kraken backend

its_happening
Tyler Goodlet 2020-07-04 18:59:02 -04:00
parent 36303f0770
commit a852292563
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
"""
Kraken backend.
"""
from typing import List
import json
import trio
import tractor
from trio_websocket import open_websocket_url
if __name__ == '__main__':
async def stream_quotes(
pairs: List[str] = ['BTC/USD'],
) -> None:
"""Subscribe ohlc quotes for ``pairs``.
``pairs`` must be formatted like `crypto/fiat`.
"""
async with open_websocket_url(
'wss://ws.kraken.com',
) as ws:
# setup subs
subs = {
'event': 'subscribe',
'pair': pairs,
'subscription': {
'name': 'ohlc',
# 'name': 'ticker',
# 'name': 'openOrders',
# 'depth': '25',
},
}
await ws.send_message(json.dumps(subs))
while True:
msg = json.loads(await ws.get_message())
if isinstance(msg, dict) and msg.get('event') == 'heartbeat':
continue
print(msg)
trio.run(stream_quotes)