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);
        }
Esempio 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;
            }
        }
Esempio n. 3
0
        internal frmProductRuleSettings(string exchangeName, ERuleType ruleType, AbstractProductProperty property)
        {
            InitializeComponent();

            __cRuleType = ruleType;
            __cProperty = property;

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

            __cRules = cExchange.GetRuleItems(ruleType);
        }
        private void CreateIndexOptions(DateTime date)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info("開始轉換指數型選擇權資料...");
            }

            List <string> cStocks = __cExchange.GetProductClassify(ESymbolCategory.IndexOption);

            foreach (string sStock in cStocks)
            {
                int iIndex = sStock.LastIndexOf(".");
                if (iIndex > -1)
                {
                    iIndex -= 2;
                    if (sStock[iIndex] >= 'A')
                    {
                        continue;                          //沒有轉換代號的選擇權全部都不要轉換
                    }
                }

                AbstractProductProperty cProperty = __cExchange.GetProperty(sStock, "Mitake");
                if (cProperty != null)
                {
                    IQuote cQuote = MitakeStorage.Storage.GetQuote(sStock);
                    if (cQuote != null)
                    {
                        SeriesSymbolData cMSeries = CreateSeries(sStock, EResolution.Minute, date);
                        SeriesSymbolData cDSeries = CreateSeries(sStock, EResolution.Day, date);

                        int iLast = cQuote.TickCount - 1;
                        if (iLast >= 0)
                        {
                            for (int i = iLast; i >= 0; i--)
                            {
                                ITick cTick = cQuote.GetTick(i);
                                if (cTick != null)
                                {
                                    cMSeries.Merge(cTick);
                                    cDSeries.Merge(cTick);
                                }
                            }

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

                            System.Console.Write("Convert... {0}        ", sStock);
                            System.Console.CursorLeft = 0;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
		/// <summary>
		///   設定 Instrument 資訊
		/// </summary>
		/// <param name="bars">Instrument 類別</param>
		/// <param name="data_stream">資料串流編號</param>
		public override void SetInstrument(Instrument bars, int data_stream) {
			base.SetInstrument(bars, data_stream);

			string sDecimal = Bars.Info.PriceScale.ToString();  //取得價格座標並轉換成字串
			int iIndex = sDecimal.IndexOf(".") + 1;  //搜尋小數點位數
			if (iIndex > 0) {
				__iDecimalPoint = sDecimal.Length - iIndex;  //計算小數位數
			}

			__cProperty = (Bars.Info as InstrumentSettings).Property;  //取得商品屬性
			__cCurrentPosition.SetBigPointValue(__cProperty.BigPointValue);  //設定每一大點的交易金額
		}
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
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);
            }
        }
        internal void SetParameters(string exchangeName, string dataSource, Product product, AbstractProductProperty property)
        {
            __sExchangeName = exchangeName;
            __sDataSource   = dataSource;
            __cProduct      = product;
            __cProperty     = property;

            //設定保證金資訊
            sourceCautions             = new SimpleBoundList <CautionMoney>(__cProperty.CautionMoneys);
            sourceCautions.AllowNew    = true;
            sourceCautions.AllowEdit   = true;
            sourceCautions.AllowDelete = true;

            //設定開收盤時間
            sourceSessions             = new SimpleBoundList <SessionObject>(__cProperty.Sessions);
            sourceSessions.AllowNew    = true;
            sourceSessions.AllowEdit   = true;
            sourceSessions.AllowDelete = true;
        }
Esempio n. 9
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;
        }
Esempio n. 10
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;
		}
Esempio n. 11
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);
            }
        }
Esempio n. 12
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);                      //更新表格
                }
            }
        }
Esempio n. 13
0
        private static _ProductInfo CreateProductInfo(string exchangeName, string dataSource, Product product, AbstractProductProperty property)
        {
            _ProductInfo cProductInfo = new _ProductInfo()
            {
                CommodityId  = (property == null) ? string.Empty : property.CommodityId,
                Description  = (property == null) ? string.Empty : property.Description,
                DataSource   = (dataSource == null) ? string.Empty : dataSource,
                ExchangeName = exchangeName,
                ProductId    = product.SymbolId,
                ProductName  = product.SymbolName
            };

            return(cProductInfo);
        }