コード例 #1
0
 public CandleSignal(Signal signal, int code)
 {
     Arrow = signal.Arrow;
     ArrowTime = signal.ActTime;
     switch (code)
     {
         case 1:
             SignalPrice = signal.ActPrice;
             break;
         case 2:
             SignalPrice = signal.GainTipPrice;
             break;
         case 3:
             SignalPrice = signal.StopLossBidPrice;
             break;
         case 4:
             SignalPrice = signal.StopGainPrice;
             break;
     }
     Code =signal.Arrow * code;
 }
コード例 #2
0
 private void SupplementSignals(Signal s)
 {
     s.Symbol = provider.Symbol;
     s.Interval = provider.CurrentTInterval;
 }
コード例 #3
0
        //object sender, System.Timers.ElapsedEventArgs e)
        private void SaveDataToFile()
        {
            if (provider.Initialized && !isSavingFile && dataUnits.ContainsKey(provider.CurrentTInterval))
            {
                isSavingFile = true;
                DateTime now = DateTime.Now;
                Console.WriteLine(" isSavingFile%%%%%%%%%%% ::: " + isSavingFile + " " + now.Second + " " + now.Millisecond);

                Interval interval;
                string tmpPath;
                string tmpCdlFile;
                string tmpSigFile;
                string dataFile;
                lock (provider)
                {
                    //ProviderHelper.CleanTmpDirs(provider);
                    tmpPath = ProviderHelper.GetTmpPath(provider);
                    tmpCdlFile = ProviderHelper.GetTmpCdlFilePath(provider);
                    tmpSigFile = ProviderHelper.GetTmpSigFilePath(provider);
                    dataFile = ProviderHelper.GetDataFilePath(provider);
                    Console.WriteLine(" dataFile ::: " + dataFile + " tmpFile ::: " + tmpCdlFile + " tmpPath :: " + tmpPath + " tmpSigFile   " + tmpSigFile);
                    interval = provider.CurrentTInterval;
                }

                List<BarData> intervDatas = new List<BarData>();
                lock (dataUnits[interval])
                {
                    intervDatas.AddRange(dataUnits[interval]);
                }

                List<Signal> signalDatas = new List<Signal>();
                lock (signalUnits[interval])
                {
                    signalDatas.AddRange(signalUnits[interval]);
                }

                if (intervDatas.Count - OFFSET > BASE)
                {
                    if (intervDatas.Count - OFFSET > MAXIMUM)
                    {
                        int rmc = intervDatas.Count - OFFSET - MAXIMUM;
                        intervDatas.RemoveRange(0, rmc);
                    }
                    intervDatas.RemoveRange(intervDatas.Count - OFFSET, OFFSET);
                    BarData firstData = intervDatas.First();

                    List<Signal> ctxSignals = new List<Signal>();

                    lock (AppConst.SignalDatasLocker)
                    {
                        foreach (Signal s in AppContext.SignalDatas)
                        {
                            if (s.Symbol == provider.Symbol && s.Interval == provider.CurrentTInterval)
                                ctxSignals.Add(s);
                        }
                    }

                    ctxSignals.Sort();
                    ctxSignals.Reverse();

                    foreach (Signal s in ctxSignals)
                    {
                        if (s.ProfitPrice == 0)
                            break;
                        if (!signalDatas.Contains(s))
                            signalDatas.Add(s);
                    }

                    List<Signal> obsletes = new List<Signal>();
                    foreach (Signal s in signalDatas)
                    {
                        if (s.ProfitTime.CompareTo(firstData.DateTime) < 0)
                            obsletes.Add(s);
                    }

                    foreach (Signal s in obsletes)
                    {
                        signalDatas.Remove(s);
                    }
                }

                if (intervDatas.Count > 0) // Initialized
                {
                    Console.WriteLine(" intervDatas.Count ::: " + intervDatas.Count);
                    BarData[] barDatas = new BarData[intervDatas.Count];
                    intervDatas.CopyTo(barDatas);
                    Console.WriteLine(" barDatas.Count ::: " + barDatas.Length);
                    DateTime newLastTime = intervDatas.Last<BarData>().DateTime;

                    IFileWorker fw = FileUtil.GetFileWorker();
                    Signal[] signals = null;
                    lock (signalUnits[interval])
                    {
                        signals = new Signal[signalUnits[interval].Count];
                        signalUnits[interval].CopyTo(signals);
                    }

                    signalUnits[interval].CopyTo(signals);

                    fw.SaveCdlFile(tmpCdlFile, barDatas, true);
                    fw.SaveSigFile(tmpSigFile, signals, true);
                    fw.ZipFiles(tmpPath, dataFile, null);
                    fw = null;
                    lastCdlTimes[interval] = newLastTime;
                    ProviderHelper.CleanTmpDirs(provider);
                }
                isSavingFile = false;
                now = DateTime.Now;
                Console.WriteLine(" isSavingFile%%%%%%%%%%% ::: " + isSavingFile + " " + now.Second + " " + now.Millisecond);
            }
        }
コード例 #4
0
        public void InitSignalUnits(List<Signal> sigList)
        {
            if (signalUnits.ContainsKey(provider.CurrentTInterval))
            {
                Signal[] signals = new Signal[sigList.Count];
                sigList.CopyTo(signals);
                Array.Sort(signals);
                Array.Reverse(signals);
                foreach (Signal s in signals)
                {
                    if (!signalUnits[provider.CurrentTInterval].Contains(s))
                        signalUnits[provider.CurrentTInterval].Add(s);
                }

                //signalUnits[provider.CurrentTInterval].AddRange(sigList);
                Console.WriteLine("   His signalUnits count >>>>>>>>>>>>>>>>>> " + signalUnits[provider.CurrentTInterval].Count);
            }
            else
            {
                signalUnits.Add(provider.CurrentTInterval, sigList);
                Console.WriteLine("   His signalUnits count >>>>>>>>>>>>>>>>>>  " + signalUnits[provider.CurrentTInterval].Count);
            }
        }
コード例 #5
0
        private void StatListUpdate()
        {
            if (AppContext.SignalDatas.Count > 0)
            {
                Signal[] signals = new Signal[AppContext.SignalDatas.Count];
                AppContext.SignalDatas.CopyTo(signals);

                if (signals.Length > 0)
                {
                    lock (AppConst.StatListLocker)
                    {
                        AppContext.StatListView.Items.Clear();
                        foreach (Signal signal in signals)
                        {
                            if (AppSetting.SYMBOLS.Contains(signal.Symbol))
                            {
                                string strSignal = AppUtil.GetSignalChinese(signal.Arrow);
                                ListViewItem item = null; int arrow = signal.Arrow == -1 ? 0 : 1;
                                if (signal.ProfitPrice <= 0)
                                    item = new ListViewItem(new string[] { signal.Symbol.ToString(), signal.ActPrice.ToString(), strSignal, signal.ActTime.ToString(), "", "" }, arrow);
                                else
                                    item = new ListViewItem(new string[] { signal.Symbol.ToString(), signal.ActPrice.ToString(), strSignal, signal.ActTime.ToString(), signal.ProfitTime.ToString(), signal.Profit.ToString() }, arrow);
                                AppContext.StatListView.Items.Add(item);
                            }
                        }
                    }
                }
            }
            else
            {
                AppContext.StatListView.Items.Clear();
            }
        }
