public DSWebClient( DataProvider provider) { webClient = new WebClient( ); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted); this.provider = provider; //webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(webClient_DownloadDataCompleted); }
public static void UnRegisterHandler(DataProvider dp) { List<IHandler> hdlList = new List<IHandler>(); lock (locker) { if (hdlQueue.Count > 0) { while (hdlQueue.Count > 0) { hdlList.Add(hdlQueue.Dequeue()); } int index = -1; for (int i = 0; i < hdlList.Count; i++) { IHandler h = hdlList[i]; if (((ProviderHandler)h).Provider == dp) { h.IsProcessing = false; h = null; index = i; break; } } if (index > 0) hdlList.RemoveAt(index); foreach (IHandler hdl in hdlList) hdlQueue.Enqueue(hdl); } } }
public static void CleanTmpDirs(DataProvider provider) { StringBuilder sb = new StringBuilder(FxpaSource.folderPath); sb.Append(SEPARATOR).Append(provider.Symbol.ToString()); sb.Append(SEPARATOR).Append(provider.CurrentTInterval.ToString()); sb.Append(SEPARATOR).Append(TMP); DeleteDirectory(sb.ToString()); }
public static string GetLocalPath( DataProvider provider) { StringBuilder sb = new StringBuilder(FxpaSource.folderPath); sb.Append(SEPARATOR).Append(provider.Symbol.ToString()); sb.Append(SEPARATOR).Append(provider.CurrentTInterval.ToString()); sb.Append(SEPARATOR).Append(LOCAL); CreateDirectory(sb.ToString()); return sb.ToString(); }
public DataCache(DataProvider dp) { provider = dp; // 180,000 means 30 mins // 360,000 means 1 hour //timer = new System.Timers.Timer(5000); //timer.Elapsed += new System.Timers.ElapsedEventHandler(SaveDataToFile); //timer.AutoReset = true; //timer.Enabled = true; //timer.Stop(); }
private void UpdateIntervalData(Interval intervSpan, ref IntervalData intvData, double[] prices, DateTime time, DataProvider provider) { if (currentTimes.ContainsKey(intervSpan) && currentDatas.ContainsKey(intervSpan)) { DateTime lastTime = currentTimes[intervSpan]; DateTime currTime = AppUtil.GetCurrentIntervalTime(lastTime, time, intervSpan); TimeSpan span = time.Subtract(lastTime); Console.WriteLine(" currentTimes[TInterval.MIN1] span " + span + " lastTime " + lastTime + " real time " + time + " currTime " + currTime); LogUtil.Info(" currentTimes[TInterval.MIN1] span " + span + " lastTime " + lastTime + " real time " + time + " currTime " + currTime); if (lastTime.CompareTo(time) > 0) { return; } else if (span >= AppConst.AppTimeSpans[intervSpan]) { lastTime = AppUtil.GetLatestIntervalTime(lastTime, time, intervSpan); Console.WriteLine(" span > interval span::: " + span + " lastTime " + lastTime + " real time " + time); BarData barData = dataUnits[intervSpan][dataUnits[intervSpan].Count - 1]; barData.DateTime = lastTime; barData.Open = intvData.Open; barData.Close = intvData.Close; barData.Low = intvData.Min; barData.High = intvData.Max; barData.SignalList = intvData.SignalList; Console.WriteLine(" BarData #### time " + barData); List<CandleSignal> currSignalList = new List<CandleSignal>(); Signal[] signals = null; lock (AppConst.SignalDatasLocker) { signals = new Signal[AppContext.SignalDatas.Count]; AppContext.SignalDatas.CopyTo(signals); } if (signals != null) { int count = 0; Array.Sort(signals); foreach (Signal s in signals) { if (s.Symbol == provider.Symbol && s.Interval == provider.CurrentTInterval) { if (s.ActTime.CompareTo(lastTime) == 0 && s.Arrow != 0) { CandleSignal cs = new CandleSignal(s, 1); if (!barData.SignalList.Contains(cs)) barData.SignalList.Add(cs); } if (s.Arrow != 0 && s.ActTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 1); currSignalList.Add(cs); } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); if (!barData.SignalList.Contains(cs)) barData.SignalList.Add(cs); } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); currSignalList.Add(cs); } if (s.GainTip != 0 && s.GainTipTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); if (!barData.SignalList.Contains(cs)) barData.SignalList.Add(cs); } if (s.GainTip != 0 && s.GainTipTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); currSignalList.Add(cs); } if (s.StopGain != 0 && s.StopGainTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); if (!barData.SignalList.Contains(cs)) barData.SignalList.Add(cs); } if (s.StopGain != 0 && s.StopGainTime.CompareTo(currTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); currSignalList.Add(cs); } if (count > 5) break; count++; } } } barData.RefreshExValues(); Console.WriteLine(" BarData ############ time " + barData); LogUtil.Info(" Last BarData ##### " + barData); SAR sar = null; CR cr = null; RSI rsi = null; RSI rsi2 = null; RSI rsi3 = null; RSI rsi4 = null; ARBR arbr = null; ARBR arbr2 = null; CCI cci = null; CCI cci2 = null; CCI cci3 = null; WR wr = null; WR wr2 = null; LWR lwr = null; BOLL boll = null; if (!provider.Initializing && provider.Initialized) { sar = iSARs[intervSpan]; cr = iCRs[intervSpan]; rsi = iRISs[intervSpan]; rsi2 = iRISs2[intervSpan]; rsi3 = iRISs3[intervSpan]; rsi4 = iRISs4[intervSpan]; arbr = iARBRs[intervSpan]; arbr2 = iARBRs2[intervSpan]; cci = iCCIs[intervSpan]; cci2 = iCCIs2[intervSpan]; cci3 = iCCIs3[intervSpan]; wr = iWRs[intervSpan]; wr2 = iWRs2[intervSpan]; lwr = iLWRs[intervSpan]; boll = iBOLLs[intervSpan]; sar.handleFullCandle(ref barData); rsi.handleFullCandle(ref barData, true,1); rsi2.handleFullCandle(ref barData, true,2); rsi3.handleFullCandle(ref barData, true,3); rsi4.handleFullCandle(ref barData, true,4); cr.handleFullCandle(ref barData); arbr.handleFullCandle(ref barData,1); arbr2.handleFullCandle(ref barData,2); cci.handleFullCandle(ref barData,1); cci2.handleFullCandle(ref barData,2); cci3.handleFragCandle(ref barData, 3); wr.handleFullCandle(ref barData,1); wr2.handleFullCandle(ref barData,2); lwr.handleFullCandle(ref barData, 0); boll.handleFullCandle(ref barData, 0); } if (dataUnits.ContainsKey(intervSpan)) { dataUnits[intervSpan][dataUnits[intervSpan].Count - 1] = (barData); } else { List<BarData> list = new List<BarData>(); list.Add(barData); dataUnits.Add(intervSpan, list); } if (provider.CurrentTInterval == intervSpan) { provider.IsUpdateCandle = false; provider.IsAddCandle = true; } Console.WriteLine(" New BarData #### time " + currTime); currentTimes[intervSpan] = currTime; Console.WriteLine(" currentTimes[" + intervSpan + "] " + currentTimes[intervSpan]); Console.WriteLine(" NEW RTD.symbol time " + time + " price " + prices[0]); intvData = new IntervalData(0); double p = prices[0]; intvData.Max = p; intvData.Min = p; intvData.Open = p; intvData.Close = p; intvData.PriceList.Clear(); foreach (double price in prices) { intvData.PriceList.Add(price); intvData.Max = Math.Max(intvData.Max, price); intvData.Min = Math.Min(intvData.Min, price); } barData = new BarData(currTime, intvData.Open, intvData.Close, intvData.Min, intvData.Max, 0); barData.SignalList = currSignalList; barData.RefreshExValues(); if (!provider.Initializing && provider.Initialized) { barData.Sar = sar.getNextSAR(); rsi.handleFullCandle(ref barData, false, 1); rsi2.handleFullCandle(ref barData, false, 2); rsi3.handleFullCandle(ref barData, false, 3); rsi4.handleFullCandle(ref barData, false, 4); cr.handleFullCandle(ref barData); cci.handleFragCandle(ref barData,2); cci2.handleFragCandle(ref barData,2); iSARs[intervSpan] = sar; iRISs[intervSpan] = rsi; iRISs2[intervSpan] = rsi2; iRISs3[intervSpan] = rsi3; iRISs4[intervSpan] = rsi4; iCRs[intervSpan] = cr; iARBRs[intervSpan] = arbr; iARBRs2[intervSpan] = arbr2; iCCIs[intervSpan] = cci; iCCIs2[intervSpan] = cci2; iCCIs3[intervSpan] = cci3; iWRs[intervSpan] = wr; iWRs2[intervSpan] = wr2; iLWRs[intervSpan] = lwr; iBOLLs[intervSpan]=boll; } LogUtil.Info(" New BarData #### " + barData); dataUnits[intervSpan].Add(barData); Console.WriteLine(" New intvData ############ op " + intvData.Open + " cls " + intvData.Close + " max " + intvData.Max + " low " + intvData.Min); Console.WriteLine(" allDataUnits[provider.Symbol][intervSpan]..Count ::::::::::::::::::::::::::: " + dataUnits[intervSpan].Count); } else { Console.WriteLine(" IN currentTimes[" + intervSpan + "] " + currentTimes[intervSpan]); foreach (double price in prices) { intvData.PriceList.Add(price); intvData.Max = Math.Max(intvData.Max, price); intvData.Min = Math.Min(intvData.Min, price); } Signal[] signals = null; lock (AppConst.SignalDatasLocker) { signals = new Signal[AppContext.SignalDatas.Count]; AppContext.SignalDatas.CopyTo(signals); } if (signals != null) { Array.Sort(signals); int count = 0; foreach (Signal s in signals) { if (s.Symbol == provider.Symbol && s.Interval == provider.CurrentTInterval) { if (s.Arrow != 0 && s.ActTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 1); if (!intvData.SignalList.Contains(cs)) intvData.SignalList.Add(cs); } if (s.GainTip != 0 && s.GainTipTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 2); if (!intvData.SignalList.Contains(cs)) intvData.SignalList.Add(cs); } if (s.StopLoss != 0 && s.StopLossTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 3); if (!intvData.SignalList.Contains(cs)) intvData.SignalList.Add(cs); } if (s.StopGain != 0 && s.StopGainTime.CompareTo(lastTime) == 0) { CandleSignal cs = new CandleSignal(s, 4); if (!intvData.SignalList.Contains(cs)) intvData.SignalList.Add(cs); } if (count > 5) break; count++; } } } intvData.Close = intvData.PriceList.Last<double>(); //intvData.isInitialized = true; if (provider.CurrentTInterval == intervSpan) { provider.IsUpdateCandle = true; provider.IsAddCandle = false; } LogUtil.Info(" Updated intvData ############ " + intvData); } Console.WriteLine(" Update intvData ############ op " + intvData.Open + " cls " + intvData.Close + " max " + intvData.Max + " low " + intvData.Min); //} //intvData.isUpdated = true; } }
public AnalyzerSession CreateSimulationSession( SessionInfo sessionInfo) { AnalyzerSession session = new AnalyzerSession(sessionInfo); DataProvider dataProvider = null; lock (this) { if (AppContext.FirstDataProvider != null) { dataProvider = AppContext.FirstDataProvider; // new DataProvider(sessionInfo.Symbol); dataProvider.Run(); } else { dataProvider = new DataProvider(sessionInfo.Symbol); dataProvider.Init(); } session.Initialize(dataProvider); _existingSessions.Add(session); } // comment by Harry //GeneralHelper.SafeEventRaise(SessionsUpdateEvent, this); return session; }
public static void UnRegisterDataProvider(DataProvider dataProvider) { lock (activeProviders) { if (activeProviders.ContainsKey(dataProvider.Symbol)) { activeProviders.Remove(((DataProvider)dataProvider).Symbol); symbolDatas.Remove(((DataProvider)dataProvider).Symbol); activeProvider = null; symList.Remove(((DataProvider)dataProvider).Symbol); } } }
public static void RegisterDataProvider(DataProvider provider) { lock (activeProviders) { //Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@ " + provider.Symbol); if (!activeProviders.ContainsKey(provider.Symbol)) { activeProviders.Add(provider.Symbol, provider); symbolDatas.Add(provider.Symbol, new List<RealTimeData>()); activeProvider = provider; symList.Add(provider.Symbol); } } }
public ProviderHandler(DataProvider provider) : base() { this.provider = provider; this.MsgUpdateEvent += new MsgUpdatedDelegate(provider.RetrieveCdlFileAndLatestRtd); }
public static string GetTmpSigFilePath(DataProvider provider) { StringBuilder sb = new StringBuilder(FxpaSource.folderPath); sb.Append(SEPARATOR).Append(provider.Symbol.ToString()); sb.Append(SEPARATOR).Append(provider.CurrentTInterval.ToString()); sb.Append(SEPARATOR).Append(TMP); CreateDirectory(sb.ToString()); sb.Append(SEPARATOR).Append(provider.Symbol.ToString()).Append(DOT).Append(SIG); return sb.ToString(); }