コード例 #1
0
        public static async Task <bool> RefreshAllVals(string source = CryptoCompareName)
        {
            FiatConvert convert = FiatConvert;

            if (convert == null || (DateTime.Now - LastConvertRefresh) > TimeSpan.FromDays(1))
            {
                var fiatResp = await Comms.Get <FiatConvert>(Comms.ConverterApi, "latest?base=USD");

                if (fiatResp.Success && fiatResp.Data != null)
                {
                    LastConvertRefresh = DateTime.Now;
                    convert            = fiatResp.Data;
                }
            }

            if (convert == null)
            {
                return(false);
            }

            FiatConvert refreshed = await RefreshCryptos(convert, source);

            if (refreshed != null)
            {
                FiatConvert = refreshed;
                SaveCache();
            }

            return(refreshed != null);
        }
コード例 #2
0
        public static async Task <double> GetCurrentUsdtoCrypto(string priceSource, string crypto)
        {
            switch (priceSource)
            {
            //case BlockchainName:
            //    var btcResp = await Comms.Get<Dictionary<string, BlockchainResult>>(Comms.BlockChainApi, Comms.BlockChainPriceRoute);
            //    if (btcResp.Success) return btcResp.Data["USD"].Delayed;
            //    break;
            //case CoindeskName:
            //    var deskResp = await Comms.Get<CoindeskResult>(Comms.CoindeskApi, Comms.CoinDeskPriceRoute);
            //    if (deskResp.Success) return deskResp.Data.Bpi["USD"].Rate_float;
            //    break;
            case CoinbaseName:
                var cbResp = await Comms.Get <CoinbaseResult>(Comms.CoinbaseApi, string.Format(Comms.CoinbasePriceRoute, crypto));

                if (cbResp.Success)
                {
                    return(cbResp.Data.Data.Amount);
                }
                break;

            case GDAXName:
                var gdaxResp = await Comms.Get <GDAXResult>(Comms.GdaxApi, string.Format(Comms.GdaxPriceRoute, crypto));

                if (gdaxResp.Success)
                {
                    return(gdaxResp.Data.Price);
                }
                break;

            case CryptoCompareName:
                var compResp = await Comms.Get <CryptoCompareResult>(Comms.CryptoCompareApi, string.Format(Comms.CryptoCompareRoute, crypto));

                if (compResp.Success)
                {
                    return(compResp.Data.USD);
                }
                break;
            }
            return(-1);
        }