Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coinbase API v2 Getting Historic Price for Multiple Days

I'm having some trouble with a Coinbase.com API call for historical data.

Previously, I was getting a variable length of days that would match the amount of space available on a terminal screen with a request URL that looked like this:

https://api.coinbase.com/v2/prices/historic?currency=USD&days=76

This would pull the previous 76 days of price history. An example of the old output is here: https://gist.github.com/KenDB3/f071a06ab3ef1a899d3cd8df8b40a049#file-coinbase-historic-days-example-2017-12-23-json

This stopped working a few days ago. The closest I can get to this is with this request URL (though I don't get the data I want):

https://api.coinbase.com/v2/prices/BTC-USD/historic?days=76

The output from this can be seen here: https://gist.github.com/KenDB3/f071a06ab3ef1a899d3cd8df8b40a049#file-coinbase-historic-days-example-2018-07-19-json

In the second example, it is just displaying prices from the day of the query at different times of that day. What I really want is the first example output where it gives a single price per day going back as many days as the request is for.

The project this is connected to is here: https://github.com/KenDB3/SyncBTC

Links that do not work: https://api.coinbase.com/v2/prices/historic?currency=BTC-USD&days=76 (No Results) https://api.coinbase.com/v2/prices/BTC-USD/historic?2018-07-15T00:00:00-04:00 (Does not pull data from 7/15/2018)

like image 367
KenDB3 Avatar asked Jul 19 '18 07:07

KenDB3


People also ask

How do I get historical data from Coinbase?

Historical data can be obtained by using the get_product_historic_rates endpoint with the Coinbase Pro API. You can specify the granularity, start and end date as the parameters of the API request. Let's obtain the historical data of ETH-USD with the default parameters and arrange it into a cleaned pandas data frame.

Can you trade with Coinbase API?

Coinbase API is a method for us to trade cryptocurrencies on Coinbase automatically via code.

What is my API secret Coinbase pro?

An API Secret, also referred to as API Private Key is simply a password used in combination with an API Key. You can think of the API Passphrase as a second password you need to enter to establish a connection between the two applications. Coinbase Pro implements this as an extra measure of authentication.


1 Answers

Any reason you aren't using coinbase pro?

The new api is very easy to use. Simply add the get command you want followed by the parameters separated with a question mark. Here is the new historic rates api documentation: https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles

The get command with the new api most similar to prices is "candles". It requires three parameters to be identified, start and stop time in iso format and granularity which is in seconds. Here is an example:

https://api.pro.coinbase.com/products/BTC-USD/candles?start=2018-07-10T12:00:00&end=2018-07-15T12:00:00&granularity=900

EDIT: also, note the time zone is not for your time zone, I believe its GMT.

like image 136
Phil_T Avatar answered Sep 24 '22 06:09

Phil_T