Created
June 16, 2020 14:21
-
-
Save hughdbrown/9c6ec5ee9045b7f202c48ca411860594 to your computer and use it in GitHub Desktop.
websockets sample code
This file contains hidden or 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