Esempio n. 1
0
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <param name="fileName">文件名</param>
        public static void StartService()
        {
            ReadPlots();
            m_userCookieService   = new UserCookieService();
            m_exportService       = new ExportService();
            m_userSecurityService = new UserSecurityService();
            m_eMSecurityService   = new EMSecurityService();
            bool loadAll = EMSecurityService.Load();

            //BlockService.Load(loadAll);
            CFTService.Start();
            SecurityService.Start();
        }
        protected override bool DecodingBody(BinaryReader br)
        {
            byte market = br.ReadByte();

            byte[] buffer  = br.ReadBytes(0x10);
            byte[] srcCode = new byte[7];
            for (int i = 0; i < srcCode.Length; i++)
            {
                srcCode[i] = buffer[i];
            }
            String emcode = ConvertCode.ConvertIntToCode((uint)ConvertCode.ConvertCodeToInt(srcCode, market));

            switch (market)
            {
            case 8:
            {
                emcode = ConvertCode.ConvertFuturesCftEmCodeToOrgEmCode(emcode);
                break;
            }
            }
            if (DetailData.EmCodeToUnicode.ContainsKey(emcode))
            {
                this.Code = DetailData.EmCodeToUnicode[emcode];
            }
            else
            {
                return(false);
            }
            br.ReadBytes(4);
            float fieldValue = br.ReadSingle();
            float num5       = br.ReadSingle();

            switch (DataCenterCore.CreateInstance().GetMarketType(this.Code))
            {
            case MarketType.TB_NEW:
            case MarketType.TB_OLD:
                if (fieldValue >= 900000f)
                {
                    fieldValue = 0f;
                }
                if (num5 < 0f)
                {
                    num5 = 0f;
                }
                break;
            }
            DetailData.FieldIndexDataSingle[this.Code][FieldIndex.UpLimit]   = fieldValue;
            DetailData.FieldIndexDataSingle[this.Code][FieldIndex.DownLimit] = num5;
            CFTService.CallBack(FuncTypeRealTime.LimitedPrice, fieldValue.ToString() + num5.ToString());
            return(true);
        }
