/// <summary>
 /// 深度行情数据回报,更新Position中的持仓损益
 /// </summary>
 /// <param name="dmd"></param>
 private void Platform_OnPositionProfitChanged(DepthMarketData dmd)
 {
     if (!this._DictInstrumentIDPositions.IsEmpty && _DictInstrumentIDPositions.ContainsKey(dmd.InstrumentID))
     {
         //字典中含有dmd相对应的InstrumentID
         List <Tuple <string, Direction, HedgeFlag> > value;
         this._DictInstrumentIDPositions.TryGetValue(dmd.InstrumentID, out value);
         foreach (var item in value)
         {
             var      key          = item;
             var      instrumentID = key.Item1;
             Position pos;
             if (!this._tradeApi.DictInvestorPosition.TryGetValue(key, out pos))
             {
                 continue;
             }
             var lastPrice = this._quoteApi.DictDepthMarketData[key.Item1].LastPrice;
             var mult      = this._tradeApi.DictInstrumentField[dmd.InstrumentID].VolumeMultiple;
             pos.LastPrice = lastPrice;
             if (key.Item2 == Direction.Buy)
             {
                 pos.OpenProfit     = (lastPrice - pos.AvgOpenPrice) * pos.TotalPosition * mult;
                 pos.PositionProfit = lastPrice * pos.TotalPosition * mult - pos.PositionCost;
             }
             else
             {
                 pos.OpenProfit     = -1 * (lastPrice - pos.AvgOpenPrice) * pos.TotalPosition * mult;
                 pos.PositionProfit = -1 * (lastPrice * pos.TotalPosition * mult - pos.PositionCost);
             }
             pos.Notify("");
         }
     }
 }
示例#2
0
        /// <summary>
        /// 行情信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="onDepthMarketData"></param>
        public void OnRtnDepthMarketData_ <T>(T onDepthMarketData)
        {
            object               obj           = onDepthMarketData;
            DepthMarketData      marketData    = (DepthMarketData)obj;
            OnQuoteMarketDataAny marketDataAny = new OnQuoteMarketDataAny
            {
                AskPrice1          = marketData.AskPrice1,
                AskPrice2          = marketData.AskPrice2,
                AskPrice3          = marketData.AskPrice3,
                AskPrice4          = marketData.AskPrice4,
                AskPrice5          = marketData.AskPrice5,
                AskVolume1         = marketData.AskVolume1,
                AskVolume2         = marketData.AskVolume2,
                AskVolume3         = marketData.AskVolume3,
                AskVolume4         = marketData.AskVolume4,
                AskVolume5         = marketData.AskVolume5,
                BidPrice1          = marketData.BidPrice1,
                BidPrice2          = marketData.BidPrice2,
                BidPrice3          = marketData.BidPrice3,
                BidPrice4          = marketData.BidPrice4,
                BidPrice5          = marketData.BidPrice5,
                BidVolume1         = marketData.BidVolume1,
                BidVolume2         = marketData.BidVolume2,
                BidVolume3         = marketData.BidVolume3,
                BidVolume4         = marketData.BidVolume4,
                BidVolume5         = marketData.BidVolume5,
                Code               = marketData.InstrumentID,
                ExchangeID         = (EnumExchangeIDTypeAny)Enum.Parse(typeof(EnumExchangeIDTypeAny), marketData.ExchangeID),
                ExchangeInstID     = marketData.ExchangeInstID,
                HighestPrice       = marketData.HighestPrice,
                LastPrice          = marketData.LastPrice,
                LowerLimitPrice    = marketData.LowerLimitPrice,
                LowestPrice        = marketData.LowestPrice,
                OpenInterest       = marketData.OpenInterest,
                OpenPrice          = marketData.OpenPrice,
                PreClosePrice      = marketData.PreClosePrice,
                PreOpenInterest    = marketData.PreOpenInterest,
                PreSettlementPrice = marketData.PreSettlementPrice,
                SettlementPrice    = marketData.SettlementPrice,
                TradingDay         = marketData.TradingDay,
                Turnover           = marketData.Turnover,
                UpdateMillisec     = marketData.UpdateMillisec,
                UpdateTime         = marketData.UpdateTime,
                UpperLimitPrice    = marketData.UpperLimitPrice,
                Volume             = marketData.Volume
            };

            if (marketData != null)
            {
                OnQuoteData?.Invoke(this, marketDataAny);
            }
        }
 /// <summary>
 /// 初始化_OcMainMarketDepthData
 /// </summary>
 private ObservableCollection <DepthMarketData> GetOcMainMarketDepthData(ObservableCollection <DepthMarketData> OcAllDMD)
 {
     lock (this._lockAllDepthMarketData)
     {
         ObservableCollection <DepthMarketData> oc = new ObservableCollection <DepthMarketData>();
         var grp = OcAllDMD.GroupBy(r => r.ProductID);
         foreach (IGrouping <string, DepthMarketData> item in grp)
         {
             DepthMarketData r = item.OrderByDescending(x => x.OpenInterest).FirstOrDefault();
             oc.Add(r);
         }
         return(oc);
     }
 }
        /// <summary>
        /// 初始化 OcAllMarketDepthData
        /// </summary>
        private ObservableCollection <DepthMarketData> GetOcAllMarketDepthData()
        {
            lock (this._lockAllDepthMarketData)
            {
                ObservableCollection <DepthMarketData> oc = new ObservableCollection <DepthMarketData>();
                oc.Clear();

                foreach (var kvp in this._quoteApi.DictDepthMarketData)
                {
                    InstrumentField _instrumentField;
                    if (this._tradeApi.DictInstrumentField.TryGetValue(kvp.Key, out _instrumentField))
                    {
                        DepthMarketData dmd = kvp.Value;
                        dmd.ProductID = _instrumentField.ProductID;
                        //有些合约虽然有ProductID,但是DMD的InstrumentID却是null
                        oc.Add(dmd);
                    }
                }
                return(oc);
            }
        }