bitvavo / python-bitvavo-api

Python wrapper for the Bitvavo API
https://pypi.org/project/python-bitvavo-api/
ISC License
38 stars 25 forks source link

API Endpoint request: Charts #26

Open icheered opened 3 years ago

icheered commented 3 years ago

The chart on the main screen is simply a dataset retrieved with a simple API call but required the user to be logged in (it must include JWT auth params). It would be great if this is also available on the official API endpoint so that its possible to display this data outside of the bitvavo client (for use cases like dashboards with graphs for different assets like stocks and crypto).

NostraDavid commented 2 years ago

You could work around this by grabbing the candles and averaging the open and close (note that timedelta(days=1) is the most important bit here)

from datetime import datetime, timedelta

response = bitvavo.candles(
    symbol="SHIB-EUR",
    interval="1m",
    options={
        "start": int((datetime.now() - timedelta(days=1)).timestamp() * 1000),
        "limit": 1440,
        "end": int(datetime.now().timestamp() * 1000),
    },
)
print(response)

For whatever weird reason, candles come as a list, so here is a snippet based on the docs to make it make sense :)

for candle in response:
    average = (float(candle[1]) + float(candle[4])) / 2
    print(
        f"average: {average} - timestamp {candle[0]}, open {candle[1]}, high {candle[2]}, low {candle[3]}, close {candle[4]}, volume {candle[5]}"
    )