Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
How to get the conversion rate of TON to a fiat currency?

Is there an API to programmatically get the current conversion rate of TON to a fiat currency?


This question was imported from Telegram Chat: https://t.me/tondev/113809

  
  
Posted one year ago
Votes Newest

Answers


You can use pancakeswap API for get coin price in USD and convert it in your application

Simple example

const PANCAKESWAP_TONCOIN_ID = '0x76a797a59ba2c17726896976b7b3747bfd1d220f'
const PANCAKESWAP_URL = 'https://api.pancakeswap.info/api/v2/tokens'
const UPDATE_ERROR = "Can't update token price"


await new Axios({})
  .get(`${PANCAKESWAP_URL}/${pancakeswapTokenId}`)
  .then(async (response) => {
    if (
      response.status === 200 &&
      response.data &&
      parseJSON(response.data)
    ) {
      const { data } = parseJSON(response.data)

      if (data.price && validateThirdpartyPrice(data.price)) {
        resolve({ price: data.price })
      } else {
        resolve({ error: UPDATE_ERROR })
      }
    } else {
      resolve({ error: UPDATE_ERROR })
    }
  })
  .catch(() => {
    resolve({ error: UPDATE_ERROR })
  })

As you can see in data.price you will get value like: 2.42187 (Toncoin in USD)

17K Views
1 Answer
one year ago
one year ago
Tags
api