man-c / pycoingecko

Python wrapper for the CoinGecko API
MIT License
1.04k stars 268 forks source link

Couldn't get ohlc price data #43

Closed Danielization closed 3 years ago

Danielization commented 3 years ago

Hi, I have tried and couldn't get ohlc for each symbol.

Below is my code: cg = CoinGeckoAPI() ohlc = cg.get_coin_ohlc_by_id(id="rublix", vs_currency="usd", days=50) print(ohlc)

Result: raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.coingecko.com/api/v3/coins/rublix/ohlc?vs_currency=usd&days=50

Kindly assists, Thank you.

man-c commented 3 years ago

Hi!

It seems that you can only use days from a specific list (days: Data up to number of days ago (1/7/14/30/90/180/365/max))). Using any from: 1/7/14/30/90/180/365/max as number of days, appears to work fine. For example:

>>> cg.get_coin_ohlc_by_id(id="rublix", vs_currency="usd", days=7)
[[1625918400000, 0.01293, 0.01293, 0.01293, 0.01293], [1625932800000, 0.013005, 0.013017, 0.013001, 0.013017], [1625947200000, 0.013055, 0.013055, 0.012645, 0.012645], [1625961600000, 0.013042, 0.013042, 0.012709, 0.012709], [1625976000000, 0.012831, 0.012885, 0.012753, 0.012885], 
[1625990400000, 0.01291, 0.013023, 0.012728, 0.012885], [1626004800000, 0.013067, 0.013078, 0.012765, 0.012765], [1626019200000, 0.013178, 0.013376, 0.013169, 0.013376], [1626033600000, 0.013486, 0.013486, 0.013243, 0.013247], [1626048000000, 0.013262, 0.01366, 0.013262, 0.013424], 
[1626062400000, 0.013375, 0.013604, 0.013232, 0.013604], [1626076800000, 0.013293, 0.013574, 0.013228, 0.013574], [1626091200000, 0.013401, 0.013512, 0.01326, 0.013471], [1626105600000, 0.013339, 0.013339, 0.012944, 0.012944], [1626120000000, 0.013233, 0.013233, 0.012818, 0.013002], 
[1626134400000, 0.012863, 0.012968, 0.012714, 0.012778], [1626148800000, 0.012856, 0.013156, 0.012813, 0.012813], [1626163200000, 0.013192, 0.013192, 0.012885, 0.012885], [1626177600000, 0.01293, 0.013176, 0.012822, 0.012822], [1626192000000, 0.012901, 0.012901, 0.012605, 0.012605], 
[1626206400000, 0.012999, 0.013041, 0.012765, 0.012765], [1626220800000, 0.012508, 0.012837, 0.012508, 0.012791], [1626235200000, 0.012911, 0.012911, 0.012571, 0.012779], [1626249600000, 0.012634, 0.012645, 0.012358, 0.012645], [1626264000000, 0.01243, 0.012944, 0.01243, 0.012944], 
[1626278400000, 0.012866, 0.012884, 0.012527, 0.012884], [1626292800000, 0.012688, 0.012969, 0.012688, 0.012969], [1626307200000, 0.012662, 0.013143, 0.012662, 0.013143], [1626321600000, 0.012859, 0.013049, 0.012776, 0.012776], [1626336000000, 0.013013, 0.013013, 0.012607, 0.012916], 
[1626350400000, 0.012854, 0.012854, 0.012526, 0.012566], [1626364800000, 0.012715, 0.012715, 0.012623, 0.012682], [1626379200000, 0.01265, 0.01265, 0.01246, 0.012472], [1626393600000, 0.01256, 0.01256, 0.012254, 0.012396], [1626408000000, 0.01234, 0.012444, 0.01233, 0.012444], 
[1626422400000, 0.01236, 0.012596, 0.012309, 0.012356], [1626436800000, 0.012243, 0.012529, 0.012161, 0.012161], [1626451200000, 0.012316, 0.012406, 0.012279, 0.012406], [1626465600000, 0.012723, 0.012757, 0.012343, 0.012707], [1626480000000, 0.012439, 0.012614, 0.012321, 0.012614], 
[1626494400000, 0.012226, 0.012362, 0.012174, 0.012174], [1626508800000, 0.012176, 0.012508, 0.012176, 0.012446], [1626523200000, 0.01252, 0.012594, 0.01248, 0.012594]]

Best