示例#1
0
        public List <StockQuotation> GetAllStockQuotation()
        {
            using (var conn = QuotationPublisher.Publisher.GetNeedDisposedConnection())
            {
                if (conn == null)
                {
                    return(null);
                }

                string key = string.Format("{0}:{1}", stockQuotSource.ToFormatString(), QuotationDataType.Quotation.ToFormatString());

                var rtnBytes = (conn as RedisClient).HVals(key);
                if (rtnBytes == null)
                {
                    return(null);
                }

                List <StockQuotation> rtn = new List <StockQuotation>();
                foreach (var rtnByte in rtnBytes)
                {
                    StockQuotation quotInfo = JsonSerializer.BytesToObject <StockQuotation>(rtnByte);
                    rtn.Add(quotInfo);
                }
                return(rtn);
            }
        }
示例#2
0
        public void UpdateStockQuotation(StockQuotation quotInfo)
        {
            byte[] quotInfoBytes = JsonSerializer.ObjectToBytes <StockQuotation>(quotInfo);
            string stkId         = quotInfo.stkId;
            string key           = string.Format("{0}:{1}", stockQuotSource.ToFormatString(), QuotationDataType.Quotation.ToFormatString());

            QuotationPublisher.Publisher.Update(key, stkId, quotInfoBytes);
        }
 public void UpdateStockQuotation(StockQuotation quotInfo)
 {
     byte[] quotInfoBytes = JsonSerializer.ObjectToBytes<StockQuotation>(quotInfo);
     string stkId = quotInfo.stkId;
     string key = string.Format("{0}:{1}", stockQuotSource.ToFormatString(), QuotationDataType.Quotation.ToFormatString());
     QuotationPublisher.Publisher.Update(key, stkId, quotInfoBytes);
 }
