1. Home
  2. Docs
  3. Chainlink Adapters
  4. Private: Adapter Downloads
  5. Asset Price Adapter Setup

Asset Price Adapter Setup

External Adaptor for Chainlink which aggregates prices of crypto assets from multiple exchanges based on a weighted average of their volume.

This adaptor is built using the bridges framework: https://github.com/linkpoolio/bridges

Currently Supported Exchanges:

  • Binance
  • Bitfinex
  • Bitstamp (Highly rate limited)
  • Bittrex
  • Coinall
  • Coinbase Pro
  • COSS
  • HitBTC
  • Huobi Pro
  • Kraken
  • Gemini
  • ZB

Setup Instructions

Local Install

Make sure Golang is installed.

Build:

make build

Then run the adaptor:

./asset-price-cl-ea -p <port> -t <tickerInterval>
Arguments
CharDefaultUsage
p8080Port number to serve
t1m0sTicker interval for the adaptor to refresh supported trading pairs, suggested units: s, m, h

Docker

To run the container:

docker run -it -p 8080:8080 -e PORT=8080 linkpoolio/asset-price-cl-ea

Container also supports passing in CLI arguments.

AWS Lambda

With the Bridges framework, this adaptor now supports being ran in AWS lambda. Although, it is strongly recommended to run it locally/Docker as it will be considerably slower in Lambda. Reason for this is due to the adaptor needing to fetch all trading pairs from exchanges prior to making the price calls. Whereas when ran non-serverless, this is a background task.

Usage

To call the API, you need to send a POST request to http://localhost:<port>/price with the request body being of the ChainLink RunResult type.

For example:

curl -X POST -H 'Content-Type: application/json' -d '{ "jobRunId": "1234", "data": { "base": "BTC", "quote": "USD" }}' http://localhost:8080/price

Should return something similar to:

{
    "jobRunId": "1234",
    "data": {
        "base": "BTC",
        "quote": "USD",
        "id": "BTC-USD",
        "price": "3836.4042305857843",
        "volume": "131747894.87525243",
        "usdPrice": "3836.4042305857843",
        "exchanges": [
            "HitBTC",
            "Bitfinex",
            "Coinbase",
            "COSS"
        ],
        "warnings": null
    },
    "status": "",
    "error": null,
    "pending": false
}

Or:

curl -X POST -H 'Content-Type: application/json' -d '{ "jobRunId": "1234", "data": { "base": "LINK", "quote": "ETH" }}' http://localhost:8080/price
{
    "jobRunId": "1234",
    "data": {
        "base": "LINK",
        "quote": "ETH",
        "id": "LINK-ETH",
        "price": "0.0031786459052877327",
        "volume": "797.6642187877999",
        "usdPrice": "0.43956635389465454",
        "exchanges": [
            "Binance",
            "Huobi",
            "COSS"
        ],
        "warnings": null
    },
    "status": "",
    "error": null,
    "pending": false
}

To integrate this adaptor with your node, follow the official documentation: https://docs.chain.link/docs/node-operators

Solidity Usage

To use this adaptor on-chain, you can create the following Chainlink request:

Chainlink.Request memory req = buildChainlinkRequest(jobId, this, this.fulfill.selector);
req.add("base", "LINK");
req.add("quote", "BTC");
req.add("copyPath", "price");
req.addInt("times", 100000000);

Allowing you to change base and quote to any trading pair.

Contribution

We welcome any contributors. The more exchanges supported, the better. Feel free to raise any PR’s or issues.

Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *