Skip to content

Instantly share code, notes, and snippets.

@hughdbrown
Created June 16, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughdbrown/9c6ec5ee9045b7f202c48ca411860594 to your computer and use it in GitHub Desktop.
Save hughdbrown/9c6ec5ee9045b7f202c48ca411860594 to your computer and use it in GitHub Desktop.
websockets sample code
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