Beispiel #1
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());
            }
        }
Beispiel #2
0
        public override void Execute()
        {
            IsProcessing = true;

            if (AppContext.FirstDataProvider != null &&
                AppContext.TradeAnalyzerControl == null)
            {
                // TO DO
            }
            else
            {
                if (!IsGetHisInfo)
                {
                    IsGetHisInfo = true;
                    string request = "";

                    Console.WriteLine(" ProviderHandler  Send ~~~~~~~~~~~  " + Protocol.M0003_1);
                    if (provider.HasLocalLastCdlTime)
                    {
                        request = NetHelper.BuildMsg(Protocol.M0003_1, new string[] { provider.Symbol.ToString(), AppUtil.IntervalToString(provider.CurrentTInterval), provider.LocalLastCdlTime.Add(AppConst.AppTimeSpans[provider.CurrentTInterval]).ToString(FORMAT) });
                    }
                    else
                    {
                        request = NetHelper.BuildMsg(Protocol.M0003_1, new string[] { provider.Symbol.ToString(), AppUtil.IntervalToString(provider.CurrentTInterval), NULL });
                    }
                    Send(request);
                }
                else if (!IsGetSignalInfo)
                {
                    IsGetSignalInfo = true;
                    Console.WriteLine(" ProviderHandler  Send ~~~~~~~~~~~   " + Protocol.C0004_2);
                    string   request = "";
                    DateTime time    = DateTime.Now;
                    //time = time.AddMonths(-6);
                    time = DateTime.Parse("2009-09-01 00:00:00");
                    if (provider.HasLocalLastSigTime)
                    {
                        request = NetHelper.BuildMsg(Protocol.C0004_2, new string[] { provider.Symbol.ToString(), AppUtil.IntervalToString(AppContext.FirstDataProvider.CurrentTInterval), provider.LocalLastSigTime.ToString(FORMAT) });
                    }
                    else
                    {
                        request = NetHelper.BuildMsg(Protocol.C0004_2, new string[] { provider.Symbol.ToString(), AppUtil.IntervalToString(AppContext.FirstDataProvider.CurrentTInterval), time.ToString(FORMAT) });
                    }
                    Send(request);
                }
                else if (!IsGetRealTimeInfo)
                {
                    IsGetRealTimeInfo = true;
                    Console.WriteLine(" ProviderHandler  Send ~~~~~~~~~~~  " + Protocol.C0003_2);
                    string request = NetHelper.BuildMsg(Protocol.C0003_2, new string[] { provider.Symbol.ToString(), AppUtil.IntervalToString(provider.CurrentTInterval), provider.StartTime.ToString(FORMAT) });
                    Send(request);
                }
            }
        }
