Example #1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="suffix"></param>
        /// <remarks></remarks>
        public StockExchange(string id, string suffix, string name, CountryInfo country, TradingTimeInfo tradeTime)
        {
            if (id != string.Empty)
            {
                mID = id;
            }
            else
            {
                throw new ArgumentNullException("id", "The ID is empty.");
            }

            mSuffix = suffix;
            mName   = name;
            if (country != null)
            {
                mCountry = country;
            }
            else
            {
                throw new ArgumentNullException("country", "The country is null.");
            }

            if (tradeTime != null)
            {
                mTradingTime = tradeTime;
            }
            else
            {
                throw new ArgumentNullException("tradeTime", "The trade time is null.");
            }
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="id"></param>
        /// <param name="suffix"></param>
        /// <remarks></remarks>
        public StockExchange(string id, string suffix, string name, CountryInfo country, TradingTimeInfo tradeTime)
        {
            if (id != string.Empty)
            {
                mID = id;
            }
            else
            {
                throw new ArgumentNullException("id", "The ID is empty.");
            }

            mSuffix = suffix;
            mName = name;
            if (country != null)
            {
                mCountry = country;
            }
            else
            {
                throw new ArgumentNullException("country", "The country is null.");
            }

            if (tradeTime != null)
            {
                mTradingTime = tradeTime;
            }
            else
            {
                throw new ArgumentNullException("tradeTime", "The trade time is null.");
            }
        }
Example #3
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");
            }
        }
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);
         }
     }
 }
 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);
         }
     }
 }
Example #6
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");
            }
        }
Example #7
0
        /// <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());
        }
        /// <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();
        }