コード例 #6
0
 private void SignalListUpdate()
 {
     if (AppContext.SignalDatas.Count > 0)
     {
         Signal[] signals = new Signal[AppContext.SignalDatas.Count];
         AppContext.SignalDatas.CopyTo(signals);
         Array.Sort(signals);
         lock (AppConst.SignalListLocker)
         {
             AppContext.SignalListView.Items.Clear();
             foreach (Signal signal in signals)
             {
                 if (AppSetting.SYMBOLS.Contains(signal.Symbol))
                 {
                     string strSignal = AppUtil.GetSignalChinese(signal.Arrow);
                     ListViewItem item = new ListViewItem(
                         new string[] {signal.Symbol.ToString(),
                   signal.ActPrice.ToString(), strSignal, signal.ActTime.ToString(), signal.StopLossPrice.ToString() }, 0);
                     AppContext.SignalListView.Items.Add(item);
                 }
             }
         }
     }
     else
     {
         AppContext.SignalListView.Items.Clear();
     }
 }
コード例 #7
0
        private void PriceListUpdate()
        {
            if (AppContext.SignalDatas.Count > 0)
            {
                Signal[] signals = new Signal[AppContext.SignalDatas.Count];
                AppContext.SignalDatas.CopyTo(signals);

                if (signals != null && signals.Length > 0)
                {
                    for (int i = 0; i < AppContext.PriceListView.Items.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(priceListView.Items[i].SubItems[0].Text))
                        {
                            AppContext.PriceListView.Items[i].SubItems[2].Text = "";
                            AppContext.PriceListView.Items[i].SubItems[3].Text = "";
                        }
                    }

                    foreach (Signal signal in signals)
                    {
                        if (AppSetting.SYMBOLS.Contains(signal.Symbol))
                        {
                            int arrowCount, profit;
                            for (int i = 0; i < priceListView.Items.Count; i++)
                            {
                                string strSymbol = priceListView.Items[i].SubItems[0].Text;
                                string cnSymbol = AppConst.AppCnSymbols[signal.Symbol];
                                if (cnSymbol != null && strSymbol != null && cnSymbol.Trim() == strSymbol.Trim())
                                {
                                    lock (AppConst.PriceListLocker)
                                    {
                                        string ac = priceListView.Items[i].SubItems[2].Text;
                                        arrowCount = string.IsNullOrEmpty(ac) ? 0 : int.Parse(ac.Trim());
                                        string pft = priceListView.Items[i].SubItems[3].Text;
                                        profit = string.IsNullOrEmpty(pft) ? 0 : int.Parse(pft.Trim());

                                        Console.WriteLine("  Symbol := " + strSymbol + " Count:= " + arrowCount + "  Profit  := " + profit);
                                        priceListView.Items[i].SubItems[2].Text = (arrowCount + 1).ToString();
                                        priceListView.Items[i].SubItems[3].Text = (profit + signal.Profit).ToString();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {  // Clean obslete datas
                for (int i = 0; i < AppContext.PriceListView.Items.Count; i++)
                {
                    if (!string.IsNullOrEmpty(priceListView.Items[i].SubItems[0].Text))
                    {
                        AppContext.PriceListView.Items[i].SubItems[2].Text = "";
                        AppContext.PriceListView.Items[i].SubItems[3].Text = "";
                    }
                }
            }
        }
コード例 #8
0
 public bool SaveSigFile(string fpath, Signal[] signals, bool isEncrypt)
 {
     try
        {
        using (StreamWriter writer = new StreamWriter(fpath, false))
        {
            int i = 0;
            DateTime start = System.DateTime.Now;
            Console.WriteLine(" start  " + start);
            foreach (Signal signal in signals)
            {
                StringBuilder sb = new StringBuilder(signal.ActTime.ToString(FORMAT));
                sb.Append(",").Append(signal.Arrow.ToString());
                sb.Append(",").Append(signal.ActPrice.ToString());
                sb.Append(",").Append(signal.GainTip);
                sb.Append(",").Append(signal.GainTipPrice);
                if (signal.GainTip != 0 && signal.GainTipPrice > 0) sb.Append(",").Append(signal.GainTipTime.ToString(FORMAT));
                else sb.Append(",").Append(NULL);
                sb.Append(",").Append(signal.StopGain);
                sb.Append(",").Append(signal.StopGainPrice);
                if (signal.StopGain != 0 && signal.StopGainPrice > 0) sb.Append(",").Append(signal.StopGainTime.ToString(FORMAT));
                else sb.Append(",").Append(NULL);
                sb.Append(",").Append(signal.StopLoss);
                sb.Append(",").Append(signal.StopLossBidPrice);
                if (signal.StopLoss != 0) sb.Append(",").Append(signal.StopLossTime.ToString(FORMAT));
                else sb.Append(",").Append(NULL);
                sb.Append(",").Append(signal.Profit);
                sb.Append(",").Append(signal.ProfitPrice);
                //if (signal.ProfitPrice > 0) sb.Append(",").Append(signal.ProfitTime.ToString(FORMAT));
                //else sb.Append(",").Append(NULL);
                //string endata = crypta.localEncrypt(sb.ToString());
                //string endata = sb.ToString();
                //Console.WriteLine(" endata    " + endata);
                i++;
                writer.WriteLine(sb.ToString());
                //}
            }
            DateTime end = System.DateTime.Now; Console.WriteLine(" end  " + end + "  count   " + i);
            Console.WriteLine(" use @@@@@@@@@@@@@@@@  " + (end.Subtract(start)));
            writer.Close();
        }
        }
        catch (Exception e)
        {
        Console.WriteLine(" e.StackTrace    " + e.StackTrace);
        return false;
        }
        return true;
 }
コード例 #9
0
        public override void Receive(object msg)
        {
            Console.WriteLine(" SignalListHandler  Receive ~~~~~~~~~~~ " + msg);
            string[] msgs = (string[])msg;
            Protocol protocol = AppUtil.ParseProtocol(msgs[1]);

            int paramAmount = int.Parse(msgs[2]);
            if (paramAmount > 0)
            {
                AppContext.SignalDatas.Clear();
                try
                {
                    for (int i = 3; i < msgs.Length; i++)
                    {
                        string signalInfo = msgs[i];
                        if (!string.IsNullOrEmpty(signalInfo))
                        {
                            string[] info = signalInfo.Split(',');
                            Signal signal = new Signal();
                            signal.Interval = AppUtil.StringToInterval(info[0]);
                            signal.Symbol = AppUtil.ParseSymbol(info[1]);
                            signal.ActPrice = double.Parse(info[2]);
                            signal.Arrow = AppUtil.StringToInt(info[3]);
                            signal.ActTime = DateTime.Parse(info[4]);
                            signal.StopLossPrice = double.Parse(info[5]);
                            if (NULL != info[6])
                            {
                                signal.StopLossTime = DateTime.Parse(info[6]);
                                signal.StopLoss = signal.Arrow;
                                signal.StopLossBidPrice = double.Parse(info[13]);
                            }
                            signal.GainTipPrice = double.Parse(info[7]);
                            if (NULL != info[8])
                            {
                                signal.GainTipTime = DateTime.Parse(info[8]);
                                signal.GainTip = signal.Arrow;
                            }
                            signal.StopGainPrice = double.Parse(info[9]);
                            if (NULL != info[10])
                            {
                                signal.StopGainTime = DateTime.Parse(info[10]);
                                signal.StopGain = signal.Arrow;
                            }
                            signal.Profit = int.Parse(info[11]);
                            signal.ProfitPrice = double.Parse(info[13]);
                            if (signal.ProfitPrice != 0 && NULL != info[12]) signal.ProfitTime = DateTime.Parse(info[12]);
                            AppContext.SignalDatas.Add(signal);
                        }
                    }
                }
                catch (Exception e)
                {
                    LogUtil.Error("  M0004  " + e.StackTrace);
                }
            }
            signals = new Signal[AppContext.SignalDatas.Count];
            AppContext.SignalDatas.CopyTo(signals);
            MethodInvoker mi = new MethodInvoker(InitPriceList);
            priceListView.Invoke(mi);
            mi = new MethodInvoker(InitSignalList);
            signalListView.Invoke(mi);
            mi = new MethodInvoker(InitStatList);
            statListView.Invoke(mi);
            mi = new MethodInvoker(RefreshStatBtn);
            AppContext.TradeExpertControl.Invoke(mi);
        }
コード例 #10
0
        public override void Receive(object msg)
        {
            Console.WriteLine(" ProviderHandler  Receive ~~~~~~~~~~~ " + provider.Symbol + "  Start  " + System.DateTime.Now.ToLongTimeString());

            if (provider != null)
            {
                string[] msgs = (string[])msg;

                Protocol protocol = AppUtil.ParseProtocol(msgs[1]);
                int paramAmount = AppUtil.StringToInt(msgs[2]);
                Console.WriteLine(" ProviderHandler  Receive ~~~~~~~~~~~ " + protocol);
                switch (protocol)
                {
                    case Protocol.M0003_1:
                        Execute();
                        if (paramAmount > 0 && !msgs.Contains<string>(NULL))
                        {
                            List<BarData> rtdDatas = new List<BarData>();
                            AppUtil.ParseRtd(ref rtdDatas, 3, msgs, protocol);
                            if (rtdDatas.Count > 0)
                            {
                                provider.StartTime = rtdDatas[rtdDatas.Count - 1].DateTime.Add(AppConst.AppTimeSpans[provider.CurrentTInterval]);
                                provider.DataCache.InitDataUnits(rtdDatas);
                                provider.InitCdlStatus = DataInitStatus.Initialized;

                            }
                            LogUtil.Info(" C0003_1  ::::: URL count " + rtdDatas.Count);
                        }
                        else
                        {
                            provider.HisUri = null;
                            provider.StartTime = provider.LocalLastCdlTime;
                            provider.CdlLoadingStatus = DownloadStatus.Finished;
                            provider.InitCdlStatus = DataInitStatus.Initialized;
                        }
                        IsGetHisInfo = true;
                        Execute();
                        //provider.DataCache.StartTime = provider.StartTime;
                        //provider.DataCache.Init();
                        Process(null);
                        break;
                    case Protocol.C0003_2:
                        if (paramAmount != AppUtil.PARSE_ERROR && paramAmount > 0)
                        {
                            List<BarData> rtdDatas = new List<BarData>();
                            AppUtil.ParseRtd(ref rtdDatas, 3, msgs, protocol);
                            provider.LatesRtds = rtdDatas;
                            provider.RtdLoadingStatus = DownloadStatus.Finished;
                            provider.InitRtdStatus = DataInitStatus.Initialized;
                        }
                        else
                        {
                            provider.RtdLoadingStatus = DownloadStatus.Failed;
                            provider.InitRtdStatus = DataInitStatus.Initialized;
                        }
                        IsGetRealTimeInfo = true;
                        break;
                    case Protocol.C0004_2:
                        if (paramAmount > 0)
                        {
                            List<Signal> sigalList = new List<Signal>();
                            for (int i = 3; i < msgs.Length; i++)
                            {
                                string signalInfo = msgs[i ];
                                if (!string.IsNullOrEmpty(signalInfo))
                                {
                                    string[] info = signalInfo.Split(',');
                                    Signal signal = new Signal();
                                    signal.Interval = AppUtil.StringToInterval(info[0]);
                                    signal.Symbol = AppUtil.ParseSymbol(info[1]);
                                    signal.ActPrice = double.Parse(info[2]);
                                    signal.Arrow = AppUtil.StringToInt(info[3]);
                                    signal.ActTime = DateTime.Parse(info[4]);
                                    signal.StopLossPrice = double.Parse(info[5]);
                                    if (NULL != info[6])
                                    {
                                        signal.StopLossTime = DateTime.Parse(info[6]);
                                        signal.StopLoss = signal.Arrow;
                                        signal.StopLossBidPrice = double.Parse(info[13]);
                                    }
                                    signal.GainTipPrice = double.Parse(info[7]);
                                    if (NULL != info[8])
                                    {
                                        signal.GainTipTime = DateTime.Parse(info[8]);
                                        signal.GainTip = signal.Arrow;
                                    }
                                    signal.StopGainPrice = double.Parse(info[9]);
                                    if (NULL != info[10])
                                    {
                                        signal.StopGainTime = DateTime.Parse(info[10]);
                                        signal.StopGain = signal.Arrow;
                                    }
                                    signal.Profit = int.Parse(info[11]);
                                    if (signal.Profit != 0 && NULL != info[12]) signal.ProfitTime = DateTime.Parse(info[12]);
                                    signal.ProfitPrice = double.Parse(info[13]);
                                    sigalList.Add(signal);
                                }
                            }
                            //provider.SignalList = sigalList;
                            //AppContext.FirstDataProvider.DataCache.InitSignalUnits(sigalList);
                            provider.DataCache.InitSignalUnits(sigalList);
                        }
                        provider.InitSigStatus = DataInitStatus.Initialized;
                        IsGetSignalInfo = true;
                        break;
                    default:
                        IsGetHisInfo = true;
                        provider.HisUri = null;
                        provider.StartTime = provider.LocalLastCdlTime;
                        provider.CdlLoadingStatus = DownloadStatus.Failed;
                        provider.InitCdlStatus = DataInitStatus.Initialized;
                        IsGetRealTimeInfo = true;
                        provider.RtdLoadingStatus = DownloadStatus.Failed;
                        provider.InitRtdStatus = DataInitStatus.Initialized;
                        IsProcessing = false;
                        break;
                }
                Console.WriteLine(" ProviderHandler  Receive ~~~~~~~~~~~ " + provider.Symbol + "  After operation  " + System.DateTime.Now.ToLongTimeString());
            }
        }
コード例 #11
0
        private void UpdateStatListView(object obj)
        {
            List<Signal> datas = ((List<Signal>)obj);
            if (datas.Count > 0)
            {
                Signal[] signals = null;
                lock (AppConst.SignalDatasLocker)
                {
                    signals = new Signal[datas.Count];
                    datas.CopyTo(signals, 0);
                    Array.Sort(signals);
                }

                lock (AppConst.StatListLocker)
                {
                    AppContext.StatListView.Items.Clear();
                    foreach (Signal signal in signals)
                    {
                        string strSignal = AppUtil.GetSignalChinese(signal.Arrow);
                        ListViewItem item = null; int arrow = signal.Arrow == -1 ? 0 : 1;
                        if (signal.ProfitPrice > 0)
                            item = new ListViewItem(new string[] { signal.Symbol.ToString(), signal.ActPrice.ToString(), strSignal, signal.ActTime.ToString(), signal.ProfitTime.ToString(), signal.ProfitPrice.ToString(), signal.Profit.ToString() }, arrow);
                        else
                            item = new ListViewItem(new string[] { signal.Symbol.ToString(), signal.ActPrice.ToString(), strSignal, signal.ActTime.ToString(), "", "", "" }, arrow);

                        if (signal.ProfitPrice <= 0)
                        {
                            item.BackColor = Color.MediumPurple;
                            int count = item.SubItems.Count - 1;
                            while (count >= 1)
                            {
                                item.SubItems[count].BackColor = Color.MediumPurple;
                                count--;
                            }
                        }
                        AppContext.StatListView.Items.Add(item);
                    }
                }
            }
            else
            {
                AppContext.StatListView.Items.Clear();
            }
        }
コード例 #12
0
        public override void Receive(object msg)
        {
            string[] msgs = (string[])msg;

            Protocol protocol = AppUtil.ParseProtocol(msgs[1]);
            int paramAmount = AppUtil.StringToInt(msgs[2]);
            if (protocol != Protocol.UNKNOWN)
            {
                if ( msgs.Length >= 4)
                {
                    LogUtil.Info(" Signal content " + msgs[3]);
                    string[] info = msgs[3].Split(',');
                    if (info.Length >= 2)
                    {
                        Interval interval = AppUtil.StringToInterval(info[0]);
                        Symbol symbol = AppUtil.ParseSymbol(info[1]);
                        try
                        {
                            switch (protocol)
                            {
                                case Protocol.K0004_1: // Arrow Signal
                                    if (!AppContext.IsReconnecting && AppContext.IsPriceListInitialized &&
                                        AppContext.IsSignalListInitialized)
                                    {
                                        if (!msgs.Contains(NULL))
                                        {
                                            Signal signal = new Signal();
                                            signal.Interval = interval;
                                            signal.Symbol = symbol;
                                            signal.ActPrice = double.Parse(info[2]);
                                            signal.Arrow = int.Parse(info[3]);
                                            signal.ActTime = DateTime.Parse(info[4]);
                                            signal.StopLossPrice = double.Parse(info[5]);
                                            Console.WriteLine(Protocol.K0004_1+"  " + signal);
                                            LogUtil.Info(Protocol.K0004_1 + "  " + signal);
                                            if (AppSetting.SYMBOLS.Contains(signal.Symbol) && AppSetting.INTEVALS.Contains(signal.Interval))
                                            {
                                                SignalProcess(signal, protocol);
                                            }
                                        }
                                    }
                                    break;
                                case Protocol.K0004_2:  // Stop Loss Signal
                                    if (!AppContext.IsReconnecting && AppContext.IsPriceListInitialized &&
                                        AppContext.IsSignalListInitialized)
                                    {
                                        if (!msgs.Contains(NULL))
                                        {
                                            Signal signal = new Signal();
                                            signal.Interval = interval;
                                            signal.Symbol = symbol;
                                            signal.StopLossBidPrice = double.Parse(info[2]);
                                            signal.StopLoss = int.Parse(info[3]);
                                            signal.Arrow = int.Parse(info[3]);
                                            signal.StopLossTime = DateTime.Parse(info[4]);
                                            signal.ActTime = DateTime.Parse(info[5]);
                                            Console.WriteLine(Protocol.K0004_2 + "  " + signal);
                                            LogUtil.Info(Protocol.K0004_2 + "  " + signal);
                                            if (signal.StopLossBidPrice > 0 && signal.StopLoss != 0)
                                            SignalProcess(signal, protocol);
                                        }
                                    }
                                    break;
                                case Protocol.K0004_3:  // Gain Tip Signal
                                    if (!AppContext.IsReconnecting && AppContext.IsPriceListInitialized &&
                                        AppContext.IsSignalListInitialized)
                                    {
                                        if (!msgs.Contains(NULL))
                                        {
                                            Signal signal = new Signal();
                                            signal.Interval = interval;
                                            signal.Symbol = symbol;
                                            signal.GainTip = int.Parse(info[2]);
                                            signal.Arrow = int.Parse(info[2]);
                                            signal.GainTipTime = DateTime.Parse(info[3]);
                                            signal.ActTime = DateTime.Parse(info[4]);
                                            signal.GainTipPrice = double.Parse(info[5]);
                                            Console.WriteLine(Protocol.K0004_3 + "  " + signal);
                                            LogUtil.Info(Protocol.K0004_3 + "  " + signal);
                                            if (signal.GainTipPrice > 0)
                                            SignalProcess(signal, protocol);
                                        }
                                    }
                                    break;
                                case Protocol.K0004_4:  // Stop Gain Signal
                                    if (!AppContext.IsReconnecting && AppContext.IsPriceListInitialized &&
                                        AppContext.IsSignalListInitialized)
                                    {
                                        if (!msgs.Contains(NULL))
                                        {
                                            Signal signal = new Signal();
                                            signal.Interval = interval;
                                            signal.Symbol = symbol;
                                            signal.StopGainPrice = double.Parse(info[2]);
                                            signal.StopGain = int.Parse(info[3]);
                                            signal.Arrow = int.Parse(info[3]);
                                            signal.StopGainTime = DateTime.Parse(info[4]);
                                            signal.ActTime = DateTime.Parse(info[5]);
                                            Console.WriteLine(Protocol.K0004_4 + "  " + signal);
                                            LogUtil.Info(Protocol.K0004_4 + "  " + signal);
                                            if (signal.StopGainPrice > 0)
                                            SignalProcess(signal, protocol);
                                        }
                                    }
                                    break;
                                case Protocol.K0004_5:  // Profit Signal
                                    if (!AppContext.IsReconnecting && AppContext.IsPriceListInitialized &&
                                        AppContext.IsSignalListInitialized)
                                    {
                                        if (!msgs.Contains(NULL))
                                        {
                                            Signal signal = new Signal();
                                            signal.Interval = interval;
                                            signal.Symbol = symbol;
                                            signal.Arrow = int.Parse(info[2]);
                                            signal.ActTime = DateTime.Parse(info[3]);
                                            signal.Profit = int.Parse(info[4]);
                                            signal.ProfitTime = DateTime.Parse(info[5]);
                                            signal.ProfitPrice = double.Parse(info[6]);
                                            Console.WriteLine(Protocol.K0004_5 + "  " + signal);
                                            LogUtil.Info(Protocol.K0004_5 + "  " + signal);
                                            if(signal.ProfitPrice >0)
                                            SignalProcess(signal, protocol);
                                        }
                                    }
                                    break;
                            }
                        }
                        catch (Exception e)
                        {
                            LogUtil.Error(" Protocol " + protocol.ToString()+ e.StackTrace);
                        }
                    }
                }
            }
        }
コード例 #13
0
        private void StatlListUpdate(object obj)
        {
            Dictionary<Protocol, Signal> protocolSignal = (Dictionary<Protocol, Signal>)obj;
            Protocol protocol = (Protocol)protocolSignal.Keys.First();
            Signal signal = (Signal)protocolSignal.Values.First();
            if (AppSetting.SYMBOLS.Contains(signal.Symbol))
            {
                if (signal.Arrow != 0 && protocol == Protocol.K0004_1)
                {
                    LogUtil.Info("StatlListUpdate signal.Arrow != 0 && protocol ==" + Protocol.K0004_1);
                    Signal[] signals = null;
                    lock (AppConst.SignalDatasLocker)
                    {
                        signals = new Signal[AppContext.SignalDatas.Count];
                        AppContext.SignalDatas.CopyTo(signals, 0);
                        Array.Sort(signals);
                    }

                    if (signals != null)
                    {
                        lock (AppConst.StatListLocker)
                        {
                            statListView.Items.Clear();
                            foreach (Signal sig in signals)
                            {
                                if (AppSetting.SYMBOLS.Contains(sig.Symbol))
                                {
                                    string strSignal = AppUtil.GetSignalChinese(sig.Arrow);
                                    ListViewItem item = new ListViewItem(
                                        new string[] {sig.Symbol.ToString(),
                                        sig.ActPrice.ToString(), strSignal, sig.ActTime.ToString(), "","", ""}, 25 + sig.Arrow);
                                    statListView.Items.Add(item);
                                }
                            }
                        }
                    }
                }
                else if (signal.ProfitPrice != 0 && protocol == Protocol.K0004_5)
                {
                    LogUtil.Info(" signal.Profit != 0  && protocol ==" + Protocol.K0004_5);
                    ListView.ListViewItemCollection items = statListView.Items;
                    for (int i = 0; i < items.Count; i++)
                    {
                        ListViewItem item = items[i];
                        if (item.SubItems.Count >= 5)
                        {
                            string strDate = item.SubItems[3].Text ?? "";
                            DateTime actTime;
                            DateTime.TryParse(strDate, out actTime);
                            if (actTime.CompareTo(signal.ActTime) == 0)
                            {
                                lock (AppConst.StatListLocker)
                                {
                                    item.SubItems[4].Text = signal.ProfitTime.ToString();
                                    item.SubItems[5].Text = signal.ProfitPrice.ToString();
                                    item.SubItems[6].Text = signal.Profit.ToString();
                                    int count = item.SubItems.Count - 1;
                                    while (count >= 0)
                                    {
                                        item.SubItems[count].BackColor = Color.Azure;
                                        count--;
                                    }
                                    items[i] = item;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #14
0
        private void SignalProcess(Signal signal, Protocol protocol)
        {
            Console.WriteLine(" Before Invoke control update ......   " + signal);
            bool dupli = false;
            bool isValid = false;
            for (int i = 0; i < AppContext.SignalDatas.Count; i++)
            {
                Signal sig = AppContext.SignalDatas[i];
                if (signal.Equals(sig))
                {
                    if (signal.Arrow == sig.Arrow && protocol == Protocol.K0004_1)
                    {
                        dupli = true;
                    }
                    else if (signal.StopLoss == sig.StopLoss && protocol == Protocol.K0004_2)
                    {
                        dupli = true;
                    }
                    else if (signal.GainTip == sig.GainTip && protocol == Protocol.K0004_3)
                    {
                        dupli = true;
                    }
                    else if (signal.StopGain == sig.StopGain && protocol == Protocol.K0004_4)
                    {
                        dupli = true;
                    }
                    else if (signal.ProfitPrice == sig.ProfitPrice && protocol == Protocol.K0004_5)
                    {
                        dupli = true;
                    }
                    else
                    {
                        if (signal.StopLoss != 0) { sig.StopLoss = signal.StopLoss; sig.StopLossTime = signal.StopLossTime; sig.StopLossBidPrice = signal.StopLossBidPrice; isValid = true; }
                        else if (signal.GainTip != 0) { sig.GainTip = signal.GainTip; sig.GainTipPrice = signal.GainTipPrice; sig.GainTipTime = signal.GainTipTime; isValid = true; }
                        else if (signal.StopGain != 0) { sig.StopGain = signal.StopGain; sig.StopGainPrice = signal.StopGainPrice; sig.StopGainTime = signal.StopGainTime; isValid = true; }
                        else if (signal.ProfitPrice > 0) { sig.Profit = signal.Profit; sig.ProfitPrice = signal.ProfitPrice; sig.ProfitTime = signal.ProfitTime; isValid = true;
                               DataProvider provider = DataService.GetProviderBySymbol(signal.Symbol);
                               if (provider != null && !provider.DataCache.SignalUnits[provider.CurrentTInterval].Contains(sig))
                               { provider.DataCache.SignalUnits[provider.CurrentTInterval].Add(sig); }
                        }
                        AppContext.SignalDatas[i] = sig;
                        LogUtil.Info(" AppContext.SignalDatas[i]  " + i +"  "+AppContext.SignalDatas[i]);
                    }
                    LogUtil.Info(" dupli ==============  " + dupli);
                    break;
                }
                if (i == AppContext.SignalDatas.Count - 1 && !dupli)
                {
                    isValid = true;
                }
            }

            if (!dupli)
            {
                if (protocol == Protocol.K0004_1)
                    AppContext.SignalDatas.Add(signal);

                if (isValid)
                {
                    Dictionary<Protocol, Signal> protocolSignal = new Dictionary<Protocol, Signal>();
                    protocolSignal.Add(protocol, signal);
                    MsgUpdatedDelegate d = null;
                    if (protocol != Protocol.K0004_5)
                    {
                        d = new MsgUpdatedDelegate(ProviderUpdate);
                        d.Invoke(protocolSignal);
                    }
                    if (protocol != Protocol.K0004_2 && protocol != Protocol.K0004_3)
                    {
                        d = new MsgUpdatedDelegate(SignalListUpdate);
                        signalListView.BeginInvoke(d, protocolSignal);
                    }
                    if (protocol == Protocol.K0004_5 || protocol == Protocol.K0004_1)
                    {
                        d = new MsgUpdatedDelegate(PriceListUpdate);
                        priceListView.BeginInvoke(d, protocolSignal);
                    }
                    if (protocol == Protocol.K0004_5 || protocol == Protocol.K0004_1)
                    {
                        d = new MsgUpdatedDelegate(StatlListUpdate);
                        statListView.BeginInvoke(d, protocolSignal);
                    }
                }
            }
        }
コード例 #15
0
        public bool LoadSigFile(string fileName, int startingRow, int rowsLimit, out List <Signal> datas, bool isDecrypt, bool isLocal)
        {
            datas = new List <Signal>();

            int i = 0;

            using (System.IO.TextReader tr = new System.IO.StreamReader(fileName))
            {
                try
                {
                    for (i = 0; i < startingRow + rowsLimit || rowsLimit == 0; i++)
                    {
                        string lineStr = tr.ReadLine();
                        if (lineStr == null)
                        {
                            break;
                        }

                        if (i >= startingRow)
                        {// Parse.
                         //if (isDecrypt)
                         //{
                         //    if (!isLocal)
                         //        lineStr = crypta.decrypt(lineStr);
                         //    else
                         //        lineStr = crypta.localDecrypt(lineStr);
                         //}

                            try
                            {
                                string[] lineSplit = Regex.Split(lineStr, ",");
                                Signal   signal    = new Signal();
                                signal.ActTime      = DateTime.Parse(lineSplit[0]);
                                signal.Arrow        = int.Parse(lineSplit[1]);
                                signal.ActPrice     = double.Parse(lineSplit[2]);
                                signal.GainTip      = int.Parse(lineSplit[3]);
                                signal.GainTipPrice = double.Parse(lineSplit[4]);
                                if (lineSplit[5] != NULL)
                                {
                                    signal.GainTipTime = DateTime.Parse(lineSplit[5]);
                                }
                                signal.StopGain      = int.Parse(lineSplit[6]);
                                signal.StopGainPrice = double.Parse(lineSplit[7]);
                                if (lineSplit[8] != NULL)
                                {
                                    signal.StopGainTime = DateTime.Parse(lineSplit[8]);
                                }
                                signal.StopLoss      = int.Parse(lineSplit[9]);
                                signal.StopLossPrice = double.Parse(lineSplit[10]);
                                if (lineSplit[11] != NULL)
                                {
                                    signal.StopLossTime     = DateTime.Parse(lineSplit[11]);
                                    signal.StopLossBidPrice = double.Parse(lineSplit[13]);
                                }
                                signal.Profit      = int.Parse(lineSplit[12]);
                                signal.ProfitPrice = double.Parse(lineSplit[13]);
                                if (lineSplit[14] != NULL)
                                {
                                    signal.ProfitTime = DateTime.Parse(lineSplit[14]);
                                }
                                LogUtil.Info(" Sig File Loading :::: " + signal);
                                datas.Add(signal);
                            }
                            catch (Exception e)
                            {
                                LogUtil.Info(" His File Loading :::: " + e.StackTrace);
                            }
                        }
                    }
                    Console.WriteLine("ccccccccccccccccccccccccccc  ");
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    datas.Clear();
                    return(false);
                }
            }
            return(true);
        }
コード例 #16
0
        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;
            }
        }
コード例 #17
0
        public void CheckInitStatus(object obj, System.Timers.ElapsedEventArgs e)
        {
            if (!Initializing)
               {
               lock (this)
               {
                   if (!Initialized && initCdlStatus == DataInitStatus.Initialized  &&
                      initRtdStatus == DataInitStatus.Initialized && initSigStatus == DataInitStatus.Initialized )
                   {
                       Initializing = true;
                       if( handler !=null )
                          handler.IsProcessing = false;
                       if (initRtdStatus == DataInitStatus.Initialized)
                       {
                           Console.WriteLine(" LatesRtds  count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + LatesRtds.Count);
                           LogUtil.Info(" LatesRtds  count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + LatesRtds.Count);
                           if (LatesRtds.Count > 0)
                           {
                              if (dataCache.DataUnits.ContainsKey(CurrentTInterval))
                               {
                                     dataCache.DataUnits[CurrentTInterval].AddRange(LatesRtds);
                               }
                               else
                               {
                                   dataCache.DataUnits.Add(CurrentTInterval, LatesRtds);
                               }
                               Console.WriteLine(" dataCache.DataUnits[CurrentTInterval].Count ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + dataCache.DataUnits[CurrentTInterval].Count);
                               LogUtil.Info(" dataCache.DataUnits[CurrentTInterval].Count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + dataCache.DataUnits[CurrentTInterval].Count);
                           }
                       }

                       RealTimeData[] rtds = null;
                       lock (dataCache.RealTimeDatas)
                       {
                           if (dataCache.RealTimeDatas.Count > 0)
                           {
                               rtds = new RealTimeData[dataCache.RealTimeDatas.Count];
                               dataCache.RealTimeDatas.CopyTo(rtds);
                               dataCache.RealTimeDatas.Clear();
                           }
                       }

                       if (dataCache.DataUnits[CurrentTInterval].Count > 0)
                       {
                           List<BarData> datas = dataCache.DataUnits[CurrentTInterval];
                           BarData lastBar = dataCache.DataUnits[CurrentTInterval][datas.Count - 1];
                           dataCache.RefreshCurrentTime(currentTInterval, lastBar.DateTime);
                           IntervalData data = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High);
                           dataCache.InitCurrentData(currentTInterval, data);
                           Console.WriteLine(" Last BAR  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + lastBar );
                           LogUtil.Info(" Last BAR  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + lastBar);
                           if (rtds != null && rtds.Length > 0)
                           {
                               Console.WriteLine(" dataCache.RealTimeDatas.  count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + rtds.Length);
                               LogUtil.Info(" dataCache.RealTimeDatas.  count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + rtds.Length);
                               Console.WriteLine(lastBar);
                               if (lastBar.IsCompleted)
                               {
                                   foreach (RealTimeData rtd in rtds)
                                   {
                                       dataCache.UpdateDataSource(rtd);
                                   }
                               }
                               else
                               {
                                   bool isCompleted = false;
                                   double max = lastBar.High;
                                   double min = lastBar.Low;
                                   List<double> prices = new List<double>();

                                   prices.Add(lastBar.Open);
                                   prices.Add(lastBar.Close);
                                   prices.Add(lastBar.Low);
                                   prices.Add(lastBar.High);

                                   for (int k = 0; k < rtds.Length; k++)
                                   {
                                       RealTimeData rtd = rtds[k];
                                       Console.WriteLine(" RealTimeData   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + rtd);
                                       LogUtil.Info(" RealTimeData   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + rtd);
                                       if (rtd.dateTime.CompareTo(lastBar.DateTime) < 0)
                                           continue;

                                       if (rtd.dateTime.Subtract(AppConst.AppTimeSpans[CurrentTInterval]) < lastBar.DateTime)
                                       {
                                           foreach (double price in rtd.datas)
                                           {
                                               prices.Add(price);
                                               max = Math.Max(max, price);
                                               min = Math.Min(min, price);
                                           }
                                           if (k == rtds.Length - 1 && prices.Count > 0)
                                           {
                                               lastBar.Close = prices[prices.Count - 1];
                                               lastBar.High = max;
                                               lastBar.Low = min;
                                               IntervalData newdata = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High);
                                               dataCache.InitCurrentData(currentTInterval, newdata);
                                               dataCache.DataUnits[CurrentTInterval][datas.Count - 1] = lastBar;
                                           }
                                       }
                                       else if (rtd.dateTime.Subtract(AppConst.AppTimeSpans[CurrentTInterval]) >= lastBar.DateTime)
                                       {
                                           if (!isCompleted)
                                           {
                                               if (prices != null && prices.Count > 0)
                                               {
                                                   lastBar.Close = prices[prices.Count - 1];
                                                   lastBar.High = max;
                                                   lastBar.Low = min;
                                                   prices.Clear();
                                               }
                                               lastBar.IsCompleted = true;
                                               dataCache.DataUnits[CurrentTInterval][datas.Count - 1] = lastBar;
                                               IntervalData newdata = new IntervalData(lastBar.Open, lastBar.Close, lastBar.Low, lastBar.High);
                                               dataCache.InitCurrentData(currentTInterval, newdata);
                                               isCompleted = true;
                                               dataCache.UpdateDataSource(rtd);
                                           }
                                           else
                                           {
                                               dataCache.UpdateDataSource(rtd);
                                           }
                                       }
                                   }
                               }
                           }

                           SAR sar = new SAR(symbol.ToString(), currentTInterval);
                           RSI rsi = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),6);
                           RSI rsi2 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),42);
                           RSI rsi3 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),14);
                           RSI rsi4 = new RSI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),22);
                           CR cr = new CR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)));
                           ARBR arbr = new ARBR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 26);
                           ARBR arbr2 = new ARBR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),42);
                           CCI cci = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 14);
                           //CCI cci2 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 42);
                           CCI cci2 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 24);
                           CCI cci3 = new CCI(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 42);
                           WR wr=new WR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)),14);
                           WR wr2 = new WR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 24);
            LWR lwr=new LWR(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 14, 3, 3);
            BOLL boll = new BOLL(symbol.ToString(), int.Parse(AppUtil.IntervalToString(currentTInterval)), 20);
                           for (int i = 0; i < datas.Count; i++)
                           {
                               BarData bar = datas[i];
                               if (bar.IsCompleted)
                               {
                                   sar.handleFullCandle(ref bar);
                                   rsi.handleFullCandle(ref bar, true, 1);
                                   rsi2.handleFullCandle(ref bar, true,2);
                                   rsi3.handleFullCandle(ref bar, true,3);
                                   rsi4.handleFullCandle(ref bar, true,4);
                                   cr.handleFullCandle(ref bar);
                                   arbr.handleFullCandle(ref bar, 1);
                                   arbr2.handleFullCandle(ref bar,2);
                                   cci.handleFullCandle(ref bar,1);
                                   cci2.handleFullCandle(ref bar,2);
                                   cci3.handleFullCandle(ref bar, 3);
                                   wr.handleFullCandle(ref bar, 1);
                                   wr2.handleFullCandle(ref bar,2);
                                   lwr.handleFullCandle(ref bar, 0);
                                   boll.handleFullCandle(ref bar, 0);
                                   datas[i] = bar;
                               }
                           }
                           dataCache.SARs[currentTInterval] = sar;
                           dataCache.RISs[currentTInterval] = rsi;
                           dataCache.RISs2[currentTInterval] = rsi2;
                           dataCache.RISs3[currentTInterval] = rsi3;
                           dataCache.RISs4[currentTInterval] = rsi4;
                           dataCache.CRs[currentTInterval] = cr;
                           dataCache.ARBRs[currentTInterval] = arbr;
                           dataCache.ARBRs2[currentTInterval] = arbr2;
                           dataCache.CCIs[currentTInterval] = cci;
                           dataCache.CCIs2[currentTInterval] = cci2;
                           dataCache.CCIs3[currentTInterval] = cci3;
                           dataCache.WRs[currentTInterval] = wr;
                           dataCache.WRs2[currentTInterval] = wr2;
                           dataCache.LWRs[currentTInterval] = lwr;
                           dataCache.BOLLs[currentTInterval] = boll;

                           List<Signal> signalList = dataCache.SignalUnits[currentTInterval];
                           LogUtil.Info(" SignalList  count  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + signalList.Count);

                           if (signalList.Count > 0)
                           {
                               Signal[] signals = new Signal[signalList.Count];
                               signalList.CopyTo(signals, 0);
                               Array.Sort(signals);
                               Array.Reverse(signals);
                               DateTime currentTime = dataCache.CurrentTimes[currentTInterval];
                               int startIndex = 0;
                               foreach (Signal signal in signals)
                               {
                                   DateTime actTime = signal.ActTime;

                                   for (int i = startIndex; i < dataCache.DataUnits[currentTInterval].Count; i++)
                                   {
                                       bool isUpdate = false;
                                       List<CandleSignal> sigList = new List<CandleSignal>();
                                       BarData candle = dataCache.DataUnits[currentTInterval][i];
                                       if (actTime.CompareTo(candle.DateTime) > 0)
                                       {
                                           continue;
                                       }
                                       else if (actTime.CompareTo(candle.DateTime) == 0)
                                       {
                                           startIndex = i;
                                           isUpdate = true;
                                           LogUtil.Info(" Signal " + signal );
                                           LogUtil.Info(" Candle " + candle);
                                          // LogUtil.Info(" bf1st " + dataCache.DataUnits[currentTInterval][i-1]);
                                           //LogUtil.Info(" bf2nd " + dataCache.DataUnits[currentTInterval][i-2]);
                                           CandleSignal cs = new CandleSignal(signal, 1);
                                           sigList.Add(cs);
                                       }
                                       if (signal.GainTip!=0 && signal.GainTipPrice > 0 && candle.DateTime.CompareTo(signal.GainTipTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 2);
                                           sigList.Add(cs);
                                           isUpdate = true;
                                       }
                                       if (signal.StopLoss != 0 && signal.StopLossBidPrice > 0 && candle.DateTime.CompareTo(signal.StopLossTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 3);
                                           sigList.Add(cs);
                                           isUpdate = true;
                                       }
                                       if (signal.StopGain != 0 &&  signal.StopGainPrice > 0 && candle.DateTime.CompareTo(signal.StopGainTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 4);
                                           sigList.Add(cs);
                                           isUpdate = true;
                                       }
                                       if (isUpdate)
                                       {
                                           if (candle.SignalList != null)
                                               candle.SignalList.AddRange(sigList);
                                           else
                                               candle.SignalList = sigList;
                                           candle.RefreshExValues();
                                           dataCache.DataUnits[currentTInterval][i] = candle;
                                       }
                                   }
                                   List<CandleSignal> sList = new List<CandleSignal>();
                                   if (signal.ActTime.CompareTo(currentTime) <= 0)
                                   {
                                       if (signal.ActTime.CompareTo(currentTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 1);
                                           sList.Add(cs);
                                       }
                                       if (signal.GainTipPrice > 0 && signal.GainTipTime.CompareTo(currentTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 2);
                                           sList.Add(cs);
                                       }
                                       if (signal.StopLossBidPrice > 0 && signal.StopLossTime.CompareTo(currentTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 3);
                                           sList.Add(cs);
                                       }
                                       if (signal.StopGainPrice > 0 && signal.StopGainTime.CompareTo(currentTime) == 0)
                                       {
                                           CandleSignal cs = new CandleSignal(signal, 4);
                                           sList.Add(cs);
                                       }
                                       dataCache.CurrentDatas[currentTInterval].SignalList.AddRange(sList);
                                   }
                               }
                           }
                           Console.WriteLine(" LAST ###### "+lastBar);
                           LogUtil.Info(" LAST ###### " + lastBar);

                           dataCache.RefreshDataUnits(datas);
                       }
                       //dataCache.Start();
                       if (AppContext.IsLoading)
                       {
                           AppContext.IsFirstProviderInit = true;
                           isAddCandle = true;
                           Initialized = true;
                           Initializing = false;
                           ProviderHelper.CleanInitDirs(this);
                       }
                       else
                       {
                           isAddCandle = true;
                           Initialized = true;
                           Process(null, null);
                           timerInit.Stop();
                           timerAuto.Start();
                           Initializing = false;
                           ProviderHelper.CleanInitDirs(this);
                           Console.WriteLine(" End  Now   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  " + DateTime.Now.ToLongTimeString());
                       }
                   }
               }
               }
        }