Esempio n. 3
0
        void PushSendDataPacket()
        {
            while (true)
            {
                DataPacket dataPacket = null;
                lock (_sendDataPacketQueue)
                {
                    if (_sendDataPacketQueue.Count > 0)
                    {
                        dataPacket = _sendDataPacketQueue.Dequeue();
                    }
                }
                try
                {
                    if (dataPacket != null)
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            using (BinaryWriter bw = new BinaryWriter(memoryStream))
                            {
                                int len = dataPacket.CodePacket(bw);
                                if (dataPacket is RealTimeDataPacket)
                                {
                                    switch (((RealTimeDataPacket)dataPacket).RequestType)
                                    {
                                    case FuncTypeRealTime.StatisticsAnalysis:
                                        if (String.IsNullOrEmpty((dataPacket as ReqStatisticsAnalysisDataPacket).Url))
                                        {
                                            break;
                                        }
                                        String         url     = StatisticAnalyUrl + (dataPacket as ReqStatisticsAnalysisDataPacket).Url;
                                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                                        request.BeginGetResponse(new AsyncCallback(OnResponse), request);
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.Heart:
                                        byte[] bytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                                        CFTService.Send(TcpService.SSHQ, bytes);
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        _dataQuery.QueryQuote(TcpService.LSHQ, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.IndexDetail:
                                    case FuncTypeRealTime.StockDetail:
                                    case FuncTypeRealTime.StockDetailLev2:
                                    case FuncTypeRealTime.StockTrend:
                                    case FuncTypeRealTime.StockTrendPush:
                                    case FuncTypeRealTime.StockTrendAskBid:
                                    case FuncTypeRealTime.StockTrendInOutDiff:
                                    case FuncTypeRealTime.IndexFuturesTrend:
                                    case FuncTypeRealTime.RedGreen:
                                    case FuncTypeRealTime.StockDict:
                                    case FuncTypeRealTime.DealSubscribe:
                                    case FuncTypeRealTime.DealRequest:
                                    case FuncTypeRealTime.BlockOverViewList:
                                    case FuncTypeRealTime.BlockSimpleQuote:
                                    case FuncTypeRealTime.BlockIndexReport:
                                    case FuncTypeRealTime.SectorQuoteReport:
                                    case FuncTypeRealTime.BlockQuoteReport:
                                    case FuncTypeRealTime.CapitalFlow:
                                    case FuncTypeRealTime.PriceStatus:
                                    case FuncTypeRealTime.Rank:
                                    case FuncTypeRealTime.TickTrade:
                                    case FuncTypeRealTime.OrderDetail:
                                    case FuncTypeRealTime.OrderQueue:
                                    case FuncTypeRealTime.ShortLineStrategy:
                                    case FuncTypeRealTime.ContributionStock:
                                    case FuncTypeRealTime.ContributionBlock:
                                    case FuncTypeRealTime.IndexFuturesDetail:
                                    case FuncTypeRealTime.MinKLine:
                                    case FuncTypeRealTime.LimitedPrice:
                                        CFTService.Send(TcpService.SSHQ, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.AllOrderStockDetailLevel2:
                                    case FuncTypeRealTime.StockDetailOrderQueue:
                                    case FuncTypeRealTime.NOrderStockDetailLevel2:
                                        if (dataPacket.IsPush)
                                        {
                                            if (
                                                _pushPackets.ContainsKey((int)((RealTimeDataPacket)dataPacket).RequestType))
                                            {
                                                DataPacket tmp = _pushPackets[(int)((RealTimeDataPacket)dataPacket).RequestType];
                                                tmp.IsPush = false;

                                                using (MemoryStream memoryStream1 = new MemoryStream())
                                                {
                                                    using (BinaryWriter bw1 = new BinaryWriter(memoryStream1))
                                                    {
                                                        tmp.CodePacket(bw1);
                                                        CFTService.Send(TcpService.SSHQ, memoryStream1.ToArray());
                                                        Debug.Print("SendPacket cancel " + ((RealTimeDataPacket)dataPacket).RequestType);
                                                    }
                                                }
                                            }
                                            _pushPackets[((int)((RealTimeDataPacket)dataPacket).RequestType)]
                                                = dataPacket;
                                            CFTService.Send(TcpService.SSHQ, memoryStream.ToArray());
                                            Debug.Print("SendPacket request " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        }
                                        else
                                        {
                                            if (
                                                _pushPackets.ContainsKey(
                                                    (int)((RealTimeDataPacket)dataPacket).RequestType))
                                            {
                                                _pushPackets.Remove(
                                                    (int)((RealTimeDataPacket)dataPacket).RequestType);
                                            }
                                            CFTService.Send(TcpService.SSHQ, memoryStream.ToArray());
                                            Debug.Print("SendPacket cancel " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        }
                                        break;

                                    case FuncTypeRealTime.TrendCapitalFlow:

                                        //using (FileStream fs = new FileStream("d:\\trendCaptial.txt", FileMode.Create))
                                        //{
                                        //    byte[] data = memoryStream.ToArray();
                                        //    fs.Write(data, 0, data.Length);
                                        //    fs.Close();

                                        //}

                                        CFTService.Send(TcpService.SSHQ, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.HisTrend:
                                    case FuncTypeRealTime.HisKLine:
                                    case FuncTypeRealTime.ReqF10:
                                    case FuncTypeRealTime.HisTrendlinecfs:
                                    case FuncTypeRealTime.CapitalFlowDay:
                                        _dataQuery.QueryQuote(TcpService.LSHQ, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.InitLogon:

                                        CFTService.Send(TcpService.SSHQ, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeRealTime.OceanHeart:
                                    case FuncTypeRealTime.OceanRecord:
                                    case FuncTypeRealTime.OceanTrend:
                                        _dataQuery.QueryQuote(TcpService.WPFW, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((RealTimeDataPacket)dataPacket).RequestType);
                                        break;
                                    }
                                }
                                else if (dataPacket is OrgDataPacket)
                                {
                                    switch (((OrgDataPacket)dataPacket).RequestType)
                                    {
                                    case FuncTypeOrg.HeartOrg:
                                        _dataQuery.QueryQuote(TcpService.JGFW, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        _dataQuery.QueryQuote(TcpService.DPZS, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeOrg.BlockReport:
                                    case FuncTypeOrg.BlockIndexReport:
                                    case FuncTypeOrg.GlobalIndexReport:
                                    case FuncTypeOrg.EmIndexReport:
                                    case FuncTypeOrg.BlockStockReport:
                                    case FuncTypeOrg.HKStockReport:
                                    case FuncTypeOrg.FundStockReport:
                                    case FuncTypeOrg.BondStockReport:
                                    case FuncTypeOrg.FuturesStockReport:
                                    case FuncTypeOrg.IndexFuturesReport:
                                    case FuncTypeOrg.CustomReport:
                                    case FuncTypeOrg.InitReportData:
                                    case FuncTypeOrg.RateReport:
                                    case FuncTypeOrg.FinanceReport:
                                    case FuncTypeOrg.FinanceOrg:
                                    case FuncTypeOrg.DDEReport:
                                    case FuncTypeOrg.CapitalFlowReport:
                                    case FuncTypeOrg.NetInFlowReport:
                                    case FuncTypeOrg.ProfitForecastReport:
                                    case FuncTypeOrg.CustomDDEReport:
                                    case FuncTypeOrg.CustomCapitalFlowReport:
                                    case FuncTypeOrg.CustomNetInFlowReport:
                                    case FuncTypeOrg.CustomProfitForecastReport:
                                    case FuncTypeOrg.Rank:
                                    case FuncTypeOrg.NetInFlowRank:
                                    case FuncTypeOrg.OSFuturesReport:
                                    case FuncTypeOrg.OSFuturesReportNew:
                                    case FuncTypeOrg.OsFuturesLMEReport:
                                    case FuncTypeOrg.ForexReport:
                                    case FuncTypeOrg.USStockReport:
                                    case FuncTypeOrg.FinanceStockReport:
                                    case FuncTypeOrg.CustomFinanceStockReport:
                                    case FuncTypeOrg.BondPublicOpeartion:
                                    case FuncTypeOrg.ChangeName:
                                        _dataQuery.QueryQuote(TcpService.JGFW, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeOrg.MonetaryFundDetail:
                                    case FuncTypeOrg.NonMonetaryFundDetail:
                                    case FuncTypeOrg.FundTrpAndSunDetail:
                                    case FuncTypeOrg.FundCIPMonetaryDetail:
                                    case FuncTypeOrg.FundCIPNonMonetaryDetail:
                                    case FuncTypeOrg.FundBFPDetail:
                                    case FuncTypeOrg.FundHeaveStockReport:
                                    case FuncTypeOrg.FundHYReport:
                                    case FuncTypeOrg.FundKeyBondReport:
                                    case FuncTypeOrg.FundManager:
                                    case FuncTypeOrg.FinanceHeaveFundReport:
                                    case FuncTypeOrg.FinanceHeaveStockReport:
                                    case FuncTypeOrg.FinanceHeaveHYReport:
                                    case FuncTypeOrg.FinanceHeaveBondReport:
                                    case FuncTypeOrg.FinanceHeaveManagerReport:
                                    case FuncTypeOrg.CNIndexDetail:
                                    case FuncTypeOrg.CSIIndexDetail:
                                    case FuncTypeOrg.CSIndexDetail:
                                    case FuncTypeOrg.GlobalIndexDetail:
                                    case FuncTypeOrg.InterBankDetail:
                                    case FuncTypeOrg.RateSwapDetail:
                                    case FuncTypeOrg.InterBankRepurchaseDetail:
                                    case FuncTypeOrg.ShiborDetail:
                                    case FuncTypeOrg.TrendOrgDP:
                                    case FuncTypeOrg.MinKLineOrgDP:
                                    case FuncTypeOrg.LowFrequencyTBY:
                                    case FuncTypeOrg.BankBondReport:
                                    case FuncTypeOrg.ShiborReport:
                                        _dataQuery.QueryQuote(TcpService.DPZS, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeOrg.DepthAnalyse:
                                    case FuncTypeOrg.EMIndexDetail:
                                    case FuncTypeOrg.MinKLineOrg:
                                    case FuncTypeOrg.TrendOrg:
                                    case FuncTypeOrg.IndexStatic:
                                    case FuncTypeOrg.USStockDetail:
                                    case FuncTypeOrg.OSFuturesDetail:
                                    case FuncTypeOrg.ForexDetail:
                                    case FuncTypeOrg.ConvertBondDetail:
                                    case FuncTypeOrg.NonConvertBondDetail:
                                    case FuncTypeOrg.OSFuturesLMEDetail:
                                    case FuncTypeOrg.OSFuturesLMEDeal:
                                    case FuncTypeOrg.NewProfitForcast:
                                        _dataQuery.QueryQuote(TcpService.GPZS, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        break;

                                    case FuncTypeOrg.TradeDate:
                                    case FuncTypeOrg.HisKLineOrg:
                                    case FuncTypeOrg.FundKlineAfterDivide:
                                    case FuncTypeOrg.DivideRightOrg:
                                        _dataQuery.QueryQuote(TcpService.JGLS, memoryStream.ToArray());
                                        Debug.Print("SendPacket " + ((OrgDataPacket)dataPacket).RequestType);
                                        break;
                                    }
                                }
                                else if (dataPacket is InfoOrgBaseDataPacket)
                                {
                                    _queryConnnection.DoSendPacket(
                                        ((InfoOrgBaseDataPacket)dataPacket).CodeInfoPacket(), dataPacket.MsgId);
                                    Debug.Print("SendPacket " + ((InfoOrgBaseDataPacket)dataPacket).RequestId);
                                }
                                else if (dataPacket is IndicatorDataPacket)
                                {
                                    IndicatorDataPacket iPacket = dataPacket as IndicatorDataPacket;
                                    _indicatorQueryConnectiuon.DoSendPacket(iPacket.CreateCommand(),
                                                                            dataPacket.MsgId);
                                    Debug.Print("SendPacket " + ((IndicatorDataPacket)dataPacket).RequestId);
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.Print(e.Message);
                }
                Thread.Sleep(2);
            }
        }