static async Task Main(string[] args) { var config = CreateConfiguration(); OpenLogger(config); string apiKey = File.ReadAllText(config["finnhubkeypath"]); var client = new FinnhubClient(apiKey); var dbContext = new StockContext(); var exchangeConnector = new ExchangeConnector(client, dbContext); //await exchangeConnector.GetExchanges(); var stockConnector = new StockConnector(client, dbContext); //await stockConnector.GetSymbols("AX"); var fileConnector = new FileConnector(config["filepath"] + "20200428splits.csv", "Splits"); fileConnector.ImportToStockDB(dbContext); CloseLogger(); }
public async Task Stock(CommandContext ctx) { try { if (ctx.Message.Author.Username == "AlperenT") { await ctx.Channel.SendMessageAsync("lmao"); return; } string[] args = ctx.Message.Content.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); Console.WriteLine(ctx.Message.Author.Username + ": " + ctx.Message.Content); int pageSize = 300; var finn = new FinnhubClient(Bot.finnKey); if (args.Length > 1 && args[1].Length < 5) { var quote = await finn.Stock.GetQuote(args[1]); var company = await finn.Stock.GetCompany(args[1]); string message = args[1] + " - " + company.Name + " - " + company.Weburl + "\n" + "Current Price: " + quote.Current.ToString("C") + " - High: " + quote.High.ToString("C") + " - Low: " + quote.Current.ToString("C"); await ctx.Channel.SendMessageAsync(message); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
static async Task TryGetRawData(FinnhubClient client) { Console.WriteLine(); Console.WriteLine("Raw Data"); var rawData = await client.GetRawDataAsync("stock/profile", new Field(FieldKeys.Symbol, "AAPL")); Console.WriteLine($"Success: Raw data has {rawData.Length} characters."); }
static async Task TryTechnicalAnalysis(FinnhubClient client) { Console.WriteLine(); Console.WriteLine("Technical Analysis"); var supportResistance = await client.TechnicalAnalysis.GetSupportResistance("AAPL", Resolution.Day); Console.WriteLine($"Success: {supportResistance.Levels.Count} support/resistance levels."); }
static async Task TryStocks(FinnhubClient client) { Console.WriteLine("Stock"); var company = await client.Stock.GetCompany("AAPL"); Console.WriteLine($"Success: Retrieved company {company.Name}."); var company2 = await client.Stock.GetCompanyByIsin("US0378331005"); // AAPL Console.WriteLine($"Success: Retrieved company {company.Name}."); var company3 = await client.Stock.GetCompanyByCusip("037833100"); // AAPL Console.WriteLine($"Success: Retrieved company {company.Name}."); var compensation = await client.Stock.GetCompensation("AAPL"); Console.WriteLine($"Success: Retrieved compensation for {compensation.Name} ({compensation.CompanyName})."); var recommendations = await client.Stock.GetRecommendationTrends("AAPL"); Console.WriteLine($"Success: Retrieved {recommendations.Length} recommendations."); var priceTarget = await client.Stock.GetPriceTarget("AAPL"); Console.WriteLine($"Success: Retrieved price target for {priceTarget.Symbol}."); var peers = await client.Stock.GetPeers("AAPL"); Console.WriteLine($"Success: Retrieved {peers.Length} peers."); var earnings = await client.Stock.GetEarnings("AAPL"); Console.WriteLine($"Success: Retrieved {earnings.Length} earnings entries."); var exchanges = await client.Stock.GetExchanges(); Console.WriteLine($"Success: {exchanges.Length} stock exchanges found."); var symbols = await client.Stock.GetSymbols("US"); Console.WriteLine($"Success: Stock exchange has {symbols.Length} symbols."); var quote = await client.Stock.GetQuote("AAPL"); Console.WriteLine($"Success: Current AAPL quote price is {quote.Current}."); var candles = await client.Stock.GetCandles("AAPL", Resolution.Day, 10); Console.WriteLine($"Success: Retrieved {candles.Length} candles."); }
public async Task GetCompanyNews() { var httpClientTester = new HttpClientTester() .SetResponseContent(DataLoader.LoadAlternativeData("news")); var client = new FinnhubClient(httpClientTester.Client, "APIKey"); var news = await client.AlternativeData.GetCompanyNews("AAPL"); news.Should().HaveCount(3); news[0].Category.Should().Be("technology"); httpClientTester.RequestMessage.RequestUri .AbsoluteUri.Should().Be("https://finnhub.io/api/v1/news/AAPL?token=APIKey"); }
public async Task SupportResistance() { var httpClientTester = new HttpClientTester() .SetResponseContent(DataLoader.LoadTechnicalAnalysis("supportResistance")); var client = new FinnhubClient(httpClientTester.Client, "APIKey"); var supportResistance = await client.TechnicalAnalysis.GetSupportResistance("AAPL", Model.Resolution.Day); supportResistance.Should().NotBeNull(); supportResistance.Levels.Count.Should().Be(6); httpClientTester.RequestMessage.RequestUri .AbsoluteUri.Should().Be("https://finnhub.io/api/v1//scan/support-resistance?token=APIKey&symbol=AAPL&resolution=D"); }
static async Task Run() { var apiKey = Environment.GetEnvironmentVariable("FinnhubApiKey", EnvironmentVariableTarget.User); var client = new FinnhubClient(apiKey); await TryStocks(client); await TryForex(client); await TryCrypto(client); await TryTechnicalAnalysis(client); await TryAlternativeData(client); await TryGetRawData(client); Console.WriteLine(); Console.WriteLine("Done"); Console.ReadKey(); }
public async Task Exchanges() { var httpClientTester = new HttpClientTester() .SetResponseContent(DataLoader.LoadCrypto("exchanges")); var client = new FinnhubClient(httpClientTester.Client, "APIKey"); var exchanges = await client.Crypto.GetExchanges(); exchanges.Should().NotBeNull(); exchanges.Should().HaveCount(12); exchanges[11].Should().Be("HUOBI"); httpClientTester.RequestMessage.RequestUri .AbsoluteUri.Should().Be("https://finnhub.io/api/v1/crypto/exchange?token=APIKey"); }
static async Task TryForex(FinnhubClient client) { Console.WriteLine(); Console.WriteLine("Forex"); var exchanges = await client.Forex.GetExchanges(); Console.WriteLine($"Success: {exchanges.Length} forex exchanges found."); var symbols = await client.Forex.GetSymbols("fxcm"); Console.WriteLine($"Success: Forex exchange has {symbols.Length} symbols."); var candles = await client.Forex.GetCandles(symbols.First().CandleSymbol, Resolution.Day, 10); Console.WriteLine($"Success: Retrieved {candles.Length} candles."); }
static async Task TryAlternativeData(FinnhubClient client) { Console.WriteLine(); Console.WriteLine("Alternative Data"); var news = await client.AlternativeData.GetNews(NewsCategory.Forex); Console.WriteLine($"Success: {news.Length} Forex news stories."); var appleNews = await client.AlternativeData.GetCompanyNews("AAPL"); Console.WriteLine($"Success: {appleNews.Length} Company news stories."); var newsSentiment = await client.AlternativeData.GetNewsSentiment("AAPL"); Console.WriteLine($"Success: News sentiment score is {newsSentiment.CompanyNewsScore}."); }
public async Task Symbols() { var httpClientTester = new HttpClientTester() .SetResponseContent(DataLoader.LoadCrypto("symbols")); var client = new FinnhubClient(httpClientTester.Client, "APIKey"); var symbols = await client.Crypto.GetSymbols("binance"); symbols.Should().NotBeNull(); symbols.Should().HaveCount(3); symbols[2].Description.Should().Be("Binance BNBBTC"); symbols[2].DisplaySymbol.Should().Be("BNB/BTC"); symbols[2].CandleSymbol.Should().Be("BINANCE:BNBBTC"); httpClientTester.RequestMessage.RequestUri .AbsoluteUri.Should().Be("https://finnhub.io/api/v1/crypto/symbol?token=APIKey&exchange=binance"); }