Пример #1
0
        private async Task GetDexEosContractsCostAsync(TokenCostServiceSettings settings, decimal eosToUsd, List <TokenCost> tokenCosts, CancellationToken token)
        {
            var client  = new HttpClient();
            var message = await client.GetAsync($"{settings.DexEosApi}/token", token)
                          .ConfigureAwait(false);

            message.EnsureSuccessStatusCode();

            var json = await message.Content.ReadAsStringAsync()
                       .ConfigureAwait(false);

            var typedResult = JsonConvert.DeserializeObject <DexEosToken.RootObject[]>(json);

            foreach (var item in typedResult)
            {
                var tokenCost = new TokenCost
                {
                    Contract  = BaseName.StringToName(item.code),
                    TokenName = item.symbol.ToUpper(),
                    EosRate   = item.summary.last_price,
                    UsdRate   = item.summary.last_price * eosToUsd
                };

                if (tokenCosts.Any(t => t.Contract == tokenCost.Contract && t.TokenName.Equals(tokenCost.TokenName)))
                {
                    continue;
                }

                tokenCosts.Add(tokenCost);
            }
        }
Пример #2
0
        private async Task GetNewDexContractsCostAsync(TokenCostServiceSettings settings, decimal eosToUsd, List <TokenCost> tokenCosts, CancellationToken token)
        {
            var client  = new HttpClient();
            var message = await client.GetAsync($"{settings.NewDexApi}/tickers", token)
                          .ConfigureAwait(false);

            message.EnsureSuccessStatusCode();

            var json = await message.Content.ReadAsStringAsync()
                       .ConfigureAwait(false);

            var typedResult = JsonConvert.DeserializeObject <NewDexToken.RootObject>(json);

            foreach (var item in typedResult.data)
            {
                if (!item.symbol.EndsWith("-eos"))
                {
                    continue;
                }

                var tokenCost = new TokenCost
                {
                    Contract  = BaseName.StringToName(item.contract),
                    TokenName = item.currency.ToUpper(),
                    EosRate   = item.last,
                    UsdRate   = item.last * eosToUsd
                };

                if (tokenCosts.Any(t => t.Contract == tokenCost.Contract && t.TokenName.Equals(tokenCost.TokenName)))
                {
                    continue;
                }

                tokenCosts.Add(tokenCost);
            }
        }