public async static Task <Queue <decimal> > GetCCI(string symbol) { var avClient = new AlphaVantageCoreClient(); var ret = new Queue <decimal>(5); var query = GetDefaultQueryDic(symbol); query.Remove("series_type"); // not needed JObject cciObj = await avClient.RequestApiAsync(API_KEY_ALPHA_VANTAGE, ApiFunction.CCI, query); //error parsing if (!cciObj.ContainsKey("Meta Data")) { throw new AlphaVantage.Net.Core.Exceptions.AlphaVantageException($"Error parsing json object. Got: {cciObj.ToString()}"); } JToken cciDataObj = cciObj["Technical Analysis: CCI"]; foreach (var timeCCI in cciDataObj.Take(5)) { decimal wow = timeCCI.First.First.First.Value <decimal>(); ret.Enqueue(wow); } return(ret); }
public AlphaVantageTechIndicatorsClient(string apiKey) { if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException(nameof(apiKey)); } _apiKey = apiKey; _coreClient = new AlphaVantageCoreClient(); }
public AlphaVantageStocksClient(string apiKey, TimeSpan?requestTimeout = null) { if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException(nameof(apiKey)); } _apiKey = apiKey; _coreClient = new AlphaVantageCoreClient(timeout: requestTimeout); _parser = new DataParser(); }
public AlphaVantageStocksClient(string apiKey) { if (string.IsNullOrWhiteSpace(apiKey)) { throw new ArgumentNullException(nameof(apiKey)); } _apiKey = apiKey; _coreClient = new AlphaVantageCoreClient(); _parser = new StockDataParser(); }
public async Task CorrectRequestTest() { var function = ApiFunction.TIME_SERIES_INTRADAY; var symbol = "AAPL"; var interval = "15min"; var query = new Dictionary <string, string>() { { nameof(symbol), symbol }, { nameof(interval), interval } }; var client = new AlphaVantageCoreClient(); var response = await client.RequestApiAsync(ApiKey, function, query); Assert.NotNull(response); Assert.True(response.ContainsKey("Time Series (15min)")); }
public async Task BadRequestTest() { var function = ApiFunction.TIME_SERIES_INTRADAY; var symbol = "wrong_symbol"; // Bad request! No such symbol exist var interval = "15min"; var query = new Dictionary <string, string>() { { nameof(symbol), symbol }, { nameof(interval), interval } }; var client = new AlphaVantageCoreClient(); await Assert.ThrowsAsync <AlphaVantageException>(async() => { await client.RequestApiAsync(ApiKey, function, query); }); }
public async Task ValidationErrorTest() { var function = ApiFunction.TIME_SERIES_INTRADAY; var symbol = "wrong_symbol"; // Bad request! No such symbol exist var interval = "15min"; var query = new Dictionary <string, string>() { { nameof(symbol), symbol }, { nameof(interval), interval } }; var client = new AlphaVantageCoreClient(new TestValidator()); var exception = await Assert.ThrowsAsync <AlphaVantageException>(async() => { await client.RequestApiAsync(ApiKey, function, query); }); Assert.Equal(TestValidator.ErrorMsg, exception.Message); }
public async static Task <Queue <decimal> > GetRSI(string symbol) { var avClient = new AlphaVantageCoreClient(); var ret = new Queue <decimal>(5); var query = GetDefaultQueryDic(symbol); JObject rsiObj = await avClient.RequestApiAsync(API_KEY_ALPHA_VANTAGE, ApiFunction.RSI, query); //error parsing if (!rsiObj.ContainsKey("Meta Data")) { throw new AlphaVantage.Net.Core.Exceptions.AlphaVantageException($"Error parsing json object. Got: {rsiObj.ToString()}"); } JToken rsiDataObj = rsiObj["Technical Analysis: RSI"]; foreach (var timeRsi in rsiDataObj.Take(5)) { decimal wow = timeRsi.First.First.First.Value <decimal>(); ret.Enqueue(wow); } return(ret); }
public async Task <StockSymbol> UpdateStockSymbolDataAsync(StockSymbol Symbol) { //String baseUrl = null; String apiKey = null; try { //baseUrl = _config.Configuration["AlphavantageBaseUrl"]; apiKey = _config.Configuration["AlphavantageApiKey"]; } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } if (String.IsNullOrWhiteSpace(apiKey)) { throw new Exception("AlphavantageApiKey null or empty!"); } AlphaVantageCoreClient client = new AlphaVantageCoreClient(); Dictionary <string, string> query = new Dictionary <string, string>() { { "symbol", Symbol.Symbol }, { "interval", "5min" }, { "outputsize", "full" } }; JObject result = await client.RequestApiAsync(apiKey, ApiFunction.TIME_SERIES_INTRADAY, query); DateTime lastRefresh = Symbol.LastRefresh ?? DateTime.MinValue; string timeZoneString = (string)result["Meta Data"]["6. Time Zone"]; //TODO: Move elsewhere if ("US/Eastern".Equals(timeZoneString)) { timeZoneString = "US Eastern Standard Time"; } TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneString); Symbol.Values = new List <StockValue>(); List <Task> waitingTasks = new List <Task>(); foreach (JObject timeSerie in result["Time Series (5min)"].Values()) { JProperty prop = (JProperty)timeSerie.Parent; String timestampProp = prop.Name; DateTime localTimeStamp = DateTime.ParseExact(timestampProp, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); DateTime utcTimeStamp = TimeZoneInfo.ConvertTimeToUtc(localTimeStamp, timeZone); if (utcTimeStamp < lastRefresh) { continue; } StockValue value = new StockValue() { TimeStamp = utcTimeStamp, Open = Decimal.Parse(timeSerie.Value <string>("1. open")), High = Decimal.Parse(timeSerie.Value <string>("2. high")), Low = Decimal.Parse(timeSerie.Value <string>("3. low")), Close = Decimal.Parse(timeSerie.Value <string>("4. close")), Volume = Decimal.Parse(timeSerie.Value <string>("5. volume")), ParentId = Symbol.Id }; Symbol.Values.Add(value); waitingTasks.Add(_repository.AddStockSymbolDataAsync(value)); if (waitingTasks.Count > 4) { int i = Task.WaitAny(waitingTasks.ToArray()); waitingTasks.RemoveAt(i); } } Task.WaitAll(waitingTasks.ToArray()); waitingTasks.Clear(); DateTime localRefresh = DateTime.ParseExact((string)result["Meta Data"]["3. Last Refreshed"], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); Symbol.LastRefresh = TimeZoneInfo.ConvertTimeToUtc(localRefresh, timeZone); return(Symbol); }