Last active
November 21, 2017 22:42
-
-
Save singlerider/859d6e3858165129f1fee296ab290747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
websockets==4.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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