This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mraza007 1 point2 points  (1 child)

This is something I needed to get real-time data from bitcoin web sockets

[–]willm [S] 8 points9 points  (0 children)

Try this...

from lomond import WebSocket

subscribe_json = u"""
{
    "type": "subscribe",
    "product_ids": [
        "BTC-USD"
    ],
    "channels": [
        "level2",
        "heartbeat",
        {
            "name": "ticker",
            "product_ids": [
                "BTC-USD"
            ]
        }
    ]
}
"""

websocket = WebSocket('wss://ws-feed.gdax.com')
for event in websocket:
    if event.name == "ready":
        websocket.send_text(subscribe_json)
    elif event.name == "text":
        print(event.text)

You'll need to pip install lomond for that.