Skip to content

Instantly share code, notes, and snippets.

@singlerider
Last active November 21, 2017 22:42
Show Gist options
  • Save singlerider/859d6e3858165129f1fee296ab290747 to your computer and use it in GitHub Desktop.
Save singlerider/859d6e3858165129f1fee296ab290747 to your computer and use it in GitHub Desktop.
websockets==4.0.1
#!/usr/bin/env python3
# https://docs.bitfinex.com/v1/reference#ws-public-order-books
import asyncio
import json
import websockets
async def subscribe_to_exchange():
async with websockets.connect('wss://api.bitfinex.com/ws') as websocket:
subscribe = {
"event": "subscribe",
"channel": "book",
"pair": "BTCUSD",
"frequency": "F0",
"precision": "P0"
}
await websocket.send(json.dumps(subscribe))
print("> {}".format(subscribe))
while True:
event = await websocket.recv()
print(event)
asyncio.get_event_loop().run_until_complete(subscribe_to_exchange())
import asyncio
import json
import websockets
async def subscribe_to_exchange():
async with websockets.connect('wss://ws-feed.gdax.com') as websocket:
subscribe = {
"type": "subscribe",
"product_ids": ["BTC-USD"],
"channels": ["full"]
}
await websocket.send(json.dumps(subscribe))
print("> {}".format(subscribe))
while True:
event = await websocket.recv()
print(event)
asyncio.get_event_loop().run_until_complete(subscribe_to_exchange())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment