Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

lino-network/lino-price-feeder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lino Price Feeder

This is a simple and naive implementation of a lino price feeder. It queries the price from multiple exchanges, and take a median price of all.

We recommand validators to run this feeder in an isolated enviroment, with connections to trusted nodes only. The security policy should not allow any in-bound connection.

Usage

Dependency

  • go version >= 1.12

Build

make build
./bin/lino-price-feeder

Configuration

You can configure the behavior of the feeder by changing the configure file. The file below is an example configuration file that queries the BTC-USD price from binance, huobi, and coinbase for example. It will feed price to the blockchain every 650 seconds. When feediing faield, it will retry every 20 seconds, and it will panic if there are 10 errors in a row. The maximum transaction fee is 0.5 lino.

You can add your own price endpoint by adding an item, (name, endpoint, json_path), in `rest_api_list`. For syntax of `json_path`, check: https://github.com/tidwall/gjson.

{
  "chain_id": "lino-testnet-upgrade5",
  "node_url": "tcp://18.213.116.0:26657",
  "max_tx_fee_lino": "0.5",
  "max_retry": 10,
  "retry_interval_sec": 20,
  "feed_every_sec": 650,
  "rest_api_list": [
    {
      "name": "binance",
      "endpoint": "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT",
      "json_path": "price"
    },
    {
      "name": "huobi",
      "endpoint": "https://api.huobi.pro/market/trade?symbol=btcusdt",
      "json_path": "tick.data.0.price"
    },
    {
      "name": "coinbase",
      "endpoint": "https://api.coinbase.com/v2/prices/BTC-USD/spot",
      "json_path": "data.amount"
    }
  ]
}

Print Current Prices

The `price` command will print the current prices queried from endpoints in the configuration.

./bin/lino-price-feeder price --config example.config.json

Feed Price

Example:

$ ./bin/lino-price-feeder feed validatorX --config example.config.json --priv-key @validatorX.key
Password of validatorX.key: 

If you haven’t generated an encrypted key file yet, you need to use `linocli` to get one.

$ linocli encrypt-key myvalidator.key
Hex-encoded Private key: 
Password: 
Password again: 

encrypted key have been wrote to myvalidator.key.