Coder Social home page Coder Social logo

coingecko's Introduction

CoinGecko

Build status Codacy BadgeNuget version Nuget downloads

CoinGecko .Net Standard api wrapper

A .Net wrapper for the CoinGecko Api as described on API documentation , including all features the API provides using clear and readable objects.

If you think something is broken, something is missing or have any questions, please open an Issue

Installation

Available on Nuget.

pm> Install-Package CoinGeckoAsyncApi

Quick start

...
using Newtonsoft.Json;
using CoinGecko.Clients;

HttpClient httpClient = new HttpClient();
JsonSerializerSettings serializerSettings = new JsonSerializerSettings();

PingClient pingClient = new PingClient(httpClient, serializerSettings);
SimpleClient simpleClient = new SimpleClient(httpClient, serializerSettings);

// Check CoinGecko API status
if ((await pingClient.GetPingAsync()).GeckoSays != string.Empty)
{
    // Getting current price of tether in usd
    string ids = "tether";
    string vsCurrencies = "usd";
    Console.WriteLine((await simpleClient.GetSimplePrice(new []{ids},new []{vsCurrencies}))["tether"]["usd"]);
}

...

Examples

Examples can be found in the Test project.

Available endpoint

Refer to CoinGecko official API

Ping Endpoints Status Testing
/ping [+] [+]
/simple/price [+] [+]
/simple/token_price/{id} [+] [+]
/simple/supported_vs_currencies [+] [+]
Coins Endpoints Status Testing
/coins/list [+] [+]
/coins/market [+] [+]
/coins/{id} [+] [+]
/coins/{id}/tickers [+] [+]
/coins/{id}/history [+] [+]
/coins/{id}/market_chart [+] [+]
/coins/{id}/market_chart/range [-] [-]
/coins/{id}/status_updates [-] [-]
/coins/{id}/ohlc [+] [+]
Contact Endpoints Status Testing
/coins/{id}/contract/{contract_address} [+] [+]
/coins/{id}/contract/{contract_address}/market_chart/ [+] [+]
/coins/{id}/contract/{contract_address}/market_chart/range [+] [+]
Exchanges Endpoints Status Testing
/exchanges [+] [+]
/exchanges/list [+] [+]
/exchanges/{id} [+] [+]
/exchanges/{id}/tickers [+] [+]
/exchanges/{id}/status_updates [-] [-]
/exchanges/{id}/volume_chart [+] [+]
Finance Endpoints Status Testing
/finance_platforms [+] [+]
/finance_products [+] [+]
Derivatives Endpoints Status Testing
/derivatives [+] [+]
/derivatives/exchanges [+] [+]
/derivatives/exchanges/{id} [+] [+]
/derivatives/exchanges/list [+] [+]
Status Updates Endpoints Status Testing
/status_updates [+] [+]
Events Endpoints Status Testing
/events [+] [+]
/events/countries [+] [+]
/events/types [+] [+]
Exchange Rates Endpoints Status Testing
/exchange_rates [+] [+]
Trending Endpoints Status Testing
/search/trending [+] [+]
Global Endpoints Status Testing
/global [+] [+]
/global/decentralized_finance_defi [+] [+]

Donations

Donations are greatly appreciated and a motivation to keep improving.

BTC: 1Czb4Z4Xj2rmvpN8YuNMc6dr7XNFuYQF5J

coingecko's People

Contributors

artyukh avatar brondavies avatar dependabot[bot] avatar drmathias avatar mak5577 avatar seraksab avatar shommey avatar tosunthex avatar whyme0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coingecko's Issues

Exchanges with Invalid Image Uri "{missing_small.png}"

Hi Thanks for this library! Its working very well.

Currently two exchanges CBX and VinEX have invalid Image uris and subsequently I get downstream exceptions "This operation is not supported for a relative URI". I'd prefer not to have to check each exchange (parse for IsAbsoluteUri) and then workaround.

Any thoughts on perhaps addressing at class level? eg changing Image from Uri to string

image

Converting to Decimal value causes exception

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)

ExchangesMain misses properties

The following properties are are returned by the api but are not present in the ExchangesMain class:

  • trust_score_rank
  • trade_volume_24h_btc_normalized

Null values in the marketcap rank cause an exception in the API client.

Hello! In the CoinsClient parsing any null marketcap rank values from the CoinGecko api causes an exception. This happens in both the GetCoinMarkets function and GetAllCoinDataWithID functions.

The output is:

HttpRequestException: Error converting value {null} to type 'System.Int64'. Path '[32].market_cap_rank', line 1, position 21880.

