private void OnAskQuote(TickData askEvent) { PrevAsk = Ask; Ask = askEvent.Price; PrevAskVol = AskVol; AskVol = _securityObj.HasQuoteSize ? askEvent.Size : 0; }
private void OnBidQuote(TickData bidEvent) { PrevBid = Bid; Bid = bidEvent.Price; PrevBidVol = BidVol; BidVol = _securityObj.HasQuoteSize ? bidEvent.Size : 0; }
private void OnTrade(TickData trade) { LastTrdPrice = trade.Price; if (LastTrdPrice == Bid) { TrdCntBid++; } if (LastTrdPrice == Ask) { TrdCntAsk++; } if ((_securityObj.HasTradeSize) && (trade.Size > 0)) { LastTrdSize = trade.Size; if (LastTrdPrice == Bid) { VolAtBid += LastTrdSize; } if (LastTrdPrice == Ask) { VolAtAsk += LastTrdSize; } } else { LastTrdSize = 0; VolAtBid = 0; VolAtAsk = 0; } if (TrdsAtPrice.ContainsKey(trade.Price)) { TrdsAtPrice[trade.Price].NewTradeAtPrice(LastTrdSize, this); } else { if ((_securityObj.HasTradeSize) && (trade.Size > 0)) { TrdsAtPrice.Add(LastTrdPrice, new TradesAtPrice(LastTrdPrice, LastTrdSize, this)); } else { TrdsAtPrice.Add(LastTrdPrice, new TradesAtPrice(LastTrdPrice, this)); } } }
// constructor used on very first event to initialize market state (market summary event) public MarketState(Security security, TickData bid, TickData ask, TickData trade) { if (security == null) { throw new ArgumentException("security object must not be null", "security"); } if (bid == null) { throw new ArgumentException("TickData object for bid object must not be null", "bid"); } if (ask == null) { throw new ArgumentException("TickData object for ask object must not be null", "ask"); } if (trade == null) { throw new ArgumentException("TickData object for trade object must not be null", "bid"); } VolumeTdy = 0; OrderFlowTdy = 0; VolAtBidTdy = 0; VolAtAskTdy = 0; _securityObj = security; StateType = MktStateType.Summary; TimeStamp = bid.TimeStamp; FirstOfInterval = true; OnBidQuote(bid); SetBidOpen(bid); OnAskQuote(ask); SetAskOpen(ask); OnTrade(trade); SetTradeOpn(trade); SetMid(); SetMidOpen(); }
private void SetTradeOpn(TickData trade) { LastPriceOpn = trade.Price; }
private void SetAskOpen(TickData askEvent) { AskOpen = askEvent.Price; AskVolOpen = _securityObj.HasQuoteSize ? askEvent.Size : 0; }
private void SetBidOpen(TickData bidEvent) { BidOpen = bidEvent.Price; BidVolOpen = _securityObj.HasQuoteSize ? bidEvent.Size : 0; }
// constructor used for each successive data event after the initial market summary event public MarketState(Security security, MarketState previousMktState, TickData tickData) { VolumeTdy = 0; OrderFlowTdy = 0; VolAtBidTdy = 0; VolAtAskTdy = 0; _securityObj = security; if (previousMktState == null) { throw new ArgumentException("Previous MarketState object must not be null", "previousMktState"); } if (tickData.TimeStamp == null) { throw new ArgumentException("tickData.TimeStamp must not be null", "tickData.TimeStamp"); } TimeStamp = tickData.TimeStamp; FirstOfInterval = (tickData.TimeStamp.Subtract(previousMktState.TimeStamp).TotalSeconds > 0); CopyPrevState(previousMktState, FirstOfInterval); switch (tickData.Type) { case Type.Ask: StateType = MktStateType.Ask; OnAskQuote(tickData); SetAskVolChg(previousMktState); SetMid(); if (FirstOfInterval) { SetAskOpen(tickData); SetMidOpen(); } break; case Type.Bid: StateType = MktStateType.Bid; OnBidQuote(tickData); SetBidVolChg(previousMktState); SetMid(); if (FirstOfInterval) { SetBidOpen(tickData); SetMidOpen(); } break; case Type.Trade: StateType = MktStateType.Trade; OnTrade(tickData); if (FirstOfInterval) { SetTradeOpn(tickData); } break; default: throw new ArgumentException("TickData's 'Type' parameter must be of enum of type TickData.Type", "tickData"); } if ((FirstOfInterval) || (Codes == null)) { Codes = tickData.Codes; } else { if (tickData.Codes != null) { if (tickData.Codes.Count > 0) { foreach (var code in tickData.Codes) { if (!Codes.ContainsKey(code.Key)) { Codes.Add(code.Key, code.Value); } } } } } }