11

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)

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
KenDB3
  • 131
  • 1
  • 1
  • 6

2 Answers2

24

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.

emem.coop
  • 3
  • 1
Phil_T
  • 942
  • 9
  • 27
  • Thank you very much. I had no idea that there was a Coinbase Pro API. While this definitely answers my question on how to once again get historic data, it, unfortunately, doesn't work very well with the program I have written. I think my long term solution will have to come from looking at other APIs that have historic prices of bitcoin. – KenDB3 Jul 23 '18 at 13:07
  • It depends on how far back you want to look, buy coinmarketcap is excellent. If you are comfortable with USDT, bittrex has excellent historical data. Both of these are available through APIs. Happy to help. – Phil_T Jul 23 '18 at 21:37
  • Huh, ok. I'll look into it. I accepted your edit. But I'll take a closer look. I'll see what I'm currently using and post that – Phil_T Nov 13 '19 at 20:15
  • The api all depends on what you are looking for. If you want accurate historical data, there are better options, but usually require money. It is what it is. – Phil_T Nov 13 '19 at 20:17
  • 3
    Okay... I found the problem: you use `stop` as your parameter name (which I blindly copied apparently). It should be `end`. Then it works. – Will Nov 14 '19 at 01:40
  • If you use `stop` instead of `end` it is ignored and you just get the maximum which is 300 data points, which if you want a fuller data set you'll have to program something to repeatedly request a succession of replies. The end time given here is a bit misleading as it won't reach it given the limit. – GenericJam Aug 10 '20 at 12:52
  • I couldn't find BTC data from 2014, but https://api.pro.coinbase.com/products/BTC-USD/candles?start=2016-01-01T12:00:00&end=2016-01-15T12:00:00&granularity=86400 from 2016 returned something. – Ryan Jun 01 '21 at 18:02
3

Here is a wrapper for the CoinBase API for the export of Historical Data: https://pypi.org/project/Historic-Crypto/

It should provide the required outcome through invoking:

pip install Historic-Crypto
from Historic_Crypto import HistoricalData
new = HistoricalData('ETH-USD',300,'2020-06-01-00-00').retrieve_data()

for a full list of cryptocurrencies available:

pip install Historic-Crypto
from Historic_Crypto import Cryptocurrencies

data = Cryptocurrencies(extended_output=False).find_crypto_pairs()
DJW001
  • 143
  • 2
  • 10
  • You fail to mention that this requires you to have "Coinbase Pro". This is different to the question which asks for "Coinbase API V2" – Ernesto Feb 09 '22 at 19:50
  • This is incorrect Ernesto. Please note that the package has worked correctly since 2019, and works without restriction currently. – DJW001 Apr 18 '22 at 20:21
  • All references in the original github say "Coinbaise Pro" and both Cryptocurrencies and HistoricalData classes point only to "api.pro.coinbase.com". Moreover, I tried using this with a non-pro account (i.e. regular Coinbase account) and it does not work. For reference: https://github.com/David-Woroniuk/Historic_Crypto – Ernesto Apr 19 '22 at 11:55
  • Just to further clarify that the Coinbase API V2 (https://developers.coinbase.com/api/v2) is not the Coinbase Pro API (https://developers.coinbase.com/docs/exchange) – Ernesto Apr 19 '22 at 12:08
  • It should work without an account? Seems to work for most people without an account? Agreed that it references pro, I was trying to match behaviour of V2 when I wrote the package. – DJW001 Apr 20 '22 at 07:12
  • OK, but you still use specifically the Pro API. It is a nice alternative and I see its quite popular, so I agree its a better solution, but its not mentioned in the answer nor in the question. Also, its polite to put a disclaimer that you are the developer of a package when offering it as an answer. – Ernesto Apr 21 '22 at 10:31