
Coinbase Crypto Trading Bot
How to Connect to Coinbase with Python 3
Keen to learn how to connect your Python 3 code to Coinbase? You’ve come to exactly the right place!
If you’ve been following my series on building a Coinbase Crypto Trading Bot, welcome back!
Let’s get into it.
About the Series
In this series, I show you how to build your own crypto trading bot to detect a market signal.
The series uses Python 3 to connect to Coinbase, then implements a modified version of the well-known Engulfing Candle Trading Strategy. Throughout the project, I show you how to set up your project in a way that makes it easy to expand with your own ideas and strategies in the future.
All code for the series can be found on the project GitHub. Each episode has working code samples you can copy and paste straight into your own crypto trading bot. I only ask that you throw me a shoutout and a follow on Medium, LinkedIn, or Twitter.
To help you check out your code, I’ve created several locations where the output from this tutorial is posted. The code checks the “BTC-USDC” trading pair and can be found in the #coinbase and #strategyone areas. Check it out on my website, Twitter, and Discord. Note. All trading is at your own risk. Do your own research.
In This Episode
By the end of this episode, you’ll have successfully connected to Coinbase using their Coinbase Pro API. You’ll be able to retrieve your balance and the candlesticks for “BTC-USDC”.
Update August 2023
I could never have anticipated how popular this series, along with a YouTube channel would become.
After a listening to my readers/viewers feedback, I realized that many people were spending huge amounts of time trying to solve installation/configuration problems — rather than experiencing the joy of algorithmic trading.
I want to change this narrative — and in so doing, open up algorithmic trading for everyone.
To do this, I’ve recently launched Tradeoxy: Trading For Everyone.
If you’re reading this, Tradeoxy will simplify 90% of this series, using a series of powerful API’s and easy to use tooling.
Currently it’s in the early-access / building stage and I’d be incredibly grateful if you’d join us on this adventure. Your feedback will help us shape a better product.
Join the early access program (for free) here.
You can also view our launch video, and follow our journey on LinkedIn, Twitter, Instagram, YouTube.
About Coinbase
Coinbase is one of the world’s largest centralized crypto exchanges. In many ways, it is a US-based competitor to Binance.
My observations of Coinbase are as follows:
Pros:
- High focus on developing institutional-grade services for the crypto industry
- Clean UI
- Reasonably featured REST API
- Sandbox trading area (for testing)
Cons:
- API Documentation is somewhat confusing
- REST API is limited compared to Binance (10 requests per second, only retrieves 300 candles at a time)
- Confusing permissions model
- Limited trading options — doesn’t include STOP LOSS or TAKE PROFIT options for orders (or I just haven’t found it, reference my ‘confusing API documentation note)
Regardless, it’s still an impressive API set and more than sufficient for our purposes.
By the way, if you haven’t signed up for Coinbase, feel free to use my referral link.
Sign Up
Signing up for Coinbase is relatively straightforward. You’ll need to go through some standard KYC (Know Your Customer) requirements. Follow the steps here.
API Keys
Getting API Keys
I’ll be honest. Signing up for your API Keys with Coinbase can be a bit confusing. Especially when you’re looking to do it as an individual, rather than an institution. With all the options for Coinbase Pro, Coinbase Prime and so many more, it really can be quite a challenge.
I eventually narrowed it down to the following steps:
- Head to your settings and find the API section (link to API section here)
- Sign in if not already
- Select ‘New API Key’
- Select the accounts you want to apply it to
- For the permissions, we need the following:
wallet:accounts:read, wallet:buys:create, wallet:orders:create, wallet:sells:create, wallet:sells:read, wallet:trades:create, wallet:trades:read, wallet:transactions:read, wallet:user:read - Make sure you save the following somewhere secure: api_key, api_secret
It’s also worth having a look at your security settings to make sure you’re happy with them.
Add API Keys to the Project
Let’s get these keys into our project. Update the settings.json file outlined in episode 1 so that it looks like the following (replace the key strings with the relevant keys):




