Unlocking Candle Data for Unsupported Timeframes on Coinbase
Written on
Understanding Candle Data
Have you ever found yourself in need of candle data for a timeframe that isn't supported by the exchange's API? In this article, I'll present a straightforward solution to this dilemma. To start, we need to access the API documentation, specifically for Coinbase, which can be found here. You’ll learn how to retrieve the data you want directly from the public REST API, without requiring API access tokens.
Initially, we will gather all available symbols, followed by creating a method to return OHLC (Open, High, Low, Close) and OHLCV (which also includes Volume) data, as well as fetching tickers. OHLC and OHLCV are acronyms that signify the key metrics of a candle's state: the opening price, highest price, lowest price, closing price, and trading volume over a specified period.
The granularity field must be set to one of the following intervals: {60, 300, 900, 3600, 21600, 86400}.
Using Granularity to Achieve Desired Timeframes
To enhance our granularity options, we can cleverly combine smaller units to create larger timeframes. For instance, we can use 60-second granularity to obtain 3-minute candles, or 900-second granularity for 30-minute candles.
Let's start by fetching the symbols.
When you execute this shortcode, you'll receive a list of all available symbols, similar to: [‘OGN-USD’, ‘SHPING-EUR’, …, ‘XRP-BTC’]. Now, it's time to introduce the method for retrieving OHLCV data. The method for fetching OHLC data is quite similar, so I won't include it here. For your reference, you can check the API documentation for obtaining candles.
In the documentation, you'll notice that we need a product_id that represents a trading pair, such as DOGE-USDT. Additionally, we must specify granularity, which indicates the supported timeframes by the exchange's API. We can also include start and end timestamps. We'll begin by constructing a request body before moving on to executing the requests, which will ultimately be processed into a pandas DataFrame.
In one of the subsequent steps, we'll add a new column to convert the time into a date format.
How does the implementation look in code?
According to the API documentation, we can make three API calls per second on the public API. This limitation is why you may encounter NaN values in the results.
Want to test this implementation? Feel free to explore my GitHub repository. If you're interested in similar topics, let me know!
Thank you for taking the time to read this article! If you found it helpful, please give it a thumbs up and follow me for more content like this!
Chapter 2: Enhancing Trading Skills
In this video titled "HOW TO USE AND TRADE ON COINBASE ADVANCED (UPDATED!)", you'll learn advanced trading techniques and how to effectively use Coinbase for your trading needs.
Chapter 3: Mastering Crypto Scalping
The video "BEST 5 Minute Crypto Scalping Strategy (Simple)" covers a straightforward yet effective scalping strategy that can enhance your trading skills in just five minutes.