Beispiel #3
0
        public override void Receive(object msg)
        {
            Console.WriteLine(" TimeCheckHandler  Receive ~~~~~~~~~~~ " + msg);
            string[] msgs = (string[])msg;

            Protocol protocol    = AppUtil.ParseProtocol(msgs[1]);
            int      paramAmount = AppUtil.StringToInt(msgs[2]);

            if (protocol != Protocol.UNKNOWN)
            {
                try
                {
                    switch (protocol)
                    {
                    case Protocol.S0002_1:
                        string   strServerTime = msgs[3];
                        DateTime serverTime;
                        serverTime = DateTime.Parse(strServerTime);

                        if (FXPA != null && !FXPA.IsDisposed)
                        {
                            if (!msgs.Contains(NULL))
                            {
                                if (serverTime.CompareTo(AppSetting.END_TIME) > 0)
                                {
                                    errCode = -1;
                                    MethodInvoker mi = new MethodInvoker(ShowErrorMsg);
                                    FXPA.BeginInvoke(mi);

                                    mi = new MethodInvoker(CloseApp);
                                    FXPA.BeginInvoke(mi);
                                }
                            }
                        }

                        int DAY = Convert.ToInt16(serverTime.Day);
                        AppContext.CURRENT_TIME = serverTime;

                        DateTime startTimeOfNormalDay = AppUtil.GetStartTimeOfNormalDay(AppContext.CURRENT_TIME);

                        if (DAY > LogUtil.DAY && serverTime.CompareTo(startTimeOfNormalDay) > 0)
                        {
                            MethodInvoker mi = new MethodInvoker(TimeLabelUpdate);
                            AppContext.TradeExpertControl.BeginInvoke(mi);
                            LogUtil.DAY = DAY;
                            LogUtil.Close();
                            LogUtil.init(true, true, true, true);
                        }
                        else if (DAY > AppContext.DAY)
                        {
                            AppContext.DAY = DAY;
                            DateTime      startTimeOfWeek   = AppUtil.GetStartTimeOfWeek(AppContext.CURRENT_TIME);
                            DateTime      startTimeOfBizDay = AppUtil.GetStartTimeOfBizToday(AppContext.CURRENT_TIME);
                            List <Signal> obsoletes         = new List <Signal>();
                            if (AppSetting.STATUS == AppSetting.TEST_ACCOUNT && serverTime.CompareTo(startTimeOfWeek) > 0)
                            {
                                if (AppContext.SignalDatas.Count > 0)
                                {
                                    lock (AppConst.SignalDatasLocker)
                                    {
                                        foreach (Signal signal in AppContext.SignalDatas)
                                        {
                                            if (signal.ProfitPrice != 0 && signal.ProfitTime.CompareTo(startTimeOfWeek) < 0)
                                            {
                                                obsoletes.Add(signal);
                                            }
                                        }
                                        foreach (Signal signal in obsoletes)
                                        {
                                            AppContext.SignalDatas.Remove(signal);
                                        }
                                    }
                                }
                            }
                            else if (serverTime.CompareTo(startTimeOfBizDay) > 0)
                            {
                                if (AppContext.SignalDatas.Count > 0)
                                {
                                    lock (AppConst.SignalDatasLocker)
                                    {
                                        foreach (Signal signal in AppContext.SignalDatas)
                                        {
                                            if (signal.ProfitPrice != 0 && signal.ProfitTime.CompareTo(startTimeOfBizDay) < 0)
                                            {
                                                obsoletes.Add(signal);
                                            }
                                        }
                                        foreach (Signal signal in obsoletes)
                                        {
                                            AppContext.SignalDatas.Remove(signal);
                                        }
                                    }
                                }
                            }

                            if (obsoletes != null && obsoletes.Count > 0)
                            {
                                MethodInvoker mi = new MethodInvoker(SignalListUpdate);
                                signalListView.BeginInvoke(mi);
                                mi = new MethodInvoker(StatListUpdate);
                                AppContext.StatListView.BeginInvoke(mi);
                                mi = new MethodInvoker(PriceListUpdate);
                                priceListView.BeginInvoke(mi);
                            }

                            obsoletes.Clear();
                            List <PublishInfo> obsoletes2 = new List <PublishInfo>();
                            if (AppContext.PublishInfos.Count > 0)
                            {
                                lock (AppContext.PublishInfos)
                                {
                                    foreach (PublishInfo info in AppContext.PublishInfos)
                                    {
                                        if (AppContext.CURRENT_TIME.Subtract(info.DateTime) > AppConst.AppTimeSpans[Interval.DAY1])
                                        {
                                            obsoletes2.Add(info);
                                        }
                                    }

                                    foreach (PublishInfo info in obsoletes2)
                                    {
                                        AppContext.PublishInfos.Remove(info);
                                    }
                                    if (obsoletes2 != null && obsoletes2.Count > 0)
                                    {
                                        MethodInvoker mi = new MethodInvoker(InfoListUpdate);
                                        infoListView.BeginInvoke(mi);
                                    }
                                }
                            }
                            obsoletes2.Clear();
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    LogUtil.Info(" TimeCheckHandler  Receive  Exception~~~~~~~~~~~ " + e.StackTrace);
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private void InitPriceList()
        {
            string[]      fxList      = Enum.GetNames(Symbol.AUDJPY.GetType());
            List <string> initSymbols = new List <string>();

            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)
                {
                    string symbol = signal.Symbol.ToString();
                    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();
                                    Console.WriteLine("  Symbol ==== " + symbol);
                                    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 = "";
                    }
                }
            }

            if (AppContext.IsGetSymbolPrices && AppContext.SymbolPrices.Count > 0)
            {
                foreach (KeyValuePair <string, double> pair in AppContext.SymbolPrices)
                {
                    string symbol = pair.Key;
                    double price  = pair.Value;

                    for (int i = 0; i < priceListView.Items.Count; i++)
                    {
                        string strSymbol = priceListView.Items[i].SubItems[0].Text;
                        string cnSymbol  = AppConst.AppCnSymbols[AppUtil.ParseSymbol(symbol)];
                        if (cnSymbol != null && strSymbol != null && cnSymbol.Trim() == strSymbol.Trim())
                        {
                            lock (AppConst.PriceListLocker)
                            {
                                Console.WriteLine("  Symbol := " + strSymbol + "  Price := " + price);
                                priceListView.Items[i].SubItems[1].Text = price.ToString();
                                break;
                            }
                        }
                    }
                }
                AppContext.IsGetSymbolPrices = false;
                AppContext.SymbolPrices.Clear();
            }
            AppContext.IsPriceListInitialized = true;
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        public FxAnalyzerControl(ProfessionalAnalyzer expert)
        {
            InitializeComponent();

            tradeAnalyzer = expert;
            tradeAnalyzer.SessionManager.SessionsUpdateEvent += new GeneralHelper.GenericDelegate <IAnalyzerSessionManager>(SessionManager_SessionUpdateEvent);

            //Adjust Listview column width
            priceListView_ColumnWidthChanged();

            DataService.priceList = priceListView;
            DataService.ImageList = imageList1;

            //设置数据源
            _host = tradeAnalyzer.SessionManager;

            _sessions = null;
            _sessions = FxpaSource.SessionList.ToArray();

            int i;

            for (i = 0; i < _sessions.Length; i++)
            {
                string symbol = AppUtil.GetSymbolChinese(_sessions[i].Symbol);
                if (symbol != "")
                {
                    ListViewItem p = new ListViewItem(new string[] { AppUtil.GetSymbolChinese(_sessions[i].Symbol), "", "", "" });
                    priceListView.Items.Add(p);
                }
            }

            //priceListView.Items.AddRange(p);

            // Comment by Harry
            //根据内容自动Adjust 列头大小
            //AutoResizeColumnWidth(priceListView);

            //
            DateTime now = DateTime.Now;

            //this.titleStrip1.HeaderText.Text = " " + now.ToString("MM dd, yyyy  " + AppConst.Days[Convert.ToInt16(now.DayOfWeek)]);
            //this.titleStrip1.HeaderText.Font = new Font(this.titleStrip1.HeaderText.Font, FontStyle.Bold);
            //this.titleStrip1.HeaderText.Margin = new Padding(10, 0, 0, 0);
            //this.titleStrip1.HeaderText.ForeColor = Color.FromArgb(91, 89, 91);
            timeLabel.Text = now.ToString("MM'月'dd' day ' " + AppConst.Days[Convert.ToInt16(now.DayOfWeek)]);
            //this.label1.Margin = new Padding(10, 0, 0, 0);
            //this.label1.ForeColor = Color.FromArgb(91, 89, 91);
            timeLabel.Refresh();

            AnalyzerSession session;

            foreach (SessionInfo sin in FxpaSource.AvailableSessionList)
            {
                aliveSessions.Add(sin.Symbol);
                session = _host.CreateSimulationSession(sin);
                break;
            }

            //AppContext.SignalHandler.PriceListView = priceListView;
            //AppContext.SignalHandler.AnalyzerControl = this;
            //AppContext.SignalListHandler.PriceListView = priceListView;
            //  AppContext.TimeCheckHandler.PriceListView = priceListView;
            AppContext.PriceListView        = priceListView;
            AppContext.TradeAnalyzerControl = this;
        }