Exemplo n.º 1
0
 public CoinService(string[] coinList, string vsCurrency)
 {
     _client     = CoinGeckoClient.Instance;
     _coinList   = coinList;
     _vsCurrency = vsCurrency;
     LastUpdate  = DateTime.Now;
 }
Exemplo n.º 2
0
    public CoinGeckoClientTests(CoinGeckoApiFixture apiFixture, ITestOutputHelper output)
        : base(apiFixture, output)
    {
        _coinsClient = ServiceProvider.GetRequiredService <ICoinGeckoClient>();

        _quoteCurrencyId = Constants.UsdCoin;
        _asOf            = DateTime.Today.AddDays(-5);
    }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
    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);
    }
Exemplo n.º 5
0
        /// <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();
        }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        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");
        }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 11
0
 public IndexesClientTest()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 12
0
 public ContractClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 13
0
 public GlobalClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 14
0
 public StatusUpdatesClientTest()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 15
0
 public EventsClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 16
0
 public SimpleClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 17
0
 public DerivativesClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 18
0
 public PingClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 19
0
        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;
                }
            }
        }
Exemplo n.º 20
0
 public ExchangeRatesClientTests()
 {
     _client = CoinGeckoClient.Instance;
 }
Exemplo n.º 21
0
 public Service(ICoinGeckoClient coinGeckoClient)
 {
     _coinGeckoClient = coinGeckoClient;
 }