File tree Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Expand file tree Collapse file tree 3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ public enum PriceServiceNames
1515 MempoolSpace ,
1616 Bitfinex ,
1717 Coindesk ,
18+ CoinGecko ,
1819 }
1920 public enum BalanceServiceNames
2021 {
Original file line number Diff line number Diff line change 1+ // WatchOnlyBitcoinWallet
2+ // Copyright (c) 2016 Coding Enthusiast
3+ // Distributed under the MIT software license, see the accompanying
4+ // file LICENCE or http://www.opensource.org/licenses/mit-license.php.
5+
6+ using Newtonsoft . Json . Linq ;
7+ using System . Diagnostics ;
8+ using System . Threading . Tasks ;
9+
10+ namespace WatchOnlyBitcoinWallet . Services . PriceServices
11+ {
12+ public class CoinGecko : ApiBase , IPriceApi
13+ {
14+ public async Task < Response < decimal > > UpdatePriceAsync ( )
15+ {
16+ Response < decimal > resp = new ( ) ;
17+ Response < JObject > apiResp = await SendApiRequestAsync ( "https://api.coingecko.com/api/v3/exchange_rates" ) ;
18+ if ( ! apiResp . IsSuccess )
19+ {
20+ resp . Error = apiResp . Error ;
21+ return resp ;
22+ }
23+ Debug . Assert ( apiResp . Result is not null ) ;
24+
25+ JToken ? x = apiResp . Result [ "rates" ] ? [ "usd" ] ? [ "value" ] ;
26+ if ( x is null )
27+ {
28+ resp . Error = "JSON in API response doesn't include the params " +
29+ "(API may have changed, please report this as a bug)." ;
30+ return resp ;
31+ }
32+
33+ resp . Result = ( decimal ) x ;
34+ return resp ;
35+ }
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ private async void UpdatePrice()
6565 PriceServiceNames . MempoolSpace => new MempoolSpace ( ) ,
6666 PriceServiceNames . Bitfinex => new Bitfinex ( ) ,
6767 PriceServiceNames . Coindesk => new Coindesk ( ) ,
68+ PriceServiceNames . CoinGecko => new CoinGecko ( ) ,
6869 _ => throw new NotImplementedException ( ) ,
6970 } ;
7071
You can’t perform that action at this time.
0 commit comments