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;
                        }
                    }
                }
            }
        }
예제 #2
0
        private static void ConvertCSV(string csvFile)
        {
            string[] sData = LoadCSV(csvFile);
            if (sData == null)
            {
                return;
            }

            bool             bConvert = false;
            SeriesSymbolData cMSeries = null, cDSeries = null;

            if (logger.IsInfoEnabled)
            {
                logger.Info("[Convert] 開始轉換 CSV 期貨檔案資訊...");
            }

            string[] sItems    = sData[0].Split(',');
            string   sSymbolId = null;

            bConvert = cTargetSymbols.TryGetValue(Path.GetFileNameWithoutExtension(csvFile), out sSymbolId);

            if (bConvert)
            {
                int iLength = sData.Length;
                cMSeries = CreateSeries(sSymbolId, EResolution.Minute);
                cMSeries.SetRange(iLength);
                cMSeries.AdjustSize(iLength, true);

                for (int i = iLength - 1; i >= 0; i--)
                {
                    sItems = sData[i].Split(',');
                    DateTime cTime   = DateTime.Parse(sItems[0]);
                    double   dOpen   = double.Parse(sItems[1]);
                    double   dHigh   = double.Parse(sItems[2]);
                    double   dLow    = double.Parse(sItems[3]);
                    double   dClose  = double.Parse(sItems[4]);
                    double   dVolume = double.Parse(sItems[5]);
                    cMSeries.AddSeries(cTime, dOpen, dHigh, dLow, dClose, dVolume, false);
                }

                cDSeries = CreateSeries(sSymbolId, EResolution.Day);
                cMSeries.Merge(cDSeries);

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

                cMSeries.Dispose();
                cDSeries.Dispose();
            }
        }
예제 #3
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);
            }
        }