示例#1
0
        public async Task <GlobalQuoteSaida> ObterCotacaoPorSiglaAtivo(string sigla)
        {
            if (string.IsNullOrEmpty(sigla) || string.IsNullOrEmpty(_configHelper.ApiAlphaVantageConfig.UrlGlobalQuotes) || string.IsNullOrEmpty(_configHelper.ApiAlphaVantageConfig.Key))
            {
                return(null);
            }

            try
            {
                using (var client = new HttpClient {
                    Timeout = new TimeSpan(0, 0, 15)
                })
                {
                    var response = await client.GetAsync(string.Format(_configHelper.ApiAlphaVantageConfig.UrlGlobalQuotes, sigla.ToUpper(), _configHelper.ApiAlphaVantageConfig.Key));

                    var globalQuote = GlobalQuote.Obter(response.Content.ReadAsStringAsync().Result);

                    return(globalQuote.Params != null
                        ? new GlobalQuoteSaida(globalQuote.Params)
                        : null);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Erro ao utilizar a query \"GLOBAL_QUOTE\" ({string.Format(_configHelper.ApiAlphaVantageConfig.UrlGlobalQuotes, sigla, _configHelper.ApiAlphaVantageConfig.Key)}) para a sigla {sigla} da API da Alpha Vantage.");

                return(null);
            }
        }
示例#2
0
        private AlphaVantageSingleQuote MapData(Dictionary <string, string> columnHeaderValueMap)
        {
            string   symbol        = columnHeaderValueMap[nameof(symbol)];
            decimal  high          = decimal.Parse(columnHeaderValueMap[nameof(high)]);
            decimal  low           = decimal.Parse(columnHeaderValueMap[nameof(low)]);
            decimal  open          = decimal.Parse(columnHeaderValueMap[nameof(open)]);
            decimal  previousClose = decimal.Parse(columnHeaderValueMap[nameof(previousClose)]);
            long     volume        = long.Parse(columnHeaderValueMap[nameof(volume)]);
            decimal  change        = decimal.Parse(columnHeaderValueMap[nameof(change)]);
            string   changePercent = columnHeaderValueMap[nameof(changePercent)];
            decimal  price         = decimal.Parse(columnHeaderValueMap[nameof(price)]);
            DateTime latestDay     = DateTime.Parse(columnHeaderValueMap[nameof(latestDay)]);

            var globalQuote = new GlobalQuote
            {
                Symbol         = symbol,
                High           = high,
                Low            = low,
                Open           = open,
                PreviousClose  = previousClose,
                Volume         = volume,
                Change         = change,
                Price          = price,
                ChangePercent  = changePercent,
                LastTradingDay = latestDay,
                LastUpdated    = DateTime.UtcNow
            };

            return(new AlphaVantageSingleQuote {
                Data = globalQuote
            });
        }
示例#3
0
        public static GlobalQuote getXigniteData(string isin)
        {
            var         bond = new XigniteGlobalQuotes(XigniteKey);
            GlobalQuote data = bond.GetGlobalDelayedQuote(isin, IdentifierTypes.ISIN);

            return(data);
        }
示例#4
0
        public static void CheckStocks()

        {
            List <StockInput> data = AccessFiles.getStockInput();

            foreach (StockInput company in data)
            {
                GlobalQuote mytempQuery = AccessXIgnite.getXigniteData(company.mic, company.ticker);
                if (mytempQuery == null)
                {
                    Console.WriteLine("{0},{1} not working, trying isin", company.mic, company.ticker);
                    mytempQuery = AccessXIgnite.getXigniteData(company.isin);
                    if (mytempQuery.Outcome != "Success")
                    {
                        Console.WriteLine("No isin");
                        company.foundwithisin = false;
                    }
                    else
                    {
                        Console.WriteLine("{0},{1} working with isin on {2}", company.mic, company.ticker, mytempQuery.Security.Market);
                        company.stockMarket   = mytempQuery.Security.Market;
                        company.foundwithisin = true;
                    }
                }

                else
                {
                    Console.WriteLine("{0},{1} working", company.mic, company.ticker);
                    company.found = true;
                }
            }
            Console.Clear();
            foreach (StockInput company in data)
            {
                if (company.found == true)
                {
                    Console.WriteLine("{0},{1}", company.mic, company.ticker);
                }
            }

            Console.WriteLine("Found with ISIN");
            foreach (StockInput company in data)
            {
                if (company.found == false && company.foundwithisin == true)
                {
                    Console.WriteLine("{0},{1},{2},{3}", company.isin, company.ticker, company.mic, company.stockMarket);
                }
            }

            Console.WriteLine("Not found");
            foreach (StockInput company in data)
            {
                if (company.found == false && company.foundwithisin == false)
                {
                    Console.WriteLine("{0},{1},{2}", company.isin, company.ticker, company.mic);
                }
            }
        }
