wiringbits / block-explorer

The official Stakenet block explorer
https://xsnexplorer.io/
36 stars 36 forks source link

server: Add currencies mentioned in issue #117 for the stakenet-light-wallet #443

Closed Sadhill94 closed 2 years ago

Sadhill94 commented 2 years ago

Problem

For the feature #117 (trello ref), we would like to add more currencies. Since the dex use the block explorer to get the currency rates, we have to add these currencies in the block explorer repo first. image

NB: This is not an urgent feature

Solution

After looking around in the project, i realized that by just adding a new line to the object Currency extends Enum[Currency] with the correct(recognized) currency code provided by CMC, it will make the conversion rates works.

Also seeing this api endpoint format, it kindly confirm the process to works and it shouldn't impact too much the current application state.

getPrice in CurrencyService.scala s"v1/tools/price-conversion?id=${coinMarketCapConfig.coinID.string}&amount=1&convert=${currency.entryName}"

Result

I've aswell had a discussion with @AlexITC regarding the implementation, as he told me, he has to verify the current CMC API plan in place to see if adding more currencies won't overwhelm your calls quotas.

I've made some tests with the api payload to make sure the currencies were correct:

BTC examples conversions CMC:

USD
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:54:00.000Z",
    "quote": {
        "USD": {
            "price": 35918.82342837237,
            "last_updated": "2022-01-27T20:54:00.000Z"
        }
    }
}

AUD
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:55:00.000Z",
    "quote": {
        "AUD": {
            "price": 51067.0957600385,
            "last_updated": "2022-01-27T20:55:02.000Z"
        }
    }
}

CHF
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:54:00.000Z",
    "quote": {
        "CHF": {
            "price": 33445.309571801066,
            "last_updated": "2022-01-27T20:54:02.000Z"
        }
    }
}

CNY
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:57:00.000Z",
    "quote": {
        "CNY": {
            "price": 228436.46126972494,
            "last_updated": "2022-01-27T20:57:02.000Z"
        }
    }
}

RUB
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:58:00.000Z",
    "quote": {
        "RUB": {
            "price": 2795248.838970382,
            "last_updated": "2022-01-27T20:58:03.000Z"
        }
    }
}

NOK
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T20:58:00.000Z",
    "quote": {
        "NOK": {
            "price": 320860.58436084737,
            "last_updated": "2022-01-27T20:58:03.000Z"
        }
    }
}

WON
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T21:28:00.000Z",
    "quote": {
        "WON": {
            "price": 4710206.354904945,
            "last_updated": "2022-01-27T21:27:00.000Z"
        }
    }
}

BRL
"data": {
    "id": 1,
    "symbol": "BTC",
    "name": "Bitcoin",
    "amount": 1,
    "last_updated": "2022-01-27T21:28:00.000Z",
    "quote": {
        "BRL": {
            "price": 193458.57072520445,
            "last_updated": "2022-01-27T21:28:03.000Z"
        }
    }
}
AlexITC commented 2 years ago

Also, you will likely want to submit a twin PR to sync the new values in ETH and its tokens: https://github.com/X9Developers/eth-indexer/blob/master/src/main/scala/io/stakenet/eth/explorer/services/CurrencyService.scala#L25