Code Monkey home page Code Monkey logo

web3-subgraph-consumer-api's Introduction

web3-subgraph-consumer-api

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.

Setup

  1. Ensure Python 3.10 is installed
  2. Create a virtual environment: python -m venv .venv
  3. Activate virtual environment:
    • Windows: .venv/Scripts/activate
    • Mac: . .venv/bin/activate
  4. Run pip install -r requirements.txt

Database Configuration

  1. Following the .env.example, create an .env file with your database configuration
  2. You will need to create a new token_hour_data and token 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
    );

Local Run

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:

  1. Activate virtual environment:
    • Windows: .venv/Scripts/activate
    • Mac: . .venv/bin/activate
  2. Run python src/app.py

Querying The API

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) and time_unit_in_hours

Querying The API Externally

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.

Debugging

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.

Linting

Use flake8 src/ in the root project directory to run against all src/ files.

Automated Testing

To run automated acceptance tests:

  1. Ensure that your database and tables are setup according to above
  2. If the database has not been populated yet run sh run.sh (skip if already populated)
  3. Run sh run_test.sh to trigger e2e tests

web3-subgraph-consumer-api's People

Contributors

stevenxchung avatar

Watchers

Phillip avatar Hsu Han Ooi avatar Matheus Felipe avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.