Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

oceanprotocol/price-fetch-server

Subgraph Fetch Price Server

This is an express server for requesting the price of tokens from the CoinGecko API. Prices are returned in USD.

Use Case

This server has been created for cases where the CoinGecko API can't be called directly. Instead, a call to this server can be made via IPFS, which will trigger the request to CoinGecko and this server will then return the requested token prices.

For example, the subgraph cannot make HTTP calls so it can use this server as an alternative way of requesting prices for tokens.

Running locally

clone this repo:

git clone git@github.com:oceanprotocol/subgraph-fetch-price.git

Change directory:

cd subgraph-fetch-price

Install the dependencies:

npm install

Start the server locally

npm run start

Paths

There are two paths for requesting prices, one for the current price and one for the historical price:

GET Current price

This gets the current price of the token. The tokenId must be included in the request, a list of valid tokenIds are here. An up to date list can be requested from CoinGecko GET https://api.coingecko.com/api/v3/coins/list

/ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/:tokenId

Example Request:

http://localhost:3000/ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/ocean-protocol

Example response:

{
    "usd": 0.491975
}

GET Historical Price

This request gets the historical price of the token. The tokenId must be included in the request, a list of valid tokenIds are here. An up to date list can be requested from CoinGecko GET https://api.coingecko.com/api/v3/coins/list. The request must also include the timestamp in unix timestamp format (eg. 1550245790).

/ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/:tokenId/:timestamp

Example Request:

http://localhost:3000/ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/ocean-protocol/1620245790

Example response:

{
    "usd": 1.4499657614470953
}

Development

Run the following command to start the server in development mode with nodemon:

npm run dev

Run the following command to build the server:

npm run build

Run the following command to start the server in development:

npm run start

Testing

Run the following command to run all tests:

npm run test

Run the following command to run the formatting and linting tests:

npm run test:format

Run the following command to run the integration tests:

npm run test:integration

Run in Docker

Run the following command to build the service in a Docker container:

npm run build:docker

Next, run the following command to start running the RBAC service in the Docker container:

npm run start:docker

Now you are ready to send requests to the server via postman. Make sure to replace the URL to http://localhost:49160 in your requests.

✨ Code Style

Code style is automatically enforced through ESLint & Prettier rules:

  • Git pre-commit hook runs prettier on staged files, setup with Husky
  • VS Code suggested extensions and settings for auto-formatting on file save

For running linting and auto-formatting manually, you can use from the root of the project:

# linting check, also runs Typescript typings check
npm run lint

# auto format all files in the project with prettier, taking all configs into account
npm run format

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors