Example #1
0
        /// <summary>
        /// Creates a new instance from an IDSearchResult
        /// </summary>
        /// <param name="searchResult"></param>
        /// <remarks></remarks>
        public YID(IDSearchData searchResult)
        {
            if (searchResult != null)
            {
                this.SetID(searchResult.ID, false);
                this.Name     = searchResult.Name;
                this.Industry = searchResult.Industry;
                this.Type     = searchResult.Type;

                string exc = searchResult.Exchange.Replace("N/A", "").Trim();
                if (exc != string.Empty)
                {
                    StockExchange se = WorldMarket.GetStockExchangeByID(exc);
                    if (se == null)
                    {
                        se = WorldMarket.GetStockExchangeByName(exc);
                    }
                    if (se != null)
                    {
                        this.StockExchange = se;
                    }
                    else
                    {
                        se = WorldMarket.GetStockExchangeBySuffix(this.ID);
                        if (se != null)
                        {
                            this.StockExchange = se;
                        }
                        else
                        {
                            CountryInfo     cnt = WorldMarket.GetDefaultCountry(Country.US);
                            TradingTimeInfo tti = new TradingTimeInfo(0, new DayOfWeek[] {
                                DayOfWeek.Monday,
                                DayOfWeek.Tuesday,
                                DayOfWeek.Wednesday,
                                DayOfWeek.Thursday,
                                DayOfWeek.Friday
                            }, null, new DateTime(), new TimeSpan(23, 59, 59), -5);
                            this.StockExchange = new StockExchange(searchResult.Exchange, this.Suffix, searchResult.Exchange, cnt, tti);
                        }
                    }
                }

                if (searchResult.ISIN != null && searchResult.ISIN.Value.Replace("N/A", "").Trim() != string.Empty)
                {
                    try
                    {
                        this.ISIN = new ISIN(searchResult.ISIN.Value);
                    }
                    catch (ArgumentException ex)
                    {
                        this.ISIN = null;
                    }
                }
            }
            else
            {
                throw new ArgumentException("The passed result is null", "searchResult");
            }
        }
        /// <summary>
        /// Loads default market information from market.xml
        /// </summary>
        /// <remarks></remarks>

        public static void FillCountriesWithIndices()
        {
            XDocument xmlDoc = MyHelper.ParseXmlDocument(Properties.Resources.market);

            XElement[] countryNodes = XPath.GetElements("//Resources/Countries/Country", xmlDoc);

            foreach (XElement countryNode in countryNodes)
            {
                CountryInfo ctr = null;

                string ctrIDStr = MyHelper.GetXmlAttributeValue(countryNode, "ID");
                foreach (CountryInfo defaultCtr in DefaultCountries)
                {
                    if (defaultCtr.ID.ToString() == ctrIDStr)
                    {
                        ctr = defaultCtr;
                        break;
                    }
                }

                if (ctr != null)
                {
                    ctr.Indices.Clear();
                    XElement indicesNode = XPath.GetElement("Indices", countryNode);
                    foreach (XElement indexNode in indicesNode.Elements())
                    {
                        if (indexNode.Name.LocalName == "Index")
                        {
                            string name = MyHelper.GetXmlAttributeValue(indexNode, "Name");
                            string id   = MyHelper.GetXmlAttributeValue(indexNode, "ID");

                            string        seStr = MyHelper.GetXmlAttributeValue(indexNode, "StockExchange");
                            StockExchange se    = null;
                            foreach (StockExchange defaultExc in mStockExchanges)
                            {
                                if (defaultExc.ID == seStr)
                                {
                                    se = defaultExc;
                                    break;
                                }
                            }

                            ctr.Indices.Add(new YIndexID(id)
                            {
                                Name          = name,
                                StockExchange = se
                            });
                        }
                    }
                }
            }
        }
Example #3
0
 protected virtual void SetID(string id, bool setStockExchangeBySuffix = true)
 {
     if (id == null || id.Trim() == string.Empty)
     {
         throw new ArgumentNullException("id", "The ID is null.");
     }
     mID = id.Trim().ToUpper();
     this.OnPropertyChanged("ID");
     if (setStockExchangeBySuffix)
     {
         mStockExchange = null;
         StockExchange se = WorldMarket.GetStockExchangeBySuffix(id);
         if (se != null)
         {
             this.StockExchange = se;
         }
     }
 }
Example #4
0
 internal StockExchange(StockExchange se)
 {
     if (se == null)
     {
         throw new ArgumentNullException("se", "Original StockExchange is null.");
     }
     else
     {
         if (se != null)
         {
             mID      = se.ID;
             mCountry = se.Country;
             mSuffix  = se.Suffix;
             mName    = se.Name;
             TradingTimeInfo tt = se.TradingTime;
             mTradingTime = new TradingTimeInfo(tt.DelayMinutes, tt.TradingDays, tt.Holidays, tt.LocalOpeningTime, tt.TradingSpan, tt.UtcOffsetStandardTime, tt.DaylightSavingTimes);
         }
     }
 }
        /// <summary>
        /// Loads a list of default stock exchanges from market.xml
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static StockExchange[] GetDefaultStockExchanges()
        {
            List <StockExchange> lst = new List <StockExchange>();

            XDocument xmlDoc = MyHelper.ParseXmlDocument(Properties.Resources.market);

            XElement[] exchanges = XPath.GetElements("//Resources/StockExchanges/StockExchange", xmlDoc);

            foreach (XElement exchangeNode in exchanges)
            {
                string seID     = MyHelper.GetXmlAttributeValue(exchangeNode, "ID");
                string seSuffix = MyHelper.GetXmlAttributeValue(exchangeNode, "Suffix");
                string seName   = MyHelper.GetXmlAttributeValue(exchangeNode, "Name");

                CountryInfo seCountry = null;
                string      ctrID     = MyHelper.GetXmlAttributeValue(exchangeNode, "Country");
                foreach (CountryInfo ctr in DefaultCountries)
                {
                    if (ctr.ID.ToString() == ctrID)
                    {
                        seCountry = ctr;
                        break;
                    }
                }

                //TradingTimeInfo
                int      seDelayMinutes     = Convert.ToInt32(MyHelper.GetXmlAttributeValue(exchangeNode, "DelayMinutes"));
                int      seRelativeToUTC    = Convert.ToInt32(MyHelper.GetXmlAttributeValue(exchangeNode, "UtcOffsetStandardTime"));
                DateTime seOpeningTimeLocal = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(exchangeNode, "OpeningTimeLocal"));
                DateTime seClosingTimeLocal = Convert.ToDateTime(MyHelper.GetXmlAttributeValue(exchangeNode, "ClosingTimeLocal"));
                TimeSpan seTradingSpan      = seClosingTimeLocal - seOpeningTimeLocal;

                List <DayOfWeek> seTradingDaysList = new List <DayOfWeek>();
                string           trdDays           = MyHelper.GetXmlAttributeValue(exchangeNode, "TradingDays");
                foreach (string day in trdDays.Split(','))
                {
                    switch (day)
                    {
                    case "Mo":
                        seTradingDaysList.Add(DayOfWeek.Monday);
                        break;

                    case "Tu":
                        seTradingDaysList.Add(DayOfWeek.Tuesday);
                        break;

                    case "We":
                        seTradingDaysList.Add(DayOfWeek.Wednesday);
                        break;

                    case "Th":
                        seTradingDaysList.Add(DayOfWeek.Thursday);
                        break;

                    case "Fr":
                        seTradingDaysList.Add(DayOfWeek.Friday);
                        break;

                    case "Sa":
                        seTradingDaysList.Add(DayOfWeek.Saturday);
                        break;

                    case "Su":
                        seTradingDaysList.Add(DayOfWeek.Sunday);
                        break;
                    }
                }

                DaylightSavingTime[] seDaylightSavingTimes = null;
                if (seCountry != null)
                {
                    seDaylightSavingTimes = seCountry.DaylightSavingTimes;
                }

                TradingTimeInfo seTradingTimeInfo = new TradingTimeInfo(seDelayMinutes, seTradingDaysList.ToArray(), null, seOpeningTimeLocal, seTradingSpan, seRelativeToUTC, seDaylightSavingTimes);

                StockExchange se = new StockExchange(seID, seSuffix, seName, seCountry, seTradingTimeInfo);
                string        s  = MyHelper.GetXmlAttributeValue(exchangeNode, "Tags");
                if (s != string.Empty)
                {
                    se.Tags.AddRange(s.Split(','));
                }
                lst.Add(se);
            }

            return(lst.ToArray());
        }