//行情回报 public static void Body_OnTick(DepthMarketData dmd) { lock (Dic_InstrumentID_PositionKeys) { if (!Body.Dic_InstrumentID_PositionKeys.IsEmpty && Body.Dic_InstrumentID_PositionKeys.ContainsKey(dmd.InstrumentID)) { List <Tuple <string, TThostFtdcPosiDirectionType, TThostFtdcHedgeFlagType> > value; Body.Dic_InstrumentID_PositionKeys.TryGetValue(dmd.InstrumentID, out value); foreach (var item in value) { var key = item; var instrumentID = key.Item1; Position pos; if (!Body.trdApi.DicPosition.TryGetValue(key, out pos)) { continue; } var lastPrice = Body.mktApi.DicDepthMarketData[key.Item1].LastPrice; var mult = Body.trdApi.DicInstrumentField[dmd.InstrumentID].VolumeMultiple; pos.LastPrice = lastPrice; if (key.Item2 == TThostFtdcPosiDirectionType.THOST_FTDC_PD_Long) { 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(""); } } }; }
////////////////////////////////////////////////////////////////////////////////////////////// #region 回调绑定 //行情回调 private void MainWindow_OnTick(DepthMarketData dmd) { if (dmd.InstrumentID != this._instrumentID) { return; } Dispatcher.Invoke(new Action(() => { this.btnAskPrice1.Content = dmd.AskPrice1.ToString(); this.tbkAskVolume1.Text = dmd.AskVolume1.ToString(); this.btnBidPrice1.Content = dmd.BidPrice1.ToString(); this.tbkBidVolume1.Text = dmd.BidVolume1.ToString(); })); }
//主力合约的市场行情数据 public static ObservableCollection <DepthMarketData> GenerateMainDepthData(ObservableCollection <DepthMarketData> OCAllMarketDepthData) { lock (OCAllMarketDepthData) { var oc = new ObservableCollection <DepthMarketData>(); var grp = OCAllMarketDepthData.GroupBy(r => r.FutureCode); foreach (IGrouping <string, DepthMarketData> item in grp) { DepthMarketData r = item.OrderByDescending(x => x.OpenInterest).FirstOrDefault(); oc.Add(r); } return(oc); } }
//回调函数:更新行情 abstract public void OnTick(DepthMarketData dmd);