コード例 #18
0
        public bool LoadSigFile(string fileName, int startingRow, int rowsLimit, out List<Signal> datas, bool isDecrypt, bool isLocal)
        {
            datas = new List<Signal>();

               int i = 0;

               using (System.IO.TextReader tr = new System.IO.StreamReader(fileName))
               {
               try
               {
                   for (i = 0; i < startingRow + rowsLimit || rowsLimit == 0; i++)
                   {
                       string lineStr = tr.ReadLine();
                       if (lineStr == null)
                       {
                           break;
                       }

                       if (i >= startingRow)
                       {// Parse.
                           //if (isDecrypt)
                           //{
                           //    if (!isLocal)
                           //        lineStr = crypta.decrypt(lineStr);
                           //    else
                           //        lineStr = crypta.localDecrypt(lineStr);
                           //}

                           try
                           {
                               string[] lineSplit = Regex.Split(lineStr, ",");
                               Signal signal = new Signal();
                               signal.ActTime = DateTime.Parse(lineSplit[0]);
                               signal.Arrow = int.Parse(lineSplit[1]);
                               signal.ActPrice = double.Parse(lineSplit[2]);
                               signal.GainTip = int.Parse(lineSplit[3]);
                               signal.GainTipPrice = double.Parse(lineSplit[4]);
                               if (lineSplit[5] != NULL) signal.GainTipTime = DateTime.Parse(lineSplit[5]);
                               signal.StopGain = int.Parse(lineSplit[6]);
                               signal.StopGainPrice = double.Parse(lineSplit[7]);
                               if (lineSplit[8] != NULL) signal.StopGainTime = DateTime.Parse(lineSplit[8]);
                               signal.StopLoss = int.Parse(lineSplit[9]);
                               signal.StopLossPrice = double.Parse(lineSplit[10]);
                               if (lineSplit[11] != NULL)
                               {
                                   signal.StopLossTime = DateTime.Parse(lineSplit[11]);
                                   signal.StopLossBidPrice = double.Parse(lineSplit[13]);
                               }
                               signal.Profit = int.Parse(lineSplit[12]);
                               signal.ProfitPrice = double.Parse(lineSplit[13]);
                               if (lineSplit[14] != NULL) signal.ProfitTime = DateTime.Parse(lineSplit[14]);
                               LogUtil.Info(" Sig File Loading :::: " + signal);
                               datas.Add(signal);

                           }
                           catch (Exception e)
                           {
                               LogUtil.Info(" His File Loading :::: " + e.StackTrace);
                           }
                       }
                   }
                   Console.WriteLine("ccccccccccccccccccccccccccc  ");
               }
               catch (Exception exception)
               {
                   Console.WriteLine(exception.ToString());
                   datas.Clear();
                   return false;
               }
               }
               return true;
        }