Beispiel #1
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);
                }
            }
        }
        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);
            }
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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);
                }
            }
        }
Beispiel #5
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);
            }
        }