Ejemplo n.º 1
0
        internal Queue <DateTime> CreateRealtimePeriods(DateTime today)
        {
            DateTime cFrom = today;

            AbstractExchange        cExchange     = ProductManager.Manager.GetExchange(__cDataRequest.Exchange);
            AbstractProductProperty cProperty     = cExchange.GetProperty(__cDataRequest.Symbol);
            IContractTime           cContractTime = cProperty.ContractRule as IContractTime;

            DateTime cExpiration = DateTime.MinValue;

            if (cContractTime == null)
            {
                cExpiration = today.AddDays(2);
            }
            else
            {
                ContractTime cContract = cContractTime.GetContractTime(today);
                cExpiration = cContract.MaturityDate;
            }

            ESymbolCategory cCategory = __cSettings.ASymbolInfo2.Category;

            if ((cCategory == ESymbolCategory.Future || cCategory == ESymbolCategory.IndexOption || cCategory == ESymbolCategory.StockOption || cCategory == ESymbolCategory.FutureOption || cCategory == ESymbolCategory.FutureRolover) && ConvertParameter.強制今日為期權到期日)
            {
                cExpiration = new DateTime(today.Year, today.Month, today.Day, cExpiration.Hour, cExpiration.Minute, cExpiration.Second);
            }

            if (__cDataRequest.Resolution.TotalSeconds == Resolution.MAX_BASE_TOTALSECONDS)
            {
                cFrom = today.AddDays(-1);
            }
            __cTimeQueue = __cDataRequest.Resolution.CalculateRealtimePeriods(this.LastBarTime, today, cExpiration);
            return(__cTimeQueue);
        }
Ejemplo n.º 2
0
        internal _QuoteInfo(string exchangeName, string dataSource, string symbolId, string symbolName, double price)
        {
            this.SymbolId   = symbolId;
            this.SymbolName = symbolName;
            this.DataSource = dataSource;

            AbstractExchange        cExchange = ProductManager.Manager.GetExchange(exchangeName);
            AbstractProductProperty cProperty = cExchange.GetProperty(symbolId, dataSource);

            IPriceScale cPriceScale = null;

            if (cProperty != null)
            {
                cPriceScale = cProperty.PriceScaleRule as IPriceScale;
            }

            double[] dScales = new double[] { 1, 1 };
            if (cPriceScale != null)
            {
                dScales = cPriceScale.GetPriceScale(price);
            }

            string sScale = dScales[0].ToString();
            int    iIndex = sScale.IndexOf('.');

            if (iIndex > -1)
            {
                __iDecimals = sScale.Length - iIndex - 1;
            }
        }
