danpaquin / coinbasepro-python

The unofficial Python client for the Coinbase Pro API
MIT License
1.82k stars 740 forks source link

Issue with "get_product_historic_rates" start and end dates #439

Open Bainsbe opened 3 years ago

Bainsbe commented 3 years ago

The "get_product_historic_rates" function seems to return more values than needed when "start" or "end" variables get passed in.

import cbpro as cbp

client = cbp.PublicClient()
response = client.get_product_historic_rates( 'BTC-USD', start = '2021-05-01T01:00:00', granularity = 86400)

The above returns 300 values despite granularity being daily and the start time being only 7 days ago. The endpoint seems to be returning correct values for the query when tested separately. Tested it on: https://gdaxurl.surge.sh/

ensingerphilipp commented 3 years ago

Specify the "end" date 1 Day later and it should work

response = client.get_product_historic_rates( 'BTC-USD', start = '2021-05-01T01:00:00', end = '2021-05-02T01:00:00', granularity = 86400)

Bainsbe commented 3 years ago

@ensingerphilipp Thanks, that works!

Maybe worth looking into implementing a fix for this on the back end - so end defaults to today if start is passed in alone and end defaults to end date minus 300 periods if passed in alone.