πŸ§™Price Oracle

Overview

The LN Exchange Price Oracle is the cornerstone of decentralized finance within the Lightning Network, primarily serving RFQ (Request for Quote) services. This platform provides dynamic pricing, including price fluctuations and a spread between buy and sell prices, ensuring accurate and reliable rates for assets traded on the network.

This guide will walk you through integrating with the platform, fetching prices, and adding currency pairs.


Unified Interface Domain

GRPC: oracle.ln.exchange:443 REST: https://oracle.ln.exchange


Fetching Prices

GRPC Calls

Setup: Add the following configuration to your terminal --taproot-assets.experimental.rfq.priceoracleaddress=rfqrpc://oracle.ln.exchange:443

REST Calls

REST API documentation in the section below provides details on how to integrate.

Adding Currency Pairs & Prices

There are 2 methods for adding assets/currency pairs:

Method 1: Using BTC/USDT Price

This method is intended for assets that are tied to the USDT stablecoin. When this method is used, the system automatically fetches the current BTC/USDT price, ensuring that your asset's value reflects real-time market conditions.

Method 2: Manual Price Specification

This method is useful for testing purposes. You can manually specify the price of the assets.

After adding prices using either method, prices can be fetched immediately.

  • If a currency pair or currency doesn’t exist, the system will automatically create them.

  • Prices can be added multiple times; the system will always use the most recently added price when fetching.

  • Note: For dynamic BTC-USDT pricing, set price=0 when adding the price. This value is fixed, and subsequent modifications are restricted.

Please refer to the API section for more details.


Price Oracle API

Quick Start

Example:
oracle ~ % curl --location --request POST 'https://oracle.ln.exchange/napi/price/custom' \
--header 'Content-Type: application/json' \
--data-raw '{
    "paymentAssetName": "BTC",
    "paymentAssetId": "0000000000000000000000000000000000000000000000000000000000000000",
    "subjectAssetName": "LUSDT",
    "subjectAssetId": "1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049",
    "subjectAssetDemical": "4",
    "price": "10",  
    "priceFluctuationRate": "0.02"
}'
{"code":"0","msg":"Success","data":true,"succ":true}

oracle ~ % grpcurl -d '{"subjectAsset":{"assetIdStr":"1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049"},"paymentAsset":{"assetIdStr":"0000000000000000000000000000000000000000000000000000000000000000"}}' oracle.ln.exchange:443 priceoraclerpc.PriceOracle.QueryRateTick
{
  "success": {
    "rate_tick": {
      "rate": "9000",
      "expiry_timestamp": "1724149789477"
    }
  }
}

GRPC Section

Fetch Price

  • URL:oracle.ln.exchange:443

  • Method:priceoraclerpc.PriceOracle.QueryRateTick

Request Parameters

Request Example

grpcurl -d '{"subjectAsset":{"assetIdStr":"1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049"},"paymentAsset":{"assetIdStr":"0000000000000000000000000000000000000000000000000000000000000000"}}' oracle.ln.exchange:443 priceoraclerpc.PriceOracle.QueryRateTick

Response Parameters

Response Example

{
  "success": {
    "rate_tick": {
      "rate": "9000",
      "expiry_timestamp": "1724144023331"
    }
  }
}

REST Section API

REST Request Authentication

All private REST requests must include the following header

Header Parameters


Fetch Price List

  • URL:/napi/price/getList

  • Method:GET

Request Parameters

Request Example

{
    "symbolAssetsId": "0000000000000000000000000000000000000000000000000000000000000000-1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049",
    "transaction_type": "1",
    "current": "1",
    "size": "10"
}

Response Parameters

Response Example

{
    "code": "0",
    "msg": "Success",
    "data": {
        "total": 1,
        "pages": 1,
        "list": [
            {
                "symbol": "BTC-LUSDT",
                "price": 10000,
                "ctime": "2024-08-19T10:01:03",
                "base": "BTC",
                "baseAssetsId": "0000000000000000000000000000000000000000000000000000000000000000",
                "quote": "LUSDT",
                "quoteAssetsId": "1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049"
            }
        ],
        "transaction_type": "1"
    },
    "succ": true
}

Add Currency Pair & Price

  • URL:/napi/price/custom

  • Method:POST

Request Parameters

Request Example (Price not equal to 0)

{
    "paymentAssetName": "BTC",
    "paymentAssetId": "0000000000000000000000000000000000000000000000000000000000000000",
    "subjectAssetName": "LUSDT",
    "subjectAssetId": "1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049",
    "subjectAssetDemical": "4",  
    "price": "10",  
    "priceFluctuationRate": "0.02"
}

Request Example (Price equal to 0)

{
    "paymentAssetName": "BTC",
    "paymentAssetId": "0000000000000000000000000000000000000000000000000000000000000000",
    "subjectAssetName": "LUSDT",
    "subjectAssetId": "1f0e5e108dbaca43b836c8f0990abb5118bbe52c24b9237414d14cd53b1ad049",
    "subjectAssetDemical": "4", 
    "price": "0",  
    "priceFluctuationRate": "0.02"
}

Response Parameters

Response Example

{
    "code": "0",
    "msg": "Success",
    "data": true,
    "succ": true
}

Last updated