示例#4
0
 public void Enqueue(StockQuotation quotInfo, bool isRealtimeQuotation, string clientId = null)
 {
     EnqueueData(quotInfo, isRealtimeQuotation, clientId);
 }
        private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.Binary.QuotSnap300611 quotSnap)
        {
            SetStockQuotationProperty(quotInfo, quotSnap.CommonInfo);

            quotInfo.buyQty1 = 0;
            quotInfo.buyQty2 = 0;
            quotInfo.buyQty3 = 0;
            quotInfo.buyQty4 = 0;
            quotInfo.buyQty5 = 0;

            quotInfo.sellQty1 = 0;
            quotInfo.sellQty2 = 0;
            quotInfo.sellQty3 = 0;
            quotInfo.sellQty4 = 0;
            quotInfo.sellQty5 = 0;

            quotInfo.buyPrice1 = 0;
            quotInfo.buyPrice2 = 0;
            quotInfo.buyPrice3 = 0;
            quotInfo.buyPrice4 = 0;
            quotInfo.buyPrice5 = 0;

            quotInfo.sellPrice1 = 0;
            quotInfo.sellPrice2 = 0;
            quotInfo.sellPrice3 = 0;
            quotInfo.sellPrice4 = 0;
            quotInfo.sellPrice5 = 0;

            if (quotSnap.ExtInfo != null && quotSnap.ExtInfo.MDEntries != null && quotSnap.ExtInfo.MDEntries.Length > 0)
            {
                foreach (var mdEntry in quotSnap.ExtInfo.MDEntries)
                {
                    if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300611.MDEntryType.Buy)
                    {
                        quotInfo.buyPrice1 = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                        quotInfo.buyQty1 = mdEntry.MDEntrySize/qtyTimes;
                    }
                    else if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300611.MDEntryType.Sell)
                    {
                        quotInfo.sellPrice1 = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                        quotInfo.sellQty1 = mdEntry.MDEntrySize / qtyTimes;
                    }
                }
            }
        }
        private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.Binary.QuotSnap309011 quotSnap)
        {
            SetStockQuotationProperty(quotInfo, quotSnap.CommonInfo);
            if (quotSnap.ExtInfo != null && quotSnap.ExtInfo.MDEntries != null && quotSnap.ExtInfo.MDEntries.Length > 0)
            {

                foreach (var mdEntry in quotSnap.ExtInfo.MDEntries)
                {
                    if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo309011.MDEntryType.NewIndex)
                    {
                        quotInfo.newIndex = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes ;
                    }
                    else if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo309011.MDEntryType.OpenIndex)
                    {
                        quotInfo.openIndex = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo309011.MDEntryType.CloseIndex)
                    {
                        quotInfo.closeIndex = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo309011.MDEntryType.HighIndex)
                    {
                        quotInfo.highIndex = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo309011.MDEntryType.LowIndex)
                    {
                        quotInfo.lowIndex = (decimal)mdEntry.MDEntryPx / mdEntryPxTimes;
                    }
                }
            }
            quotInfo.change = quotInfo.newIndex - quotInfo.closeIndex;
            if (quotInfo.closeIndex != 0.0m)
                quotInfo.changePercent = quotInfo.change / quotInfo.closeIndex;
        }
        private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.Binary.RealtimeStatus status)
        {
            quotInfo.stkId = status.Status.SecurityID;
            quotInfo.stkIdPrefix = status.Status.SecurityPreName;
            if (!string.IsNullOrEmpty(status.Status.SecurityPreName))
            {
                quotInfo.closeFlag = status.Status.SecurityPreName.Substring(0, 1);

                if (status.Status.SecurityPreName.Length > 1)
                {
                    quotInfo.passCreditCashStk = status.Status.SecurityPreName.Substring(1, 1);
                    quotInfo.passCreditShareStk = quotInfo.passCreditCashStk;
                }
            }
        }
 private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.StaticInfo.SecurityInfoBase securityInfo)
 {
     quotInfo.stkId = securityInfo.CommonInfo.SecurityID;
     quotInfo.stkName = securityInfo.CommonInfo.Symbol;
 }
        private void ProcessMarketData(QuotV5.Binary.RealtimeStatus status, DateTime receiveTime)
        {
            RawQuotationInfoSnap.RealtimeStatus[status.Status.SecurityID] = status;
            StockQuotation preQuotInfo = null;
            StockQuotation newQuotInfo = null;
            if (ProcessedDataSnap.StockQuotation.TryGetValue(status.Status.SecurityID, out preQuotInfo))
            {
                newQuotInfo = preQuotInfo.Clone();
                SetStockQuotationProperty(newQuotInfo, status);
            }
            else
            {
                newQuotInfo = new StockQuotation();

                QuotV5.StaticInfo.SecurityInfoBase securityInfo = null;
                if (RawStaticInfoSnap.SecurityInfo.TryGetValue(status.Status.SecurityID, out securityInfo))
                    SetStockQuotationProperty(newQuotInfo, securityInfo);

                SetStockQuotationProperty(newQuotInfo, status);

                QuotV5.Binary.QuotSnap300111 quotSnap = null;
                if (RawQuotationInfoSnap.QuotSnap300111.TryGetValue(status.Status.SecurityID, out quotSnap))
                    SetStockQuotationProperty(newQuotInfo, quotSnap);

                QuotV5.Binary.QuotSnap300611 quotSnap2 = null;
                if (RawQuotationInfoSnap.QuotSnap300611.TryGetValue(status.Status.SecurityID, out quotSnap2))
                    SetStockQuotationProperty(newQuotInfo, quotSnap2);

            }
            if (newQuotInfo != null)
            {
                newQuotInfo.receiveTime = DatetimeToLong(receiveTime);
                ProcessedDataSnap.StockQuotation[newQuotInfo.stkId] = newQuotInfo;
                quotRepository.UpdateStockQuotation(newQuotInfo);
                if (quotPublisher != null)
                    quotPublisher.Enqueue(newQuotInfo, true);
            }
        }
        private void ProcessMarketData(QuotV5.Binary.QuotSnap300111 quotSnap, DateTime receiveTime)
        {
            RawQuotationInfoSnap.QuotSnap300111[quotSnap.CommonInfo.SecurityID] = quotSnap;
            if (quotSnap.CommonInfo.MDStreamID == QuotV5.Binary.QuotSnap300111.MDStreamID.Option)
            {
                FutureQuotation preQuotInfo = null;
                FutureQuotation newQuotInfo = null;
                if (ProcessedDataSnap.FutureQuotation.TryGetValue(quotSnap.CommonInfo.SecurityID, out preQuotInfo))
                {
                    newQuotInfo = preQuotInfo.Clone();
                    QuotV5.StaticInfo.SecurityInfoBase securityInfo = null;
                    if (RawStaticInfoSnap.SecurityInfo.TryGetValue(quotSnap.CommonInfo.SecurityID, out securityInfo))
                        SetFutureQuotationProperty(newQuotInfo, securityInfo as QuotV5.StaticInfo.OptionSecuirtyInfo);

                    SetFutureQuotationProperty(newQuotInfo, quotSnap);
                }
                else
                {
                    newQuotInfo = new FutureQuotation();

                    QuotV5.StaticInfo.SecurityInfoBase securityInfo = null;
                    if (RawStaticInfoSnap.SecurityInfo.TryGetValue(quotSnap.CommonInfo.SecurityID, out securityInfo))
                        SetFutureQuotationProperty(newQuotInfo, securityInfo as QuotV5.StaticInfo.OptionSecuirtyInfo);

                    QuotV5.Binary.RealtimeStatus status = null;
                    if (RawQuotationInfoSnap.RealtimeStatus.TryGetValue(quotSnap.CommonInfo.SecurityID, out status))
                        SetFutureQuotationProperty(newQuotInfo, status);

                    SetFutureQuotationProperty(newQuotInfo, quotSnap);
                }
                if (newQuotInfo != null)
                {

                    ProcessedDataSnap.FutureQuotation[newQuotInfo.stkId] = newQuotInfo;
                    quotRepository.UpdateFutureQuotation(newQuotInfo);
                    if (quotPublisher != null)
                        quotPublisher.Enqueue(newQuotInfo, true);
                }

            }
            else
            {
                StockQuotation preQuotInfo = null;
                StockQuotation newQuotInfo = null;
                if (ProcessedDataSnap.StockQuotation.TryGetValue(quotSnap.CommonInfo.SecurityID, out preQuotInfo))
                {
                    newQuotInfo = preQuotInfo.Clone();
                    QuotV5.StaticInfo.SecurityInfoBase securityInfo = null;
                    if (RawStaticInfoSnap.SecurityInfo.TryGetValue(quotSnap.CommonInfo.SecurityID, out securityInfo))
                        SetStockQuotationProperty(newQuotInfo, securityInfo);

                    SetStockQuotationProperty(newQuotInfo, quotSnap);
                }
                else
                {
                    newQuotInfo = new StockQuotation();

                    QuotV5.StaticInfo.SecurityInfoBase securityInfo = null;
                    if (RawStaticInfoSnap.SecurityInfo.TryGetValue(quotSnap.CommonInfo.SecurityID, out securityInfo))
                        SetStockQuotationProperty(newQuotInfo, securityInfo);

                    QuotV5.Binary.RealtimeStatus status = null;
                    if (RawQuotationInfoSnap.RealtimeStatus.TryGetValue(quotSnap.CommonInfo.SecurityID, out status))
                        SetStockQuotationProperty(newQuotInfo, status);

                    SetStockQuotationProperty(newQuotInfo, quotSnap);
                }
                if (newQuotInfo != null)
                {
                    newQuotInfo.receiveTime = DatetimeToLong(receiveTime);
                    ProcessedDataSnap.StockQuotation[newQuotInfo.stkId] = newQuotInfo;
                    quotRepository.UpdateStockQuotation(newQuotInfo);
                    if (quotPublisher != null)
                        quotPublisher.Enqueue(newQuotInfo, true);
                }
            }
        }
 private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.Binary.QuotSnapCommonInfo quotSnapCommonInfo)
 {
     quotInfo.stkId = quotSnapCommonInfo.SecurityID;
     quotInfo.knockQty = quotSnapCommonInfo.TotalVolumeTrade / qtyTimes;
     quotInfo.knockMoney = (decimal)quotSnapCommonInfo.TotalValueTrade / amtTimes;
     quotInfo.tradeTimeFlag = quotSnapCommonInfo.TradingPhaseCode;
     quotInfo.closePrice = (decimal)quotSnapCommonInfo.PrevClosePx / pxTimes;
     quotInfo.changeTime = quotSnapCommonInfo.OrigTime;
 }
        private void SetStockQuotationProperty(StockQuotation quotInfo, QuotV5.Binary.QuotSnap300111 quotSnap)
        {
            SetStockQuotationProperty(quotInfo, quotSnap.CommonInfo);
            if (quotSnap.ExtInfo != null && quotSnap.ExtInfo.MDEntries != null && quotSnap.ExtInfo.MDEntries.Length > 0)
            {

                foreach (var mdEntry in quotSnap.ExtInfo.MDEntries)
                {
                    if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.BuyPrice)
                    {
                        if (mdEntry.Entry.MDPriceLevel == 1)
                        {
                            quotInfo.buyPrice1 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.buyQty1 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 2)
                        {
                            quotInfo.buyPrice2 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.buyQty2 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 3)
                        {
                            quotInfo.buyPrice3 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.buyQty3 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 4)
                        {
                            quotInfo.buyPrice4 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.buyQty4 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 5)
                        {
                            quotInfo.buyPrice5 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.buyQty5 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }

                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.SellPrice)
                    {
                        if (mdEntry.Entry.MDPriceLevel == 1)
                        {
                            quotInfo.sellPrice1 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.sellQty1 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 2)
                        {
                            quotInfo.sellPrice2 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.sellQty2 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 3)
                        {
                            quotInfo.sellPrice3 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.sellQty3 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 4)
                        {
                            quotInfo.sellPrice4 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.sellQty4 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                        else if (mdEntry.Entry.MDPriceLevel == 5)
                        {
                            quotInfo.sellPrice5 = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                            quotInfo.sellQty5 = mdEntry.Entry.MDEntrySize / qtyTimes;
                        }
                    }

                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.HighPrice)
                    {
                        quotInfo.highPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.KnockPrice)
                    {
                        quotInfo.newPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.LowPrice)
                    {
                        quotInfo.lowPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.OpenPrice)
                    {
                        quotInfo.openPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.MaxOrderPrice)
                    {
                        quotInfo.maxOrderPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.MinOrderPrice)
                    {
                        quotInfo.minOrderPrice = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.IOPV)
                    {
                        quotInfo.IOPV = (decimal)mdEntry.Entry.MDEntryPx / mdEntryPxTimes;
                    }
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.BuySummary)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.SellSummary)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.SettlePrice)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.PriceEarningRatio1)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.PriceEarningRatio2)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.Diff1)
                    //{

                    //}
                    //else if (mdEntry.Entry.MDEntryType == QuotV5.Binary.QuotSnapExtInfo300111.MDEntryType.Diff2)
                    //{

                    //}
                }
            }

            quotInfo.change = quotInfo.newPrice - quotInfo.closePrice;
            if (quotInfo.closePrice != 0.0m)
                quotInfo.changePercent = quotInfo.change / quotInfo.closePrice;
        }