示例#5
0
        static public void AccessEnglishWeb()
        {
            InstrumentContext ctx          = new InstrumentContext();
            String            queryPath    = @"http://www.londonstockexchange.com/exchange/prices-and-markets/stocks/summary/company-summary/";
            List <Target>     londonStocks = AccessFiles.getList(StockName.London);

            foreach (Target item in londonStocks)
            {
                string xquery = ".//div[@class='commonTable table-responsive']/table//td";
                string path   = queryPath + item.urlIdentifier + ".html";
                Console.WriteLine("Getting {0}", path);
                var myArray = GetTable(path, xquery);
                if (myArray == null)
                {
                    continue;
                }
                Instrument myInstrument = new Instrument();
                {
                    string   changes = myArray[3].InnerText.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace(")", string.Empty).Replace("(", string.Empty);
                    String[] m       = Regex.Split(changes, "%");
                    myInstrument.PctChange(m[0]);
                    myInstrument.Change(m[1]);
                    myInstrument.LastPrice(myArray[1].InnerText);
                    myInstrument.DayHigh(myArray[5].InnerText);
                    myInstrument.DayLow(myArray[7].InnerText);
                    myInstrument.Volume(myArray[9].InnerText);
                    string isolatePrevClose = myArray[11].InnerText.Replace("\r", string.Empty).Replace("\n", string.Empty);
                    m = Regex.Split(isolatePrevClose, "on");
                    myInstrument.PrevClose(m[0]);
                    myInstrument.Bid(myArray[13].InnerText);
                    myInstrument.Ask(myArray[15].InnerText);
                    myInstrument.ticker            = item.shortIdentifier;
                    myInstrument.timestamp         = System.DateTime.Now;
                    myInstrument.stockExchangeName = StockName.London;
                    myInstrument.url = path;
                }
                // accessing the mongoDB

                // In order to not get banned we delay individul request from the london website
                //Getting the data from Xignite
                GlobalQuote       tempQuery        = AccessXIgnite.getXigniteData("XLON", item.shortIdentifier);
                var               serializedParent = JsonConvert.SerializeObject(tempQuery);
                GlobalQuoteExtend query            = JsonConvert.DeserializeObject <GlobalQuoteExtend>(serializedParent);
                query.DBtimestamp = myInstrument.timestamp;
                ctx.IgniteInstruments.InsertOne(query);
                var differences = myInstrument.compareInstrument(query);
                ctx.Instruments.InsertOne(myInstrument);

                if (differences.different == true)
                {
                    ctx.mismatchInstruments.InsertOne(differences);
                    Console.WriteLine("Found a mismatch! " + differences.ticker + " " + differences.comments);
                }
                System.Threading.Thread.Sleep(1000);
            }
        }
示例#6
0
 public void StartProgram()
 {
     _outputManager.RequestStockSymbol();
     StockSymbol = _inputManager.RecordStockSymbol();
     // check for valid stock symbol from DB
     Request     = _apiManager.BuildApiRequest(StockSymbol);
     GlobalQuote = _apiManager.ExecuteApiRequest(Request);
     // record globalQuote results in DB
     _outputManager.PrintQuoteInfo(GlobalQuote);
     //Console.ReadKey();
 }
