示例#1
0
        public async Task <PredictionModel> GetPriceNowAsync(CryptoCurrencyType cryptoCurrencyType,
                                                             string fiatCurrencyCode = "USD")
        {
            using var httpClient = new HttpClient();
            string symbol     = GetSymbol(cryptoCurrencyType, fiatCurrencyCode);
            string requestUrl = string.Format(BinanceAPIEndpoint, symbol);

            var response = await httpClient.GetAsync(requestUrl);

            var responseText = await response.Content.ReadAsStringAsync();

            dynamic responseObj = JsonConvert.DeserializeObject(responseText);

            double price = responseObj.price;

            return(new PredictionModel
            {
                Author = this,
                CryptoCurrencyCode = cryptoCurrencyType.ToString(),
                AveragePrice = price,
                ChangePercent = 0,
                Date = DateTime.Now,
                FiatCurrencyCode = fiatCurrencyCode,
                IsFuture = false
            });
        }
 protected override string GetScrapePattern(CryptoCurrencyType cryptoCurrencyType)
 {
     return(cryptoCurrencyType switch
     {
         CryptoCurrencyType.ETH => @$ "<tr class=" "w0" " data-key=" "0" "><td class=" "w0" " data-col-seq=" "0" ">{TommorowFormattedString}</td><td class=" "w0" " data-col-seq=" "1" "><span class=" "mobileshow" ">Price: </span><i class=" "fa fa-usd" " aria-hidden=" "true" "></i>(.*?)</td>",
         CryptoCurrencyType.DOT => @$ "<tr class=" "w0" " data-key=" "0" "><td class=" "w0" " data-col-seq=" "0" ">{TommorowFormattedString}</td><td class=" "w0" " data-col-seq=" "1" "><span class=" "mobileshow" ">Price: </span><i class=" "fa fa-usd" " aria-hidden=" "true" "></i>(.*?)</td>",
         CryptoCurrencyType.BTC => @$ "<tr class=" "w0" " data-key=" "0" "><td class=" "w0" " data-col-seq=" "0" ">{TommorowFormattedString}</td><td class=" "w0" " data-col-seq=" "1" "><span class=" "mobileshow" ">Price: </span><i class=" "fa fa-usd" " aria-hidden=" "true" "></i>(.*?)</td>",
         _ => throw new Exception("Unknown Crypto Currency type")
     });
 public virtual async Task <PredictionModel> GetTommorowPredictionAsync(CryptoCurrencyType currencyType)
 {
     return(currencyType switch
     {
         CryptoCurrencyType.ETH => await GetTommorowEthPredictionAsync(),
         CryptoCurrencyType.BTC => await GetTommorowBtcPredictionAsync(),
         CryptoCurrencyType.DOT => await GetTommorowDotPredictionAsync(),
         _ => throw new Exception("Unknown Crypto Currency type")
     });
示例#4
0
 protected override string GetScrapePattern(CryptoCurrencyType cryptoCurrencyType)
 {
     return(cryptoCurrencyType switch
     {
         CryptoCurrencyType.ETH => @"<td class=""currency"">\s+1 day\s+<\/td>\s+<td class=\""(price up|price down)\"">\s+\$(.*?)<\/td>\s+<td class=\""(price up|price down)\"">\s+(.*?)\s+<\/td>",
         CryptoCurrencyType.DOT => @"<td class=""currency"">\s+1 day\s+<\/td>\s+<td class=\""(price up|price down)\"">\s+\$(.*?)<\/td>\s+<td class=\""(price up|price down)\"">\s+(.*?)\s+<\/td>",
         CryptoCurrencyType.BTC => @"<td class=""currency"">\s+1 day\s+<\/td>\s+<td class=\""(price up|price down)\"">\s+\$(.*?)<\/td>\s+<td class=\""(price up|price down)\"">\s+(.*?)\s+<\/td>",
         _ => throw new Exception("Unknown cyptocurrency type")
     });
示例#5
0
        private string GetSymbol(CryptoCurrencyType cryptoCurrencyType, string fiatCurrencyCode)
        {
            var postfix = fiatCurrencyCode.ToUpper() switch
            {
                "USD" => "USDT",
                "EUR" => "EUR",
                _ => fiatCurrencyCode
            };

            return($"{cryptoCurrencyType}{postfix}");
        }
    }
 public static string GetCryptoCurrencyNameByType(CryptoCurrencyType cryptoCurrencyType)
 => typeToNameMapping[cryptoCurrencyType];
示例#7
0
 protected override string GetScrapePattern(CryptoCurrencyType cryptoCurrencyType)
 {
     return cryptoCurrencyType switch
     {
         CryptoCurrencyType.ETH => @$"<td style=\""[^>]*\"">{TommorowFormattedString}<\/td>\s+<td style=\""[^>]*\"">.*?<\/td>\s+<td style=\""[^>]*\"">.(.*?)</td>",