/// <summary> /// Construct service with dependencies from database and other services. /// </summary> /// <param name="_context"> /// Database context. /// </param> /// <param name="twilioService"> /// Service for accessing SMS. /// </param> /// <param name="alpha"> /// Service for getting prices. /// </param> /// <param name="limitCount"> /// Service for limiting requests made by users. /// </param> public WatchService(IStockDbContext _context, ITwilioService twilioService, AlphaVantage alpha, ILimitCount limitCount) { context = _context; twilio = twilioService; alphaVantage = alpha; limit = limitCount; }
public Task <string> GetLatestQuoteForStock(string ticker, string apiKey) { var alphaVantage = new AlphaVantage(apiKey); var latestStockQuote = alphaVantage.Custom() .Set("symbol", ticker) .Set("function", "GLOBAL_QUOTE") .GetRawDataAsync(); return(latestStockQuote); }
[HttpGet("/GetIndicatorAV/{function}/{symbol}/{days}")] //indicator == function public IActionResult GetIndicatorAV(string function, string symbol, string days) { int numOfDays = Int32.Parse(days); string avResponse = AlphaVantage.CompleteAlphaVantageRequest(function, symbol).Result; decimal avCompositeScore = AlphaVantage.GetCompositeScore(function, avResponse, numOfDays); return(new ContentResult { StatusCode = 200, Content = "Success! Composite Score for function " + function + ": " + avCompositeScore }); }
/// <summary> /// entry point for the command line application. /// creates necessary dependencies and runs the main menu /// </summary> public static void Main() { // create dependencies here, so they can easily be switched out later IDatabase database = new SQLiteDatabase(); using (IWebClient webClient = new WebClient()) { IAPIKeyQuoteFeed quoteFeed = new AlphaVantage(webClient); RunMenu(database, quoteFeed); } }
private static readonly string AlphaVantageAPIKey = ""; //insert yoyr key here static void Main(string[] args) { Console.WriteLine("Insert stock symbol: "); string stkSymbol = Console.ReadLine(); MarketData stock = AlphaVantage.Stock(stkSymbol, AVTimeSeries.Stock_Daily, AVOutputSize.compact, AlphaVantageAPIKey); Console.WriteLine(Environment.NewLine + "Symbol: {0}, Currency: {1}", stock.Symbol, stock.Currency + Environment.NewLine); foreach (var item in stock.Bars) { Console.WriteLine("Date:{0},Open:{1},High:{2},Low:{3},Close:{4},Volume:{5}", item.Key.ToString("dd/MM/yyyy"), item.Value.open, item.Value.high, item.Value.low, item.Value.close, item.Value.volume); } Console.WriteLine(Environment.NewLine + "----------------------------------------" + Environment.NewLine + "Insert cryptocurrency symbol"); string ccSymbol = Console.ReadLine(); MarketData crypto = AlphaVantage.Digital_Currency(ccSymbol, "USD", AVTimeSeries.Digital_Currency_Daily, AlphaVantageAPIKey); Console.WriteLine(Environment.NewLine + "Symbol: {0}, Currency: {1}", crypto.Symbol, crypto.Currency + Environment.NewLine); foreach (var item in stock.Bars) { Console.WriteLine("Date:{0},Open:{1},High:{2},Low:{3},Close:{4},Volume:{5}", item.Key.ToString("dd/MM/yyyy"), item.Value.open, item.Value.high, item.Value.low, item.Value.close, item.Value.volume); } Console.WriteLine(Environment.NewLine + "----------------------------------------" + Environment.NewLine + "Indicator example"); IndicatorData indicator = AlphaVantage.Indicator(new BasicIndicator("DEMA"), "MSFT", AVInterval.Daily, AVSeriesType.close, AlphaVantageAPIKey); Console.WriteLine(Environment.NewLine + "Indicator: {0}, Interval: 30, Symbol: MSFT" + Environment.NewLine, indicator.name); int i = 0; foreach (var item in indicator.Values) { Console.WriteLine("Date:{0}, Value:{1}", item.Key.ToString("dd/MM/yyyy"), item.Value[0].Value); i++; if (i >= 25) { break; } } Console.ReadLine(); }
public QueueManager(string key, string[] symbols, string type) { mutex = new object(); toQuery = new Queue <string>(); toSell = new Queue <string>(); toBuy = new Queue <string>(); IsCompleted = false; Client = new AlphaVantage(key); var @default = Environment.GetEnvironmentVariable("ALPHAVANTAGE_APIKEY") ?? throw new Exception("Enviroment variable 'ALPHAVANTAGE_APIKEY' is not set. This is needed for pricing data."); ApiKey = key == @default ? "Demo" : key; Add(symbols, type); }
//************************************************************************************** /// <summary> /// Loads and asserts that realtime price is retrieved. /// </summary> public static float LoadRealTimePrice() { try { float price = AlphaVantage.RetrieveCurrentPrice(); Console.WriteLine("Realtime price retrieved."); return(price); } catch (System.Exception) { Console.WriteLine("Could not retrieve realtime price."); Console.WriteLine("Enter realtime price manually"); return(float.Parse(Console.ReadLine())); } }
public void GetQuoteTest() { Dictionary <string, string> responses = new Dictionary <string, string>() { { "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=MSFT&apikey=key", @"{ ""Global Quote"": { ""01. symbol"": ""MSFT"", ""02. open"": ""134.8800"", ""03. high"": ""135.7600"", ""04. low"": ""133.5500"", ""05. price"": ""135.5600"", ""06. volume"": ""16321151"", ""07. latest trading day"": ""2019-08-28"", ""08. previous close"": ""135.7400"", ""09. change"": ""-0.1800"", ""10. change percent"": ""-0.1326%"" } }" }, }; string ticker = "MSFT"; Quote expectedQuote = new Quote() { Price = 135.5600m, Date = new DateTime(2019, 8, 28), Symbol = ticker, }; IAPIKeyQuoteFeed quoteFeed; using (WebClientMock webClient = new WebClientMock()) { webClient.SetResponses(responses); quoteFeed = new AlphaVantage(webClient); quoteFeed.SetAPIKey("key"); } Quote quote = quoteFeed.GetQuote(ticker); Assert.AreEqual(expectedQuote, quote); }
private static async Task TryItOut(string apiKey) { var alphaVantage = new AlphaVantage(apiKey); Console.WriteLine("Get Exchange Rate"); var exchangeRate = await alphaVantage.Fx.ExchangeRate("EUR", "GBP") .GetAsync(); Console.WriteLine("Get FX"); var fxData = await alphaVantage.Fx.IntraDay("EUR", "USD") .SetInterval(Interval.FifteenMinutes) .SetOutputSize(OutputSize.Compact) .GetAsync(); Console.WriteLine("Get Stock"); var stockData = await alphaVantage.Stocks.Daily("MSFT") .SetOutputSize(OutputSize.Compact) .GetAsync(); Console.WriteLine("Get Crypto"); var cryptoData = await alphaVantage.Cryptos.Daily("BTC", "GBP") .GetAsync(); Console.WriteLine("Get Technical"); var technicalData = await alphaVantage.Technicals.SimpleMovingAverage("MSFT") .SetInterval(Interval.Daily) .SetTimePeriod(200) .SetSeriesType(SeriesType.Close) .GetAsync(); Console.WriteLine("Get Custom"); var customData = await alphaVantage.Custom() .Set("symbol", "MSFT") .Set("function", "TIME_SERIES_INTRADAY") .Set("interval", "60min") .Set("outputsize", "compact") .GetRawDataAsync(); }
public CompositeScoreResult GetCompositeScoreAV(string symbol) { string adxResponse = AlphaVantage.CompleteAlphaVantageRequest("ADX", symbol).Result; decimal adxCompositeScore = AlphaVantage.GetCompositeScore("ADX", adxResponse, 7); string aroonResponse = AlphaVantage.CompleteAlphaVantageRequest("AROON", symbol).Result; decimal aroonCompositeScore = AlphaVantage.GetCompositeScore("AROON", aroonResponse, 7); string macdResponse = AlphaVantage.CompleteAlphaVantageRequest("MACD", symbol).Result; decimal macdCompositeScore = AlphaVantage.GetCompositeScore("MACD", macdResponse, 7); ShortInterestResult shortResult = new ShortInterestResult(); //FINRA.GetShortInterest(symbol, 7); return(new CompositeScoreResult { Symbol = symbol, DataProviders = "AlphaVantage", ADXComposite = adxCompositeScore, AROONComposite = aroonCompositeScore, MACDComposite = macdCompositeScore, CompositeScoreValue = (adxCompositeScore + aroonCompositeScore + macdCompositeScore + shortResult.ShortInterestCompositeScore) / 4, ShortInterest = shortResult }); }
public WatchServiceShould() { PHONE = "NEW_PHONE"; context = new MockDbContextFactory().CreateDbContext(null); context.Requests.Add(new RequestRecord { Id = 0, RequestId = "abc", TwilioBinding = new Guid().ToString(), Price = 10 }); mockTwilio = new MockTwilioService(context, "", "", ""); mockAlpha = new MockAlphaVantageService(""); mockLimitCount = new LimitCountService(context); mockService = new MockWatchService(context, mockTwilio, mockAlpha, mockLimitCount); mockStock = new Stock { Symbol = "msft", Phone = PHONE, Price = 1.99 }; }
//private double sumOfDividends = 0; /// <summary> /// Retrieves prices for a given stock/fund from the starting date to the present /// </summary> /// <param name="stock"> Stock symbol </param> /// <param name="start"> Start date </param> /// <returns> true if data received successfully, false if not </returns> public override Task <bool> GetQuote(string stock, DateTime start, out StockQuote quote) { MarketData stockData = AlphaVantage.Stock(stock, AVTimeSeries.Stock_Daily, AVOutputSize.full, AlphaVantageAPIKey); if (stockData == null) { quote.date = DateTime.Today; quote.close = 0; quote.highest = 0; return(Task.FromResult(false)); } int tries = 0; while (stockData.Bars.Count == 0 && tries++ <= 5) { Thread.Sleep(10000); stockData = AlphaVantage.Stock(stock, AVTimeSeries.Stock_Daily, AVOutputSize.full, AlphaVantageAPIKey); if (stockData == null) { quote.date = DateTime.Today; quote.close = 0; quote.highest = 0; return(Task.FromResult(false)); } } if (stockData.Bars.Count == 0) { quote.date = DateTime.Today; quote.close = 0; quote.highest = 0; return(Task.FromResult(false)); } DateTime date = DateTime.Today; double close = 0; double highest = 0; bool first = true; foreach (var item in stockData.Bars) { if (first) { date = item.Key; close = item.Value.close; first = false; } if (item.Value.close > highest) { highest = item.Value.close; } //if (item.Value.dividend_amount != 0) // sumOfDividends += item.Value.dividend_amount; if (item.Key < start) { break; } } quote.date = date; quote.close = (decimal)close; quote.highest = (decimal)highest; return(Task.FromResult(true)); }
public AlphaVantageClient(AlphaVantageSettings settings) { _alphaVantage = new AlphaVantage(settings.ApiKey); }
public StockPriceController(AlphaVantage context) { service = context; }
public MockWatchService(IStockDbContext context, ITwilioService twilio, AlphaVantage alpha, ILimitCount limitCount) : base(context, twilio, alpha, limitCount) { }
protected BuilderTestsBase() { ServiceMock = new AlphaVantageServiceMock(); AlphaVantage = new AlphaVantage("apiKey"); AlphaVantage.Configure(x => x.Service = ServiceMock); }