示例#7
0
        static void AccessHongKong()
        {
            //some psuedo random sample of stocks
            string[] stockList = new string[] { "8091", "136", "771", "299", "8358", "1656", "3639", "21", "8316", "1663", "2927", "1637", "646", "8327", "1231", "8195", "8256", "8416", "362", "1462" };
            foreach (string stock in stockList)
            {
                string Url = @"https://www.hkex.com.hk/eng/invest/company/quote_page_e.asp?WidCoID=" + stock + @"&WidCoAbbName=&Month=1&langcode=e";

                using (WebClient client = new WebClient())
                {
                    client.Headers["User-Agent"] =
                        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36";
                    client.UseDefaultCredentials = true;
                    HtmlDocument htmlDoc = new HtmlDocument();
                    htmlDoc.LoadHtml(client.DownloadString(Url));
                    Instrument myInstrument = new Instrument();
                    {
                        myInstrument.stockExchangeName = StockName.HongKong;

                        var        a   = htmlDoc.DocumentNode.SelectNodes("//td[@bgcolor='#CCCCCC']");
                        HtmlNode[] map = new HtmlNode[a.Count];
                        a.CopyTo(map, 0);
                        myInstrument.pctChange = 0;
                        if (map[1].InnerHtml.Contains("down"))
                        {
                            myInstrument.Change("-" + map[1].InnerText);
                            myInstrument.PctChange("-" + map[2].InnerText);
                        }
                        else
                        {
                            myInstrument.Change(map[1].InnerText);
                            myInstrument.PctChange(map[2].InnerText);
                        }
                        myInstrument.LastPrice(map[0].InnerText);
                        myInstrument.Bid(map[3].InnerText);
                        myInstrument.Ask(map[4].InnerText);
                        myInstrument.DayHigh(map[6].InnerText);
                        myInstrument.DayLow(map[7].InnerText);
                        myInstrument.ticker = stock;
                        myInstrument.PrevClose(RemoveExtraText(map[8].InnerText));
                        myInstrument.Volume(map[11].InnerText);
                        myInstrument.timestamp = System.DateTime.Now;
                    }
                    GlobalQuote       mytempQuery      = AccessXIgnite.getXigniteData("XHGK", myInstrument.ticker);
                    var               serializedParent = JsonConvert.SerializeObject(mytempQuery);
                    GlobalQuoteExtend query            = JsonConvert.DeserializeObject <GlobalQuoteExtend>(serializedParent);
                    var               differences      = myInstrument.compareInstrument(query);
                }
            }
        }
示例#8
0
        static void AccessEuroNext()
        {
            List <Target> stockList = AccessFiles.getList(StockName.EURONEXT);

            foreach (var stock in stockList)
            {
                Console.WriteLine(stock.urlIdentifier);
            }
            GlobalQuote mytempQuery = AccessXIgnite.getXigniteData("XNAS", "a");

            using (PhantomJSDriver driver = new PhantomJSDriver(@"C:\phantomjs-2.1.1-windows\bin"))
            {
                foreach (Target stock in stockList)
                {
                    driver.Url = stock.urlIdentifier;
                    driver.Navigate();
                    System.Threading.Thread.Sleep(3 * 1000);
                    Instrument myInstrument = new Instrument();
                    {
                        try
                        {
                            myInstrument.PctChange(driver.FindElementById("cnDiffRelvalue").Text.Replace("(", string.Empty).Replace(")", string.Empty));
                            myInstrument.Change(driver.FindElementById("cnDiffAbsvalue").Text);
                            myInstrument.LastPrice(driver.FindElementById("lastPriceint").Text + driver.FindElementById("lastPricefract").Text);
                            myInstrument.DayHigh(driver.FindElementById("highPricevalue").Text.Split('[')[0]);
                            myInstrument.DayLow(driver.FindElementById("lowPricevalue").Text.Split('[')[0]);
                            string b = driver.FindElementById("todayVolumevalue").Text.Split('[')[0];
                            myInstrument.Volume(driver.FindElementById("todayVolumevalue").Text.Split('[')[0]);
                            //myInstrument.PrevClose(table.FindElement(By.ClassName("op")).Text);

                            myInstrument.Bid(driver.FindElementById("bidPricevalue").Text);
                            myInstrument.Ask(driver.FindElementById("askPricevalue").Text);

                            myInstrument.ticker            = stock.shortIdentifier;
                            myInstrument.timestamp         = System.DateTime.Now;
                            myInstrument.stockExchangeName = StockName.EURONEXT;
                            myInstrument.url = stock.urlIdentifier;
                        }

                        catch

                        {
                        }
                    }
                    InstrumentContext ctx = new InstrumentContext();
                    ctx.Instruments.InsertOne(myInstrument);
                }
            }
        }
示例#9
0
        public static async Task StocksDemo()
        {
            // use your AlphaVantage API key
            string apiKey = "6FQOAVODM8ZFCE3T";

            // there are 5 more constructors available
            using var client       = new AlphaVantageClient(apiKey);
            using var stocksClient = client.Stocks();

            StockTimeSeries stockTs = await stocksClient.GetTimeSeriesAsync("AAPL", Interval.Daily, OutputSize.Compact, isAdjusted : true);

            GlobalQuote globalQuote = await stocksClient.GetGlobalQuoteAsync("AAPL");

            ICollection <SymbolSearchMatch> searchMatches = await stocksClient.SearchSymbolAsync("BA");
        }
