private static Dictionary <string, Action <CryptoDataPoint, string> > CreateParsingDelegates(PhysicalCurrency currency) { var result = new Dictionary <string, Action <CryptoDataPoint, string> >(ConstantParsingDelegates) { { $"open ({currency.ToString()})", (dataPoint, strValue) => { dataPoint.OpeningPrice = strValue.ParseToDecimal(); } }, { $"high ({currency.ToString()})", (dataPoint, strValue) => { dataPoint.HighestPrice = strValue.ParseToDecimal(); } }, { $"low ({currency.ToString()})", (dataPoint, strValue) => { dataPoint.LowestPrice = strValue.ParseToDecimal(); } }, { $"close ({currency.ToString()})", (dataPoint, strValue) => { dataPoint.ClosingPrice = strValue.ParseToDecimal(); } } }; return(result); }
/// <summary> /// Returns Forex time series for a given currencies pair /// </summary> /// <param name="forexClient"></param> /// <param name="fromCurrency"></param> /// <param name="toCurrency"></param> /// <param name="interval"></param> /// <param name="outputSize"></param> /// <returns></returns> public static async Task <ForexTimeSeries> GetTimeSeriesAsync(this ForexClient forexClient, PhysicalCurrency fromCurrency, PhysicalCurrency toCurrency, Interval interval, OutputSize outputSize = OutputSize.Compact) { var parser = new ForexTimeSeriesParser(interval, fromCurrency, toCurrency); var query = new Dictionary <string, string>() { { ApiQueryConstants.FromSymbolQueryVar, fromCurrency.ToString() }, { ApiQueryConstants.ToSymbolQueryVar, toCurrency.ToString() }, }; var function = interval.ConvertToApiFunction(); if (function == ApiFunction.FX_INTRADAY) { query.Add(ApiQueryConstants.IntervalQueryVar, interval.ConvertToQueryString()); } if (function == ApiFunction.FX_INTRADAY || function == ApiFunction.FX_DAILY) { query.Add(ApiQueryConstants.OutputSizeQueryVar, outputSize.ConvertToQueryString()); } return(await forexClient.RequestApiAsync(parser, function, query)); }
/// <summary> /// Returns exchange rate for a given currencies pair /// </summary> /// <param name="forexClient"></param> /// <param name="fromCurrency"></param> /// <param name="toCurrency"></param> /// <returns></returns> public static async Task <ForexExchangeRate> GetExchangeRateAsync(this ForexClient forexClient, PhysicalCurrency fromCurrency, PhysicalCurrency toCurrency) { var query = new Dictionary <string, string>() { { ApiQueryConstants.FromCurrencyQueryVar, fromCurrency.ToString() }, { ApiQueryConstants.ToCurrencyQueryVar, toCurrency.ToString() } }; return(await forexClient.RequestApiAsync(ExchangeRateParser, ApiFunction.CURRENCY_EXCHANGE_RATE, query)); }
/// <summary> /// Returns cryptocurrency time series for requested currencies pair /// </summary> /// <param name="cryptoClient"></param> /// <param name="fromCurrency"></param> /// <param name="toCurrency"></param> /// <param name="interval"></param> /// <returns></returns> public static async Task <CryptoTimeSeries> GetTimeSeriesAsync(this CryptoClient cryptoClient, DigitalCurrency fromCurrency, PhysicalCurrency toCurrency, Interval interval) { var parser = new CryptoTimeSeriesParser(interval, fromCurrency, toCurrency); var function = interval.ConvertToApiFunction(); var query = new Dictionary <string, string>() { { ApiQueryConstants.SymbolQueryVar, fromCurrency.ToString().Replace("_", "") }, { "market", toCurrency.ToString() } }; return(await cryptoClient.RequestApiAsync(parser, function, query)); }