public CoinService(string[] coinList, string vsCurrency) { _client = CoinGeckoClient.Instance; _coinList = coinList; _vsCurrency = vsCurrency; LastUpdate = DateTime.Now; }
public CoinGeckoClientTests(CoinGeckoApiFixture apiFixture, ITestOutputHelper output) : base(apiFixture, output) { _coinsClient = ServiceProvider.GetRequiredService <ICoinGeckoClient>(); _quoteCurrencyId = Constants.UsdCoin; _asOf = DateTime.Today.AddDays(-5); }
public CoinRepository(ICoinGeckoClient coinGeckoClient, IMemoryCache memoryCache, ICoinLogger coinLogger) { coinLogger.Log($"Initializing {nameof(CoinRepository)}."); _coinGeckoClient = coinGeckoClient; _memoryCache = memoryCache; _coinLogger = coinLogger; _coins = CoinData.GetAllCoins().Where(x => x.MarketCapRank > 0).GroupBy(x => x.Symbol).Select(x => x.OrderBy(y => y.MarketCapRank).First()).ToList(); _coinBySymbolLookup = _coins.ToDictionary(x => x.Symbol, x => x); }
public CoinGeckoClientTests(ITestOutputHelper output) { _simpleClient = Substitute.For <ISimpleClient>(); _coinsClient = Substitute.For <ICoinsClient>(); _memoryCache = Substitute.For <IMemoryCache>(); _mockCreator = new MockCreator(output); _coinGeckoClient = new CoinGeckoClient(_memoryCache, _coinsClient, _simpleClient); }
/// <summary> /// Enables the API. /// </summary> public void Enable() { this.client = new CoinGeckoClient(); if (this.assetUpdateWorker.IsAlive) { throw new Exception("Already running!"); } this.assetUpdateWorker = new Thread(this.AssetUpdateWorker); this.assetUpdateWorker.Start(); }
void GetusdValue() { _UsdValue = 1; ICoinGeckoClient client = CoinGeckoClient.Instance; var coinList = client.CoinsClient.GetCoinList().Result; var coin = coinList.Where(a => a.Symbol.ToLower() == Asset.ToLower()).FirstOrDefault(); if (coin != null) { var v = client.SimpleClient.GetSimplePrice(new string[] { coin.Id }, new string[] { "usd" }).Result; _UsdValue = (decimal)v[coin.Id]["usd"].Value; } }
void GetHistories() { ICoinGeckoClient client = CoinGeckoClient.Instance; var coinList = client.CoinsClient.GetCoinList().Result; this.InvokeIfRequired(() => trades.SortBy(a => a.Timestamp)); DateTime from = trades.First().Timestamp.AddHours(-5); foreach (Trade t in trades) { GetHistory(client, from, coinList, t.BoughtAsset); GetHistory(client, from, coinList, t.SoldAsset); } this.InvokeIfRequired(() => this.Text = "loaded"); }
void GetHistory(ICoinGeckoClient client, DateTime from, IReadOnlyList <CoinList> coinList, string asset) { if (asset != null) { var coin = coinList.Where(a => a.Symbol.ToLower() == asset.ToLower()).FirstOrDefault(); if (!coinHistories.ContainsKey(asset)) { coinHistories[asset] = client.CoinsClient.GetMarketChartRangeByCoinId(coin.Id, "usd", Unix(from).ToString(), Unix(DateTime.Now).ToString()).Result; this.InvokeIfRequired(() => { DoScope1(asset, coinHistories[asset]); DoScope2(asset, coinHistories[asset]); DoScope3(asset, coinHistories[asset]); }); } } }
public CachedHttpClientHandlerTests() { var serviceCollection = new ServiceCollection(); _throttleDelay = 100; var config = new CoinGeckoApiConfiguration { BaseUrl = CoinGeckoApiFixture.CoinGeckoBaseUrl, ThrottleDelayPerSecond = _throttleDelay }; serviceCollection.AddCoinGeckoClient(config); serviceCollection.AddMemoryCache(); serviceCollection.AddSingleton(config); var serviceProvider = serviceCollection.BuildServiceProvider(); _client = serviceProvider.GetService <ICoinGeckoClient>() !; }
public FundService( IOptions <AppSettings> appSettings, IInvictusClient invictusClient, IEthplorerClient ethplorerClient, ICoinGeckoClient coinGeckoClient, IGraphClient graphClient, ICurrencyConverter currencyConverter, IFundPerformanceRepository fundPerformanceRepository, ITransactionRepository transactionRepository, IOperationRepository operationRepository, IHttpContextAccessor httpContextAccessor, IScopedCancellationToken scopedCancellationToken) : base(appSettings, currencyConverter, transactionRepository, operationRepository, httpContextAccessor, scopedCancellationToken) { this.invictusClient = invictusClient; this.ethplorerClient = ethplorerClient; this.coinGeckoClient = coinGeckoClient; this.graphClient = graphClient; this.fundPerformanceRepository = fundPerformanceRepository; }
public IndexesClientTest() { _client = CoinGeckoClient.Instance; }
public ContractClientTests() { _client = CoinGeckoClient.Instance; }
public GlobalClientTests() { _client = CoinGeckoClient.Instance; }
public StatusUpdatesClientTest() { _client = CoinGeckoClient.Instance; }
public EventsClientTests() { _client = CoinGeckoClient.Instance; }
public SimpleClientTests() { _client = CoinGeckoClient.Instance; }
public DerivativesClientTests() { _client = CoinGeckoClient.Instance; }
public PingClientTests() { _client = CoinGeckoClient.Instance; }
private async Task SyncPerformanceAsync( ICoinGeckoClient coinGeckoClient, IInvictusClient invictusClient, IFundPerformanceRepository repository, IFundSettings fund, DateTimeOffset startDate, DateTimeOffset endDate, CancellationToken cancellationToken) { var start = new DateTimeOffset(startDate.Date, TimeSpan.Zero); while (!cancellationToken.IsCancellationRequested) { if (start >= DateTimeOffset.UtcNow) { break; } var end = start.AddDays(MaxDays).Round(); Console.WriteLine($"[{fund.ContractAddress}] Processing Batch: {start} -> {end}"); var invictusNavs = await invictusClient .ListPerformanceAsync(fund.Symbol, start, end) .ToListAsync(cancellationToken); if (invictusNavs.Any()) { var marketPrices = fund.Tradable ? await coinGeckoClient .ListCoinPerformanceAsync(fund.CoinGeckoId, start.AddDays(-1), end.AddDays(1)) .ToListAsync(cancellationToken) : new List <CoinGeckoCoinPerformance>(); foreach (var nav in invictusNavs) { var closestPrice = marketPrices .OrderBy(i => Math.Abs(i.Date.ToUnixTimeSeconds() - new DateTimeOffset(nav.Date, TimeSpan.Zero).ToUnixTimeSeconds())) .FirstOrDefault(); var perf = new DataFundPerformance() { Address = fund.ContractAddress, Date = nav.Date, Nav = nav.NetAssetValuePerToken, Price = closestPrice?.Price ?? -1, MarketCap = closestPrice?.MarketCap ?? -1, Volume = closestPrice?.Volume ?? -1 }; await repository.UploadItemsAsync(perf); } } Console.WriteLine($"[{fund.ContractAddress}] Finished Batch: {start} -> {end}"); if (end >= endDate) { break; } else { start = end; } } }
public ExchangeRatesClientTests() { _client = CoinGeckoClient.Instance; }
public Service(ICoinGeckoClient coinGeckoClient) { _coinGeckoClient = coinGeckoClient; }