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);
        }
Example #2
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();
		}
Example #3
0
		internal List<string> GetClassify(ESymbolCategory productType) {
			List<string> cSymbolIds = null;
			
			lock (__cKeys) {
				__cClassify.TryGetValue(productType, out cSymbolIds);
			}
			return cSymbolIds;
		}
Example #4
0
        internal List <string> GetClassify(ESymbolCategory productType)
        {
            List <string> cSymbolIds = null;

            lock (__cKeys) {
                __cClassify.TryGetValue(productType, out cSymbolIds);
            }
            return(cSymbolIds);
        }
Example #5
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);
			}
		}
        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);
            }
        }
        private void treeExchanges_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode cNode = e.Node;

            if (cNode.Tag == null)
            {
                return;
            }

            string          sExchangeName = cNode.Parent.Text;
            ESymbolCategory cCategory     = (ESymbolCategory)cNode.Tag;

            __cSelectedNode = cNode;

            RefreshSymbolCategorys(sExchangeName, cCategory);
        }
        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);
            }
        }
Example #9
0
        internal void Remove(Product product)
        {
            string sSymbolId = product.SymbolId;

            lock (__cKeys) {
                if (__cKeys.Contains(sSymbolId))
                {
                    ESymbolCategory cType = product.Category;

                    List <string> cList = null;
                    if (__cClassify.TryGetValue(cType, out cList))
                    {
                        cList.Remove(sSymbolId);                          //效率可能會比較慢(考量到股票支數可能不多, 所以還可以接受這樣的效率)
                    }
                    __cKeys.Remove(sSymbolId);
                }
            }
        }
Example #10
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;
        }
Example #11
0
        internal void Add(Product product)
        {
            string sSymbolId = product.SymbolId;

            lock (__cKeys) {
                if (!__cKeys.Contains(sSymbolId))
                {
                    ESymbolCategory cType = product.Category;

                    List <string> cList = null;
                    if (!__cClassify.TryGetValue(cType, out cList))
                    {
                        cList = new List <string>();
                        __cClassify.Add(cType, cList);
                    }

                    cList.Add(sSymbolId);
                    __cKeys.Add(sSymbolId);                      //將分類過的股票加入至 HashSet 避免加入到重複的股票
                }
            }
        }
Example #12
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
            });
        }
Example #13
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);                      //更新表格
                }
            }
        }
Example #14
0
 /// <summary>
 ///   取得商品
 /// </summary>
 /// <param name="productType">商品類型</param>
 /// <returns>返回值:此分類的商品代號列表</returns>
 public List <string> GetProductClassify(ESymbolCategory productType)
 {
     return __cProductClassify.GetClassify(productType);
 }
Example #15
0
		/// <summary>
		///   取得商品
		/// </summary>
		/// <param name="productType">商品類型</param>
		/// <returns>返回值:此分類的商品代號列表</returns>
		public List<string> GetProductClassify(ESymbolCategory productType) {
			return __cProductClassify.GetClassify(productType);
		}