The stacktrace is:

CoinGecko.Clients.BaseApiClient.GetAsync<T>(Uri resourceUri)
CoinGecko.Clients.CoinsClient.GetCoinMarkets(string vsCurrency, string[] ids, string order, Nullable<int> perPage, Nullable<int> page, bool sparkline, string priceChangePercentage)

Some random coin IDs that cause exception are 'auxiliam', 'conun', 'paycon-token'. Thanks for your help!

Status Code 403:Forbidden - Solution

For the past few months using the default implementations of the clients in this library has resulted in HTTP status codes of 403. The reason is that CoinGecko now require a user agent specified in the requests.

This library already provides the fix built in you just have to use it!

If we look at the BaseAPIClient in the library we see this at line 43:

//_httpClient.DefaultRequestHeaders.Add("User-Agent", "your bot 0.1");

Each client in this library provides the ability to pass in your own instance of System.Net.HttpClient which is great because you can make one and set a DefaultRequestHeader of User-Agent.

So for example:

//Create an instance of System.Net.HttpClient and add our request header
HttpClient hClient = new HttpClient();
hClient.DefaultRequestHeaders.Add("User-Agent","myApp or whatever");

//Pass our HttpClient instance to the CoinCecko client
ICoinGeckoClient cgClient = new CoinGeckoClient(hClient);

Hopefully this helps anyone getting this problem.

New CoinGecko API Parameters

10 Apr 2019: exchange_ids optional params added for v3/coins/{id}/tickers

10 Apr 2019: coin_ids optional params added for v3/exchanges/{id}/tickers

Market Cap Null hits error. (Example Coin : Statera)

MarketOhlcv.cs Line 9

[JsonProperty("market_cap_rank")]
public long MarketCapRank { get; set; }

It should be
[JsonProperty("market_cap_rank")]
public long**?** MarketCapRank { get; set; }

missing ? to handle null value.

Could not load file or assembly

System.IO.FileNotFoundException: "Could not load file or assembly 'CoinGecko, Version=1.6.0.0, Culture=neutral, PublicKeyToken=null'. The specified file cannot be found."

Nuget - CoinGeckoAsyncApi 1.7.0
I will be glad to answer.

Depth / CostToMoveUp

Hi there,

Thank you for this awesome library.

I have a question regarding the Depth information of each exchange you can see at coingecko https://www.coingecko.com/en/coins/bitcoin#markets.

I was wondering where this information is reflected in the library. I found a property in CoinFullDataById.Tickers.CostToMoveUpUsd which might represent this information? However, this property shows 0.

Any ideas where to find this information?

Thank you

Doubles Vs Decimals

Hi There,

Thanks for the great library, Its has saved me a chunk of code and time.

I just was wondering what the reason for using doubles is rather than decimals, Things like % changes and so on are fine. But there are monetary values like current price that is financial and would lose accuracy being a double?

for example on the MarketData class:

[JsonProperty("current_price")]
public Dictionary<string, double?> CurrentPrice { get; set; }

Thanks!

Calls with 'Demo account API Key' end with 400 Bad request

Looking into the source code I see that when an API key is provided, it automatically uses the PRO endpoint. That is always not correct. The PRO endpoint is for paid subscription tiers only. There is also a demo account API key option (which is limited but free), which still needs to use the normal endpoint. Would you mind if I fixed that? :)

Problem with GetCoinMarkets - should be IReadOnlyList?

I get the exception: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'CoinGecko.Entities.Response.Coins.CoinMarkets' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.

I think it should be public async Task<IReadOnlyList> GetCoinMarkets...

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=50&page=1&sparkline=false&price_change_percentage=1h%2C24h%2C7d%2C14d%2C30d%2C200d%2C1y

The implications could be wide ranging, for example

    [JsonProperty("current_price")]
    public Dictionary<string,double> CurrentPrice { get; set; }

should be double (not Dictionary)

etc, etc

problem when converting "reddit_accounts_active_48h"

There was a problem when I executed method:
_client.CoinsClient.GetHistoryByCoinId(CoinIds.First().Value, "01-12-2018", "false");
I got the answer contains this:

...
"community_data":{"facebook_likes":1223,
"twitter_followers":null,
"reddit_average_posts_48h":0.0,
"reddit_average_comments_48h":0.0,
"reddit_subscribers":132,
"reddit_accounts_active_48h":"12.2916666666667"},
"developer_data":{"forks":null,"stars":null,"subscribers":null,"total_issues":null,"closed_issues":null,"pull_requests_merged":null,"pull_request_contributors":null,"commit_count_4_weeks":null},
"public_interest_stats":{"alexa_rank":2548131,"bing_matches":186000}}