示例#10
0
        public static GlobalQuote  getXigniteData(string exchgangeName, string tickerName)
        {
            var historical = new XigniteGlobalHistorical(XigniteKey);

            var    currencies = new XigniteGlobalCurrencies(XigniteKey);
            var    bond       = new XigniteGlobalQuotes(XigniteKey);
            var    ExchList   = bond.ListExchanges().ExchangeDescriptions;
            string symbol;
            var    a = historical.ListExchanges().ExchangesDescriptions;
            int    i = 0;

            /*           foreach (var b in a)
             *         {
             *             Console.WriteLine(b.Market+i+" "+b.MarketIdentificationCode);
             *             i++;
             *         }
             *
             */

            if (exchgangeName != "XNAS")
            {
                symbol = String.Format("{0}.{1}", tickerName, exchgangeName);
            }
            else
            {
                symbol = tickerName;
            }
            //string datePattern = @"MM/dd/yyyy";

            GlobalQuote data = bond.GetGlobalDelayedQuote(symbol, IdentifierTypes.Symbol);

            if (data.Message.Contains("Delay times are"))
            {
                //Console.WriteLine("Call took: " + data.Delay);
                return(data);
            }
            else
            {
                Console.WriteLine("Call failed: " + data.Message);
                return(null);
            }
        }
示例#11
0
        static void AccessNasdaq()
        {
            List <Target> stockList = AccessFiles.getList(StockName.Nasdaq);

            foreach (Target stock in stockList)
            {
                string     xquery    = ".//div[@class='genTable thin']//td";
                HtmlNode[] myArray   = GetTable(stock.urlIdentifier, xquery);
                String[]   m         = Regex.Split(myArray[17].InnerText, ";");
                string[]   innerText = new string[myArray.Length];
                for (int i = 0; i < myArray.Length; i++)
                {
                    innerText[i] = myArray[i].InnerText.Replace("&", string.Empty).Replace("#", string.Empty).Replace("%", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("nbsp", string.Empty).Replace("$", string.Empty).Replace(";", string.Empty);
                }
                for (int i = 0; i < m.Length; i++)
                {
                    m[i].Replace("&", string.Empty).Replace("#", string.Empty).Replace("%", string.Empty).Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("nbsp", string.Empty).Replace("$", string.Empty).Replace(";", string.Empty);
                }

                Instrument myInstrument = new Instrument();
                {
                    //  This is a combination of change and pct change and we thus separate them
                    if (m[1] == "9660")
                    {
                        myInstrument.PctChange("-" + m[3]);
                        myInstrument.Change("-" + m[0]);
                    }
                    // New: Nasdaq started marking unchanged in a funny way
                    else if (m[0].Contains("unch"))
                    {
                        myInstrument.PctChange(0);
                        myInstrument.Change(0);
                    }

                    else
                    {
                        myInstrument.PctChange(m[3]);
                        myInstrument.Change(m[0]);
                    }
                    myInstrument.LastPrice(innerText[1]);
                    myInstrument.DayHigh(innerText[5]);
                    myInstrument.DayLow(innerText[21]);
                    myInstrument.Volume(innerText[3]);
                    myInstrument.PrevClose(innerText[19]);
                    myInstrument.Bid(innerText[7]);
                    myInstrument.Ask(innerText[23]);
                    myInstrument.ticker            = stock.shortIdentifier;
                    myInstrument.timestamp         = System.DateTime.Now;
                    myInstrument.stockExchangeName = StockName.Nasdaq;
                    myInstrument.url = stock.urlIdentifier;
                }
                InstrumentContext ctx = new InstrumentContext();

                GlobalQuote       mytempQuery      = AccessXIgnite.getXigniteData("XNAS", myInstrument.ticker);
                var               serializedParent = JsonConvert.SerializeObject(mytempQuery);
                GlobalQuoteExtend query            = JsonConvert.DeserializeObject <GlobalQuoteExtend>(serializedParent);
                query.DBtimestamp = myInstrument.timestamp;
                ctx.IgniteInstruments.InsertOne(query);
                var differences = myInstrument.compareInstrument(query);
                ctx.Instruments.InsertOne(myInstrument);

                if (differences.different == true)
                {
                    ctx.mismatchInstruments.InsertOne(differences);
                }

                ctx.Instruments.InsertOne(myInstrument);
            }
        }
示例#12
0
 public void PrintQuoteInfo(GlobalQuote globalQuote)
 {
     Console.WriteLine($"Symbol: {globalQuote.Symbol}");
     Console.WriteLine($"Current Price: {globalQuote.CurrentPrice}");
     Console.WriteLine($"Previous Close: {globalQuote.PreviousClose}");
 }