3

I'm new to Python and API and am trying to start with some basics like making a list/plot of old BTC prices. I imported the Coinbase Wallet Client and used client.get_historic_prices(), which gave me a list of the price at midnight UTC for 365 days.

How can I adjust the parameters to get different date ranges and data resolution, for example each minute for two years? Is there a way to search the historic values of buy, sell, and spot separately?

from coinbase.wallet.client import Client 
hist_price = client.get_historic_prices()

xx=[]   
yy=[]    
for ii in range(365): 
    xx.append(ii*-1) # x coordinate being "days ago"          
    yy.append(float(hist_price['prices'][ii]['price']))

Returns (this is just from a print statement of print(hist_price['prices'][0:3]). So it's midnight once a day.

prices
length = 365
{
  "price": "974.39",
  "time": "2017-02-01T00:00:00Z"
}
{
  "price": "944.29",
  "time": "2017-01-31T00:00:00Z"
}
{
  "price": "920.47",
  "time": "2017-01-30T00:00:00Z"
}
Maxim
  • 52,561
  • 27
  • 155
  • 209
joepetrowski
  • 165
  • 2
  • 10

1 Answers1

1

Get_historic_prices is not clearly documented anywhere. This is a mini guide of what I have managed to discover about it and its usage. It's not much but it should be somewhere.

get_historic_prices supports one argument called period which can take the following values:

  • hour
  • day
  • week
  • month
  • year
  • all

Each of them except all returns approximately a list of 360 price points distributed more or less uniformly in the previous hour (day, week, month, year respectively).

all returns a list of price points one for each day at 00:00:00 UTC (i think).

get_historic_prices should also support a currency_pair argument as do the get_buy_price, get_sell_price, and get_spot_price do. Unfortunately, although I have submitted a PR, it has not been merged yet.

Giannis Spiliopoulos
  • 2,628
  • 18
  • 27
  • Giannis - do you have any idea on this issue that I raised: https://github.com/coinbase/coinbase-python/issues/47 – jason m Jun 21 '17 at 12:53
  • @jasonm take a look at my comment [here](https://stackoverflow.com/questions/43037896/historical-etherium-prices-coinbase-api/43124409#comment73360500_43124409). – Giannis Spiliopoulos Jun 22 '17 at 17:12
  • @Giannas - I made your edits as suggested in your git. yet `client.get_historic_prices(currency_pair = 'ETH-USD',period='day')` returns intraday values. is `period='day'` not a string argument? – jason m Jul 13 '17 at 23:04
  • @jasonm day (if i am not mistaken) refers to historic prices starting from 24 hours from now till now so it should return intraday values – Giannis Spiliopoulos Jul 13 '17 at 23:33
  • @GiannisSpiliopoulos sorry, I know this is old, but is there a way to use the get_historic_prices() function with period='all' and get daily values? I am getting weekly price results if I use the 'all' option – Branden Keck Mar 06 '21 at 16:55