Related article: Covalent API — how you can use it
Example of the use of Covalent API - get historical prices by ticker symbol.
Links:
Endpoint used for example (Get historical prices by ticker symbol)
https://api.covalenthq.com/v1/pricing/historical/{quote_currency}/{ticker_symbol}/
- python >= 3.9
- Covalent API key
Clone repo and create .env
file.
git clone https://github.com/erc30/covalent-api-example.git
cd covalent-api-example
cp .env.example .env
The project uses poetry as a dependency management tool. Poetry automatically creates venv and install all requirements to it.
If you have poetry, just run:
poetry install
Or you can manually create a virtual environment and install dependencies via pip:
python3.9 -m venv venv
source venv/bin/activate # activate venv in linux bash
venv\Scripts\activate.bat # activate venv in windows cmd
pip install -r requirements.txt
First add your Covalent API key to .env
file.
Then in main.py
replace following values with the desired ones.
TICKER_LIST
- list of ERC20 tokens. For non ERC20 tokens endpoint return error (maybe only yet?)START_DATE
- start date of price rangeEND_DATE
- end date of price rangeDEPOSIT
- the size of the deposit (USD) to find out how it has changed from start date to end date.
TICKER_LIST = ["UNI", "SUSHI", "BAL", "LRC", "BNT", "IDEX"]
START_DATE = "2021-01-01"
END_DATE = "2021-04-19"
# USD deposit
DEPOSIT = 1000
Activate shell with poetry:
poetry shell
Run script:
python main.py