public static void OnAzMessageReciver(object sender, MessageReceivedEventArgs args) { //获取快照数据 if (args.Command == CommandType.MarketDepthData) { var model = ProtobufHelper.Deserialize <MarketDepthDto>(args.Message); DepthDto depthResult = ConvertDepth(model); Depth.AddOrUpdate(model.Market, depthResult, (key, v) => { return(depthResult); }); } else if (args.Command == CommandType.MarketDepthDiff) { var diffModel = ProtobufHelper.Deserialize <MarketDepthDiff>(args.Message); //深度无快照,或者快照数据的版本与差异数据起始版本不一致时,重新订阅获取快照 if (!Depth.ContainsKey(diffModel.Market) || Depth[diffModel.Market].Version != diffModel.StartVersion) { azWebsocket.SendMarketDepth("eth_btc"); } else { UpdateDepth(diffModel); } } Console.WriteLine("数据更新"); }
public static DepthDto ConvertDepth(MarketDepthDto source) { var resultDto = new DepthDto(); resultDto.Version = source.Version; foreach (var item in source.AskList) { var key = Convert.ToDecimal(item.Price); if (!resultDto.Asks.ContainsKey(key)) { resultDto.Asks.Add(key, Convert.ToDecimal(item.Volume)); } else { resultDto.Asks[key] = Convert.ToDecimal(item.Volume); } } foreach (var item in source.BidList) { var key = Convert.ToDecimal(item.Price); if (!resultDto.Bids.ContainsKey(key)) { resultDto.Bids.Add(key, Convert.ToDecimal(item.Volume)); } else { resultDto.Bids[key] = Convert.ToDecimal(item.Volume); } } return(resultDto); }