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;
                        }
                    }
                }
            }
        }
        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();
            }
        }
Beispiel #3
0
		private SeriesSymbolDataRand InternalGetSeries(InstrumentDataRequest dataRequest, bool useCache) {
			SeriesStorage cStorage = null;
			string sLSymbolId = dataRequest.Symbol.ToLower();
			lock (__cStorages) {
				if (!__cStorages.TryGetValue(sLSymbolId, out cStorage)) {
					cStorage = new SeriesStorage(16);
					__cStorages.Add(sLSymbolId, cStorage);
				}
			}

			SeriesSymbolDataRand cSeriesRand = null;
			int iTotalSeconds = dataRequest.Resolution.TotalSeconds;
			if (useCache) {  //是否使用快取
				lock (cStorage) {  //需要 lock 這個區塊(避免非同步讀取資料時發生問題)
					int iBaseSeconds = (iTotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? Resolution.MIN_BASE_TOTALSECONDS : Resolution.MAX_BASE_TOTALSECONDS;
					SeriesSymbolData cSeries = cStorage.GetSeries(iTotalSeconds);
					if (cSeries == null) {
						cSeries = cStorage.GetSeries(iBaseSeconds);
						if (cSeries == null) {
							DataAdapter cAdapter = LoadAdapter(ref dataRequest);
							cSeries = cAdapter.Series;
							cStorage.Add(cSeries);
						}
					}

					if (iBaseSeconds == iTotalSeconds) {
						dataRequest = cSeries.DataRequest;
						goto exit;
					} else {
						cSeries = cSeries.CreateSeries(dataRequest); //利用基礎周期建立其他的資料周期
						cStorage.Add(cSeries);  //加入至 SeriesStorage
					}

					dataRequest.Resolution = cSeries.DataRequest.Resolution;  //將目標的週期結構更新至傳入的 InstrumentDataRequest 週期結構
					
					DataRequestEvent cRequestEvent = new DataRequestEvent(dataRequest);
					cSeries.OnRequest(cRequestEvent);  //如果已經存在則請求使用者需要的歷史資料區間(請求方法會檢查目前已下載的歷史資料區間是否足夠, 如果使用者需要的歷史資料區間比較大會向伺服器請求)
					dataRequest.Range.Count = cRequestEvent.Count;  //將請求後的正確數量傳入至結構內
				exit:
					cSeriesRand = new SeriesSymbolDataRand(cSeries, dataRequest);
				}
			} else {
				DataAdapter cAdapter = LoadAdapter(ref dataRequest, false);  //重新建立新的基礎週期序列資料(不使用快取, 不保存至快取內, 使用完畢之後立即 Dispose)
				SeriesSymbolData cSeries = cAdapter.Series;  //取得新的基礎周期序列資料

				int iBaseSeconds = (iTotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? Resolution.MIN_BASE_TOTALSECONDS : Resolution.MAX_BASE_TOTALSECONDS;
				if (iBaseSeconds == iTotalSeconds) {
					dataRequest = cSeries.DataRequest;
				} else {
					SeriesSymbolData cTargetSeries = cSeries.CreateSeries(dataRequest);  //使用 InstrumentDataRequest 建立新的其他週期序列資料
					cSeries.Merge(cTargetSeries);  //將基礎周期序列資料合併至新的其他週期序列資料
					cSeries.Dispose();  //釋放基礎周期序列資料

					cSeries = cTargetSeries;
				}

				cSeriesRand = new SeriesSymbolDataRand(cSeries, dataRequest);
				cStorage.Add(cSeries, true);  //保存序列資料(存放在 SeriesStorage 內的序列資料才會自動合併最新的即時資訊報價)
				cAdapter.Dispose();  //釋放資料配置者類別
			}
			return cSeriesRand;
		}
Beispiel #4
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);
            }
        }