Ejemplo n.º 3
0
        private void frmProductManager_Load(object sender, EventArgs e)
        {
            List <AbstractExchange> cExchanges = ProductManager.Manager.Exchanges;

            int iCount = cExchanges.Count;

            if (iCount > 0)
            {
                TreeNode cRootNode = treeExchanges.Nodes[0];

                for (int i = 0; i < iCount; i++)
                {
                    AbstractExchange cExchange     = cExchanges[i];
                    TreeNode         cTreeExchange = new TreeNode(cExchange.ShortName, 1, 1);
                    cTreeExchange.Name = cExchange.ShortName;

                    ESymbolCategory[] cCategorys = Enum.GetValues(typeof(ESymbolCategory)) as ESymbolCategory[];
                    foreach (ESymbolCategory cCategory in cCategorys)
                    {
                        List <string> cSymbols = cExchange.GetProductClassify(cCategory);
                        if (cSymbols != null && cSymbols.Count > 0)
                        {
                            string   sCategory     = Enum.GetName(typeof(ESymbolCategory), cCategory);
                            TreeNode cTreeCategory = new TreeNode(string.Format("{0}({1})", sCategory, cSymbols.Count), 2, 2);
                            cTreeCategory.Name = sCategory;
                            cTreeCategory.Tag  = cCategory;
                            cTreeExchange.Nodes.Add(cTreeCategory);
                        }
                    }
                    cRootNode.Nodes.Add(cTreeExchange);
                }
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            double dValue = 0;

            if (double.TryParse(txtBigPointValue.Text, out dValue))
            {
                __cProperty.BigPointValue = dValue;
            }

            if (double.TryParse(txtDailyLimit.Text, out dValue))
            {
                __cProperty.DailyLimit = dValue;
            }
            __cProperty.Description = txtDescription.Text;

            string sDataSource = comboDataSource.Text;

            sDataSource = (sDataSource.Length == 0) ? null : sDataSource;
            if (sDataSource == null)
            {
                DialogResult cResult = MessageBox.Show(__sMessageContent_001, __sMessageHeader_001, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (cResult == DialogResult.No)
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }

            //變更設定值
            AbstractExchange cExchange = ProductManager.Manager.GetExchange(__sExchangeName);

            cExchange.AddProperty(__cProperty, sDataSource);

            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 5
0
        internal frmProductRuleSettings(string exchangeName, ERuleType ruleType, AbstractProductProperty property)
        {
            InitializeComponent();

            __cRuleType = ruleType;
            __cProperty = property;

            AbstractExchange cExchange = ProductManager.Manager.GetExchange(exchangeName);

            __cRules = cExchange.GetRuleItems(ruleType);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="exchange"></param>
 /// <param name="localEntity"></param>
 /// <param name="distantEntity"></param>
 public AbstractGameExchangeAction(AbstractExchange exchange, AbstractEntity localEntity, AbstractEntity distantEntity = null)
     : base(GameActionTypeEnum.EXCHANGE, localEntity)
 {
     DistantEntity = distantEntity;
     Exchange      = exchange;
     Exchange.AddHandler(Entity.Dispatch);
     if (DistantEntity != null)
     {
         Exchange.AddHandler(DistantEntity.Dispatch);
     }
     Entity.AddUpdatable(Exchange);
 }
Ejemplo n.º 7
0
        private void LoadProducts(string dataSource)
        {
            List <AbstractExchange> cExchanges = ProductManager.Manager.Exchanges;

            int iCount = cExchanges.Count;

            if (iCount > 0)
            {
                for (int i = 0; i < iCount; i++)
                {
                    AbstractExchange cExchange = cExchanges[i];

                    int               iIndex        = 0;
                    string            sExchangeName = cExchange.ShortName;
                    ESymbolCategory[] cCategorys    = Enum.GetValues(typeof(ESymbolCategory)) as ESymbolCategory[];
                    foreach (ESymbolCategory cCategory in cCategorys)
                    {
                        List <string> cSymbols = cExchange.GetProductClassify(cCategory);
                        if (cSymbols != null && cSymbols.Count > 0)
                        {
                            ++iIndex;
                            tabControl_Products.TabPages.Add(cCategory.ToString());
                            if (iIndex == __cSources.Count)
                            {
                                SimpleBoundList <_ProductInfo> cList = new SimpleBoundList <_ProductInfo>(cSymbols.Count);
                                cList.AllowSort = true;
                                cList.SetComparers(__cComparison);

                                __cSources.Add(cList);
                            }

                            foreach (string sSymbolId in cSymbols)
                            {
                                AbstractProductProperty cProperty = cExchange.GetProperty(sSymbolId, dataSource);
                                if (cProperty != null)
                                {
                                    _ProductInfo cProductInfo = new _ProductInfo()
                                    {
                                        ProductId    = sSymbolId,
                                        Description  = cProperty.Description,
                                        ExchangeName = sExchangeName
                                    };

                                    __cSources[0].Add(cProductInfo);
                                    __cSources[iIndex].Add(cProductInfo);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        ///   取得交易所
        /// </summary>
        /// <param name="shortName">交易所簡稱</param>
        /// <returns>返回值:AbstractExchange類別</returns>
        public AbstractExchange GetExchange(string shortName)
        {
            int iIndex = 0;
            AbstractExchange cExchange = null;

            lock (__cKeys) {
                if (__cKeys.TryGetValue(shortName, out iIndex))
                {
                    cExchange = __cExchanges[iIndex];
                }
            }
            return(cExchange);
        }
        private void Dispose(bool disposing)
        {
            if (!this.__bDisposed)
            {
                __bDisposed = true;

                if (disposing)
                {
                    __cExchange     = null;
                    __cSymbolBuffer = null;
                }
            }
        }
Ejemplo n.º 10
0
        internal void AddExchange(AbstractExchange exchange)
        {
            string sShortName = exchange.ShortName;

            lock (__cKeys) {
                if (!__cKeys.ContainsKey(sShortName))
                {
                    int iIndex = __cExchanges.Count;
                    __cExchanges.Add(exchange);
                    __cKeys.Add(sShortName, iIndex);
                }
            }
        }
Ejemplo n.º 11
0
        private void RefreshCategoryNode(string exchangeName, ESymbolCategory category)
        {
            string sCategory = Enum.GetName(typeof(ESymbolCategory), category);

            TreeNode cRootNode     = treeExchanges.Nodes[0];
            TreeNode cExchangeNode = cRootNode.Nodes[exchangeName];
            TreeNode cCategoryNode = cExchangeNode.Nodes[sCategory];

            AbstractExchange cExchange = ProductManager.Manager.GetExchange(exchangeName);
            List <string>    cSymbols  = cExchange.GetProductClassify(category);

            if (cSymbols != null)
            {
                cCategoryNode.Text = string.Format("{0}({1})", sCategory, cSymbols.Count);
            }
        }
Ejemplo n.º 12
0
		internal static void Update(DateTime date) {
			__cToday = date.Date;
			__cSymbolList.Clear();
			__cMitakeQuoteInformations.Clear();

			AbstractExchange cExchange = ProductManager.Manager.GetExchange(__sExchangeName);
			cExchange.Update(date); //更新交易所商品屬性資訊

			cExchange.UpdateTime = DateTime.Today.AddDays(-2);  //設定為兩天前(強迫更新)
			cExchange.Clear();  //如果要更新則全部清除

			//新增上櫃指數(Mitake股票清單內沒有這支指數需要自行新增)
			cExchange.AddProduct(MitakeSymbolManager.GetIndexSymbolInformation(9998));

			//新增上市指數(Mitake股票清單內沒有這支指數需要自行新增)
			cExchange.AddProduct(MitakeSymbolManager.GetIndexSymbolInformation(9999));
		}
Ejemplo n.º 13
0
        /// <summary>
        ///   搜尋商品資訊
        /// </summary>
        /// <param name="symbolId">商品代號</param>
        /// <param name="isMatch">是否需要吻合(true=商品代號需要完全吻合, false=商品代號不需要完全吻合)</param>
        /// <returns>返回值:商品資訊列表</returns>
        public List <ProductInformation> SearchProducts(string symbolId, bool isMatch)
        {
            List <ProductInformation> cProductInfos = new List <ProductInformation>(64);

            int iCount = __cExchanges.Count;

            for (int i = 0; i < iCount; i++)
            {
                AbstractExchange cExchange = __cExchanges[i];
                List <Product>   cProducts = cExchange.SearchProducts(symbolId, isMatch);
                if (cProducts.Count > 0)
                {
                    cProductInfos.Add(new ProductInformation(cExchange, cProducts));
                }
            }
            return(cProductInfos);
        }
Ejemplo n.º 14
0
        private void RefreshSymbolCategorys(string exchangeName, ESymbolCategory category)
        {
            AbstractExchange cExchange = ProductManager.Manager.GetExchange(exchangeName);
            List <string>    cSymbols  = cExchange.GetProductClassify(category);

            __cAllData.Clear();
            __cBasicData.Clear();
            __cCustomData.Clear();

            int iCount       = cSymbols.Count;
            int iSourceCount = __cDataSources.Count;

            for (int i = 0; i < iCount; i++)
            {
                string  sSymbol  = cSymbols[i];
                Product cProduct = cExchange.GetProduct(sSymbol);
                AbstractProductProperty cBaseProperty = cExchange.GetProperty(sSymbol);

                _ProductInfo cBasicInfo = CreateProductInfo(exchangeName, null, cProduct, cBaseProperty);
                __cAllData.Add(cBasicInfo);

                if (cBaseProperty != null)
                {
                    __cBasicData.Add(cBasicInfo);

                    for (int j = 0; j < iSourceCount; j++)
                    {
                        string sDataSource = __cDataSources[j];
                        AbstractProductProperty cProperty = cExchange.GetProperty(sSymbol, sDataSource);
                        if (cProperty != cBaseProperty)
                        {
                            _ProductInfo cProductInfo = CreateProductInfo(exchangeName, sDataSource, cProduct, cProperty);
                            __cAllData.Add(cProductInfo);
                            __cCustomData.Add(cProductInfo);
                        }
                    }
                }
            }

            source.Refresh();
            if (__cSortRangeRowEvent != null)
            {
                this.dataGrid.SortRangeRows(__cSortRangeRowEvent.Range, __cSortRangeRowEvent.KeyColumn, __cSortRangeRowEvent.Ascending, __cSortRangeRowEvent.CellComparer);
            }
        }
Ejemplo n.º 15
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            string sSymbolId = txtProductId.Text;

            if (sSymbolId.Length == 0)                //如果沒有輸入商品代號就離開
            {
                return;
            }

            __sExchangeName = comboExchange.Text;
            string sCommodityId = txtCommodity.Text;

            AbstractExchange cExchange = ProductManager.Manager.GetExchange(__sExchangeName);

            __cProduct = cExchange.GetProduct(sSymbolId);
            if (__cProduct == null)
            {
                string          sProductName = txtProductName.Text;
                ESymbolCategory cCategory    = (ESymbolCategory)Enum.Parse(typeof(ESymbolCategory), comboCategory.Text);

                __cProduct            = new Product();
                __cProduct.SymbolId   = sSymbolId;
                __cProduct.SymbolName = sProductName;
                __cProduct.Category   = cCategory;
                if (sCommodityId.Length > 0)
                {
                    __cProduct.CommodityId = sCommodityId;
                }

                cExchange.AddProduct(__cProduct);
            }

            sSymbolId     = __cProduct.SymbolId;
            __sDataSource = comboDataSource.Text;
            __sDataSource = (__sDataSource.Length == 0) ? null : __sDataSource;

            string sCommodity = (sCommodityId.Length == 0) ? sSymbolId : sCommodityId;

            cExchange.AddProperty(sCommodity, __sDataSource);
            __cProperty = cExchange.GetProperty(sSymbolId, __sDataSource);

            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 16
0
        private void SaveSettings()
        {
            DialogResult cResult = MessageBox.Show(__sMessageContent_003, __sMessageHeader_003, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (cResult == DialogResult.Yes)
            {
                List <AbstractExchange> cExchanges = ProductManager.Manager.Exchanges;

                int iCount = cExchanges.Count;
                for (int i = 0; i < iCount; i++)
                {
                    AbstractExchange cExchange = cExchanges[i];
                    cExchange.Save();                      //交易所資訊儲存
                    cExchange.Load();                      //重新讀取交易所設定值
                }

                MessageBox.Show(__sMessageContent_004, __sMessageHeader_004, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 17
0
		private static int GetContractTimeIndex(string commodityId, int year, int month, int week = 0) {
			int iRet = -1;
			
			AbstractExchange cExchange = ProductManager.Manager.GetExchange(__sExchangeName);
			AbstractProductProperty cProperty = cExchange.GetProperty(commodityId, DataSource);
			if (cProperty != null) {
				int iYear = __cToday.Year;
				int iMod = iYear % 10;
				if (iMod == 9 && year == 0) {
					++iYear;
				} else {
					iYear = (iYear - iMod) + year;
				}
				
				int iDay = __cToday.Day;
				int iDays = DateTime.DaysInMonth(iYear, month);  //取得該月份的最大天數

				DateTime cContract = DateTime.MinValue;
				if (commodityId[2] == 'W') {  //如果是週商品(期權)
					int iFirstWeek = (int) new DateTime(iYear, month, 1).DayOfWeek;
					int iFirstWedDay = (7 - iFirstWeek > 3) ? 4 - iFirstWeek : 11 - iFirstWeek;
					int iWeekDay = iFirstWedDay + (week - 1) * 7;
					if (iDay > iWeekDay) {  //如果今日日期 > 週商品結算日
						return -1;  //返回 -1 (表示此週商品已經過期)
					}
					
					iWeekDay = (iWeekDay > iDays) ? iDays : iDay;
					cContract = new DateTime(iYear, month, iWeekDay);
				} else {
					iDay = ((iDay > iDays) ? iDays : iDay);  //如果傳進來的月份為商品代號上的月份代碼轉換的, 就必須注意是否超過此月份的最大天數, 如果超過就需要修正
					cContract = new DateTime(iYear, month, iDay);
				}

				IContractTime cRule = cProperty.ContractRule as IContractTime;
				if (cRule != null) {
					ContractTime cContractTimes = cRule.GetContractTime(cContract);
					iRet = cContractTimes.Id;
				}
			}
			return iRet;
		}
Ejemplo n.º 18
0
        /// <summary>
        ///   讀取指定資料夾內的所有交易所模組
        /// </summary>
        /// <param name="exchangeDirectory">資料夾名稱</param>
        public static void Load(string exchangeDirectory)
        {
            string[] sDllFiles = Directory.GetFiles(exchangeDirectory, "*.dll");

            int iLength = sDllFiles.Length;

            for (int i = 0; i < iLength; i++)
            {
                string sDllFile  = sDllFiles[i];
                string sPath     = Path.GetDirectoryName(sDllFile);
                string sAssembly = Path.GetFileNameWithoutExtension(sDllFile);

                Assembly cAssembly = Assembly.LoadFile(Path.GetFullPath(sDllFile));
                Type     cType     = cAssembly.GetType(sAssembly);

                AbstractExchange cExchange = Activator.CreateInstance(cType) as AbstractExchange;
                cExchange.Load();                       //讀取資訊
                cExchange.Initialize();                 //初始化交易所

                __current.AddExchange(cExchange);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///   從資料來源搜尋商品代號資訊
        /// </summary>
        /// <param name="symbolId">商品代號</param>
        /// <returns>返回值:DataSourceInformation類別列表</returns>
        public List <DataSourceInformation> SearchSymbolFromDataSource(string symbolId)
        {
            int iCount = __cQuoteServices.Count;
            List <DataSourceInformation> cDataSourceInfos = new List <DataSourceInformation>(iCount);

            for (int i = 0; i < iCount; i++)
            {
                AbstractQuoteService cQuoteService = __cQuoteServices[i];
                if (cQuoteService.Storage.IsSymbolExist(symbolId))
                {
                    AbstractExchange cExchange = ProductManager.Manager.GetExchange(cQuoteService.ExchangeName);
                    if (cExchange != null)
                    {
                        Product cProduct = cExchange.GetProduct(symbolId);
                        if (cProduct != null)
                        {
                            cDataSourceInfos.Add(new DataSourceInformation(cExchange.ShortName, cQuoteService, cProduct));
                        }
                    }
                }
            }
            return(cDataSourceInfos);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///   建構子
 /// </summary>
 /// <param name="exchange">交易所類別</param>
 /// <param name="products">商品資訊列表</param>
 public ProductInformation(AbstractExchange exchange, List <Product> products)
 {
     __cExchange = exchange;
     __cProducts = products;
 }
Ejemplo n.º 21
0
 internal MitakeSourceAdapter()
 {
     __cSymbolBuffer = new ZBuffer(1048576 * 5);
     __cExchange     = ProductManager.Manager.GetExchange("TWSE");
 }
Ejemplo n.º 22
0
                private void StockClient_onStock(object sender, StockEvent e) {
			switch (e.Header) {
				case 0x4d:  //Mcp命令封包回應解碼
					switch (e.Type) {
						case 0xf0:  //訂閱完成通知回應
						case 0xf1:  //回補完成通知回應
							int iSerial = e.Serial;
							if (iSerial > 0) {  //有股票流水號
								IQuote cQuote = null;
								switch(iSerial) {
									case 9998:  //OTC上櫃指數
									case 9999:  //TWI加權指數
										cQuote = MitakeStorage.Storage.GetIndex(iSerial);
										if (e.Type == 0xf1) {
											(cQuote as MitakeIndex).ComplementStatus = ComplementStatus.Complemented;
										}
										break;
									default:
										cQuote = MitakeStorage.Storage.GetQuote(iSerial);
										if (e.Type == 0xf1) {
											(cQuote as MitakeQuote).ComplementStatus = ComplementStatus.Complemented;
										}
										break;
								}
								
								if (cQuote != null) {
									if (e.Type == 0xf0) {
										OnSubscribeCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId));
									} else {
										OnComplementCompleted(new QuoteComplementCompletedEvent(this.ExchangeName, this.DataSource, cQuote.SymbolId));
									}
								}
							}
							break;
						case 0xf8:  //股票代號回補完畢通知回應
							this.IsLogin = true;  //設定登入完成的旗標
							if (this.IsUpdate) {  //是否要更新
								this.Save();  //更新報價服務器的設定值
							}
							
							string sName = this.ExchangeName;
							AbstractExchange cExchange = ProductManager.Manager.GetExchange(sName);
							if (cExchange.IsUpdate) {  //檢查是否需要更新交易所商品代號表
								cExchange.Save();  //如果要更新則儲存更新後的結果
							}
							
							//重新訂閱股票(因為有回補新的股票代號, 所以要全部重新訂閱)
							__cSubscribe = new Subscribe();  //重新建立新的訂閱陣列(登入的時候會重新傳入訂閱的股票代號, 避免期貨或選擇權換月後訂閱到舊的資訊而沒有報價)
							__cSubscribe.Add(0);  //先訂閱清盤資訊
							AddSubscribe(new List<string>(__cSymbolIds));
							
							if (logger.IsInfoEnabled) logger.Info("[QuoteService.Login] Login service success...");
							OnLoginCompleted();
							break;
					}
					break;
				case 0x53:  //股票資訊封包
					switch (e.Type) {
						case 0x00:  //收到清盤資訊
							__bReset = true;     //如果收到清盤指令, 設定旗標
							__bReseted = false;  //將已經清盤完畢的旗標清除

							ReLogin(); //重新登入伺服器
							break;
						case 0x31:  //即時成交資訊
						case 0xb1:  //即時成交資訊
						case 0x3e:  //即時成交資訊
						case 0xbe:  //即時成交資訊
						case 0x41:  //即時成交資訊
							if (sender == __cSocket) { //比較是否為即時Socket送來的資訊
								IQuote cQuote = MitakeStorage.Storage.GetQuote(e.Serial);
								if (cQuote != null) {
									OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cQuote));
								}
							}
							break;
						case 0x32:  //大盤指數資訊
						case 0x33:  //大盤成交金額資訊
						case 0x34:  //大盤委買委賣資訊
							if (sender == __cSocket) { //比較是否為即時Socket送來的資訊
								IQuote cIndex = MitakeStorage.Storage.GetIndex(e.Serial);
								if (cIndex != null) {
									OnQuote(new QuoteEvent(this.ExchangeName, this.DataSource, cIndex));
								}
							}
							break;
						case 0x35:  //即時公告資訊(三竹傳來的新聞或是公告)
							MitakeNotice cNotice = Decode_S35.Decode(e.Serial, e.Source);
							if (cNotice != null) {
								OnNotice(new QuoteNoticeEvent(this.DataSource, cNotice));
							}
							break;
					}
					break;
			}
		}
Ejemplo n.º 23
0
        private void toolItem_Modify_Click(object sender, EventArgs e)
        {
            ToolStripButton cButton = sender as ToolStripButton;
            int             iIndex  = int.Parse(cButton.Tag as string);

            string  sExchange   = null;
            string  sDataSource = null;
            Product cProduct    = null;
            AbstractProductProperty cProperty = null;

            switch (iIndex)
            {
            case 1:                      //新增
                frmCreateProduct frmCreateProduct = new frmCreateProduct();
                DialogResult     cResult          = frmCreateProduct.ShowDialog();
                if (cResult == DialogResult.OK)
                {
                    sDataSource = frmCreateProduct.DataSource;
                    sExchange   = frmCreateProduct.ExchangeName;
                    cProduct    = frmCreateProduct.Product;
                    cProperty   = frmCreateProduct.Property;

                    ESymbolCategory cCategory = cProduct.Category;
                    RefreshCategoryNode(sExchange, cCategory);                                 //更新樹狀結構
                    RefreshSymbolCategorys(sExchange, cCategory);                              //更新表格
                }
                break;

            case 2:                      //修改
            case 3:                      //刪除
                if (dataGrid.SelectedDataRows.Length > 0)
                {
                    object oData = dataGrid.SelectedDataRows[0];
                    if (oData != null)
                    {
                        _ProductInfo cProductInfo = oData as _ProductInfo;

                        string sSymbolId = cProductInfo.ProductId;
                        sExchange   = cProductInfo.ExchangeName;
                        sDataSource = cProductInfo.DataSource;
                        sDataSource = (sDataSource.Length == 0) ? null : sDataSource;
                        AbstractExchange cExchange = ProductManager.Manager.GetExchange(sExchange);
                        cProduct = cExchange.GetProduct(sSymbolId);

                        if (iIndex == 2)                                    //修改動作
                        {
                            cProperty = cExchange.GetProperty(sSymbolId, sDataSource);
                        }
                        else                                      //刪除動作
                        {
                            bool bDeleteProperty = sDataSource != null;
                            if (!bDeleteProperty)
                            {
                                DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_001, __sMessageHeader_001, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                bDeleteProperty |= cDeleteResult == DialogResult.Yes;
                            }

                            if (bDeleteProperty)
                            {
                                DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_002, __sMessageHeader_002, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (cDeleteResult == DialogResult.Yes)
                                {
                                    cExchange.RemoveProperty(sSymbolId, sDataSource);                                              //要先移除屬性設定(因為屬性會從 Product 結構取得商品資訊, 所以要先移除屬性設定)
                                }

                                if (sDataSource == null)                                            //如果資料報價來源是 null 才可以移除商品(如果為 null 會詢問使用者是否要刪除)
                                {
                                    cExchange.RemoveProduct(sSymbolId);
                                }

                                ESymbolCategory cCategory = cProduct.Category;
                                RefreshCategoryNode(sExchange, cCategory);                                             //更新樹狀結構
                                RefreshSymbolCategorys(sExchange, cCategory);                                          //更新表格
                            }
                            return;
                        }
                    }
                }
                break;
            }

            if (cProduct != null && cProperty != null)
            {
                frmProductPropertySettings frmProductPropertySettings = new frmProductPropertySettings();
                frmProductPropertySettings.SetParameters(sExchange, sDataSource, cProduct, cProperty.Clone());
                DialogResult cResult = frmProductPropertySettings.ShowDialog();
                if (cResult == DialogResult.OK)
                {
                    string          sExchangeName = __cSelectedNode.Parent.Text;
                    ESymbolCategory cCategory     = (ESymbolCategory)__cSelectedNode.Tag;

                    RefreshSymbolCategorys(sExchangeName, cCategory);                      //更新表格
                }
            }
        }
Ejemplo n.º 24
0
        private static void AddProductToExchange(MitakeSymbolInformation symbolInformation, string commodityId)
        {
            ESymbolCategory cCategory = ESymbolCategory.Stock;

            switch (symbolInformation.市場別)
            {
            case 0:                      //集中市場
            case 1:                      //上櫃市場
                string sType = ((symbolInformation.市場別 == 0) ? "TSE" : "OTC");
                commodityId = string.Format("{0}_STOCK", sType);

                switch (symbolInformation.市場分類)
                {
                case 3:                                  //基金
                    cCategory   = ESymbolCategory.Spread;
                    commodityId = string.Format("{0}_{1}", sType, "SPREAD");
                    break;

                case 4:                                  //認股權證
                    cCategory   = ESymbolCategory.Warrant;
                    commodityId = string.Format("{0}_{1}", sType, "WARRANT");
                    break;

                case 9:                                  //中央政府公債
                    cCategory   = ESymbolCategory.Bond;
                    commodityId = string.Format("{0}_{1}", sType, "BOND");
                    break;

                case 10:                                  //富時指數(TW50)
                    cCategory   = ESymbolCategory.Index;
                    commodityId = "INDEX";
                    break;
                }
                break;

            case 2:                      //期貨市場
                switch (symbolInformation.市場分類)
                {
                case 1:                                 //一般期貨
                case 3:                                 //期貨股票
                    cCategory = ESymbolCategory.Future;
                    if (symbolInformation.市場分類 == 3)
                    {
                        commodityId = "STOCK_FUTURE";
                    }
                    break;

                case 2:                                  //選擇權
                    if (MitakeSymbolManager.IsIndexOption(commodityId))
                    {
                        cCategory = ESymbolCategory.IndexOption;
                    }
                    else
                    {
                        cCategory = ESymbolCategory.StockOption;
                    }
                    break;
                }
                break;
            }

            if (commodityId == null)
            {
                commodityId = "UNKNOWN";
            }

            string           sExchangeName = MitakeSymbolManager.ExchangeName;
            AbstractExchange cExchange     = ProductManager.Manager.GetExchange(sExchangeName);

            cExchange.AddProduct(new Product()
            {
                CommodityId = commodityId,
                Category    = cCategory,
                SymbolId    = symbolInformation.SymbolId,
                SymbolName  = symbolInformation.SymbolName
            });
        }
Ejemplo n.º 25
0
        internal static void Convert(DateTime date, bool isDownload = true)
        {
            string[] sData = LoadRPT(date, isDownload);
            if (sData == null)
            {
                return;
            }

            double           dVolume = 0;
            bool             bConvert = false;
            string           sEDate = string.Empty;
            string           sOSymbolId = string.Empty;
            string           sDate = date.ToString("yyyyMMdd");
            SeriesSymbolData cMSeries = null, cDSeries = null;

            if (logger.IsInfoEnabled)
            {
                logger.Info("[Convert] 開始轉換期交所的期貨資訊...");
            }

            int iLength = sData.Length;

            for (int i = 1; i < iLength; i++)
            {
                string[] sItems = sData[i].Split(',');
                if (sItems.Length == 9)
                {
                    string sFutureDate = sItems[0].Trim();
                    if (!sFutureDate.Equals(sDate))                        //檢查日期是否為欲轉換的日期
                    {
                        continue;
                    }

                    string sSymbolId = sItems[1].Trim();
                    if (!sSymbolId.Equals(sOSymbolId))
                    {
                        if (bConvert)
                        {
                            FileAdapter cAdapter = new FileAdapter(Settings.GlobalSettings.Settings.DataPath, false);
                            cAdapter.Write(cMSeries);
                            cAdapter.Write(cDSeries);
                        }

                        dVolume    = 0;
                        sOSymbolId = sSymbolId;

                        string sTWSymbolId = null;
                        bConvert = cTargetSymbols.TryGetValue(sSymbolId, out sTWSymbolId);
                        if (bConvert)
                        {
                            cMSeries = CreateSeries(sTWSymbolId, EResolution.Minute, date);
                            cDSeries = CreateSeries(sTWSymbolId, EResolution.Day, date);

                            if (ConvertParameter.強制今日為期權到期日)
                            {
                                sEDate = DateTime.Now.Year.ToString() + ConvertParameter.自訂期權合約月份.ToString("0#");
                            }
                            else
                            {
                                AbstractExchange        cExchange     = ProductManager.Manager.GetExchange("TWSE");
                                AbstractProductProperty cProperty     = cExchange.GetProperty(sTWSymbolId);
                                IContractTime           cContractTime = cProperty.ContractRule as IContractTime;
                                ContractTime            cContract     = cContractTime.GetContractTime(date);

                                sEDate = cContract.MaturityDate.ToString("yyyyMM");
                            }
                        }
                    }

                    if (bConvert)
                    {
                        string sEndDate = sItems[2].Trim();
                        if (sEndDate.Length == 6 && sEndDate.Equals(sEDate))
                        {
                            Tick cTick = new Tick();
                            cTick.Time   = DateTimeParser.Parse(sItems[0], sItems[3]);
                            cTick.Price  = double.Parse(sItems[4]);
                            cTick.Single = double.Parse(sItems[5]) / 2;                              //Buy + Sell(需要除以2)
                            dVolume     += cTick.Single;
                            cTick.Volume = dVolume;

                            cMSeries.Merge(cTick);
                            cDSeries.Merge(cTick);
                        }
                    }
                }
            }

            if (bConvert)
            {
                FileAdapter cAdapter = new FileAdapter(Settings.GlobalSettings.Settings.DataPath, false);
                cAdapter.Write(cMSeries);
                cAdapter.Write(cDSeries);
            }
        }