tosunthex / CoinGecko

CoinGecko .Net Standard api wrapper
111 stars 46 forks source link

Converting to Decimal value causes exception #30

Closed grante closed 2 years ago

grante commented 2 years ago

The change earlier this year from double to decimal for all percentage changes has caused a conversion issue. Decimals only support a range [10E-28 .. 10E+28] but coin gecko can return smaller values. The value I received for 'price_change_percentage_30d_in_currency' was '4.047727242293578e+35' which suggests they are sending as doubles which have range [10E-324 ... 10E+308].

When calling GetAllCoinsData() today and walking through all coins, the library eventually threw this exception:

System.Net.Http.HttpRequestException: Input string '4.047727242293578e+35' is not a valid decimal. Path '[43].market_data.price_change_percentage_30d_in_currency.aed', line 1, position 531734.
   at CoinGecko.Clients.BaseApiClient.GetAsync[T](Uri resourceUri)
   at CoinGecko.Clients.CoinsClient.GetAllCoinsData(String order, Nullable`1 perPage, Nullable`1 page, String localization, Nullable`1 sparkline)
OxfordGrid commented 2 years ago

Getting the same error for tickers.last

tosunthex commented 2 years ago

Hi @grante and @OxfordGrid

Thanks for your reply I changed it because I think precision is important and i still don't understand why coingecko return value like that from percentage change.

You can find double type for all of the percentage_change parameters in the new version.