Connecting Python to the GDAX Websocket Feed

Reading the GDAX Feed using Python

GDAX provides a public websocket service which allows anyone to read real-time GDAX data. This is a great service when you consider that it is free to anyone that has the skills to utilize it. This feed could be used for automated trading purposes or for performing real-time calculations that are not included in the GDAX web UI.

In this case, there is not an official GDAX Python module. There are some notable modules on GitHub which you could utilize. We will put together some code using the well established websocket module.

A WORD OF CAUTIONCoinbase handles financial assets. Always use the sandbox when testing code and ideas. Use appropriate security measures when using API credentials. 


  • Create a subscription request in JSON format
  • Send the subscription request to wss://
  • Display the results
  • Display the execution duration in seconds each time 


  1. Install the python websocket and json modules
  2. Choose the GDAX Channels to join

Python Code

I will be subscribing to the Litecoin ticker using the code below. Feel free to use the currency of your choice.

from websocket import create_connection
import json, time

# Tracking execution time
start = time.time()

# Create connection
ws = create_connection("wss://")

# Create subscription message
message = {
    "type": "subscribe",
    "channels": [{"name": "ticker", "product_ids": ["LTC-USD"]}]
# Send subscribe Message

result = ws.recv()
print result

# execution time
print "\nExecution Time: " + str(time.time() - start)


  • The subscribe message needs to be sent once
  • Omit the ws.close() statement to keep the websocket connection open
  • Run the ws.recv() command to read the feed



Execution Time: 0.608999967575

And Then?

In a future post, we will look at how to store this feed data, perform useful calculations, and then visualize the data.


  1. You might be interested in Lomond:


Post a Comment

Popular posts from this blog

Hacking the Sonoff Wifi Switch - Part 2

Creating Alexa Skills for IoT and Nodemcu - Part 2 AWS IoT

Hacking the Sonoff Wifi Switch - Part 3 Alexa Smart Home