In the class property expects: long,

[JsonProperty("reddit_accounts_active_48h")]
public long? RedditAccountsActive48H { get; set; }

to fix that we must change it to:

public decimal? RedditAccountsActive48H { get; set; }

"reddit_accounts_active_48h":"12.2916666666667"

The goingecko 'atl_change_percentage' in the full data respone is not always a decimal

Hi,

I'm running on an issue on a particular coin at this moment: hundered-finance.
The atl_change_percentage of this coin at the moment of writing is: 1.4209472837214499e+29.
This is caused by the 'all-time-low'-value that is 0 for this coin. I assume that this is not normal and a bug at coin gecko.

When I request all coin date about this coin I get this exception:

---> System.Net.Http.HttpRequestException: Input string '1.4209472837214499e+29' is not a valid decimal.
Path 'market_data.atl_change_percentage.aed', line 1, position 7972.
   at CoinGecko.Clients.BaseApiClient.GetAsync[T](Uri resourceUri)
   at CoinGecko.Clients.CoinsClient.GetAllCoinDataWithId(String id, String localization, Boolean tickers, Boolean marketData, Boolean communityData, Boolean developerData, Boolean sparkline)

So it looks like this kind of value is possible in the atl_change_percentage response and this can't be converted into a decimal for the public Dictionary<string, decimal> AtlChangePercentage.

Error converting value {null} to type 'System.Boolean'.

I am using Version 1.3.1 and I am getting the following error with some of the coins in this function:

CoinGeckoClient.CoinsClient.GetAllCoinDataWithId("loopring")

It happens with these coinId's: blox, dmm-governance, origin-protocol, republic-protocol, havven, ethlend, loopring, decred, ravencoin, status, vechain

System.Net.Http.HttpRequestException: Error converting value {null} to type 'System.Boolean'. Path 'tickers[10].is_anomaly', line 1, position 39366.
at CoinGecko.Clients.BaseApiClient.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoinGecko.Clients.CoinsClient.<GetAllCoinDataWithId>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoinGecko.Clients.CoinsClient.<GetAllCoinDataWithId>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at PriceHistories.Form1.<butCoinMarketCap_Click>d__5.MoveNext()

With CoinId insolar-old it's this error:

System.Net.Http.HttpRequestException: Error converting value {null} to type 'System.DateTimeOffset'. Path 'market_data.last_updated', line 1, position 27053.
at CoinGecko.Clients.BaseApiClient.d__21.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoinGecko.Clients.CoinsClient.<GetAllCoinDataWithId>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoinGecko.Clients.CoinsClient.<GetAllCoinDataWithId>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at PriceHistories.Form1.<butCoinMarketCap_Click>d__5.MoveNext()

Null Conversion Error

Hi,

Another null error when calling: CoinsClient.GetCoinMarkets("usd");

Error converting value {null} to type 'System.DateTimeOffset'. Path '[36].ath_date', line 1, position 27442.

Thanks

Missing "order" parameter in GetCoinMarkets

The "order" parameter of the /coins/markets API query is missing from the query string dictionary in the GetCoinMarkets method of the CoinsClient class.

        public async Task<List<CoinMarkets>> GetCoinMarkets(string vsCurrency, string[] ids, string order, int? perPage,
            int? page, bool sparkline, string priceChangePercentage,string category)
        {
            return await GetAsync<List<CoinMarkets>>(QueryStringService.AppendQueryString(CoinsApiEndPoints.CoinMarkets,
                new Dictionary<string, object>
                {
                    {"vs_currency", vsCurrency},
                    {"ids", string.Join(",", ids)},
                    {"order", order}, <---------   this line is missing
                    {"per_page", perPage},
                    {"page", page},
                    {"sparkline", sparkline},
                    {"price_change_percentage", priceChangePercentage},
                    {"category",category}
                })).ConfigureAwait(false);
        }

GetMarketChartsByCoinId null issue

Hi,

When I try to call:

client.GetMarketChartsByCoinId("bitcoin", "usd", "max");

It fails with a null error because one of the data points for market_caps is null:

[
1491091200000,
null
]

Thanks

Which .Net version am I supposed to target?

Which .Net am I supposed to be targeting? Whether I choose .Net 2, 3 or 4.5 for my project and try to import it via Nuget, I get this: "Could not install package 'CoinGeckoAsyncApi 1.2.6'. You are trying to install this package into a project that targets '.NETFramework,Version=v3.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author"

000259

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.