Consumer and API server for open Web3 subgraphs. For more information regarding implementation and design considerations, see consumer-api-design.md. Enthusiasts may visit the official docs to learn more about The Graph indexing protocol.
- Ensure Python 3.10 is installed
- Create a virtual environment:
python -m venv .venv
- Activate virtual environment:
- Windows:
.venv/Scripts/activate
- Mac:
. .venv/bin/activate
- Windows:
- Run
pip install -r requirements.txt
- Following the
.env.example
, create an.env
file with your database configuration - You will need to create a new
token_hour_data
andtoken
table as shown below
CREATE TABLE
token_hour_data (
PRIMARY KEY (iso_timestamp, token_symbol),
iso_timestamp TIMESTAMP NOT NULL,
token_symbol VARCHAR(255) NOT NULL,
open FLOAT NOT NULL,
close FLOAT NOT NULL,
high FLOAT NOT NULL,
low FLOAT NOT NULL,
price_usd FLOAT NOT NULL
);
CREATE TABLE
token (
PRIMARY KEY (symbol),
name VARCHAR(255) NOT NULL,
symbol VARCHAR(255) NOT NULL,
total_supply VARCHAR(255) NOT NULL,
volume_usd VARCHAR(255) NOT NULL,
decimals VARCHAR(255) NOT NULL
);
The run.sh
script activates the environment and runs the app. Note that you may need to update the paths depending on your operating system. Alternatively, you may run the app by following the steps below:
- Activate virtual environment:
- Windows:
.venv/Scripts/activate
- Mac:
. .venv/bin/activate
- Windows:
- Run
python src/app.py
For querying the API manually I recommend using Postman:
- Create a new HTTP GET under a new collection
- Base URL is
{{your_base_url}}/chart-data
- Query params are
token_symbol
(case-insensitive) andtime_unit_in_hours
Oftentimes, if you aren't running Postman locally, you may have trouble reaching localhost. One recommendation is to setup ngrok which allows you to access your localhost from the internet.
If using VSCode, when debugging be sure to set breakpoints in any file but start the debugger on src/app.py
. Otherwise, a ModuleNotFoundError
will be thrown.
Use flake8 src/
in the root project directory to run against all src/
files.
To run automated acceptance tests:
- Ensure that your database and tables are setup according to above
- If the database has not been populated yet run
sh run.sh
(skip if already populated) - Run
sh run_test.sh
to trigger e2e tests