private void MarketSimulatorTimerStep() { int?conflationIntervalInMilleseconds = null; List <Subscription> subsToUse = new List <Subscription>(); lock (this._syncroot) //protect _subscriptions { foreach (var item in this._subscriptions) { if (Types.RandomDataGenerator.ShouldIncludeQuote()) //70% chance that I'll send a new quote for the current subscription (after the first response which contains all tickers) { subsToUse.Add(item); } if (item.ConflationInterval.HasValue) { conflationIntervalInMilleseconds = item.ConflationInterval.Value * 1000; } } } if (subsToUse.Count > 0) { MarketDataRequest.MarketEvent evt = new MarketDataRequest.MarketEvent(Event.EventType.SUBSCRIPTION_DATA, null, subsToUse); if (this._asyncHandler != null) { this._asyncHandler(evt, this); } } }
public void Subscribe(IList <Subscription> subscriptionList) { lock (this._syncroot) //protect _subscriptions this._subscriptions.AddRange(subscriptionList); MarketDataRequest.MarketEvent evtSubStatus = new MarketDataRequest.MarketEvent(Event.EventType.SUBSCRIPTION_STATUS, null, subscriptionList); if (this._asyncHandler != null) { this._asyncHandler(evtSubStatus, this); } }
public bool StartAsync() { this._sessionState = SessionStateType.started; MarketDataRequest.MarketEvent evtSessionStatus = new MarketDataRequest.MarketEvent(Event.EventType.SESSION_STATUS, null, null); MarketDataRequest.MarketEvent evtServiceStatus = new MarketDataRequest.MarketEvent(Event.EventType.SERVICE_STATUS, new CorrelationID(), null); if (this._asyncHandler != null) { this._asyncHandler(evtSessionStatus, this); this._asyncHandler(evtServiceStatus, this); } return(true); }
public void Cancel(CorrelationID corr) { lock (this._syncroot) //protect _subscriptions { for (int i = this._subscriptions.Count - 1; i >= 0; i--) { if (this._subscriptions[i].CorrelationID.Value == corr.Value && this._subscriptions[i].CorrelationID.IsInternal == corr.IsInternal) { MarketDataRequest.MarketEvent evtSubCancel = new MarketDataRequest.MarketEvent(Event.EventType.SUBSCRIPTION_STATUS, this._subscriptions[i]); if (this._asyncHandler != null) { this._asyncHandler(evtSubCancel, this); } this._subscriptions.RemoveAt(i); } } } }
internal MarketEvent(EventType evtType, CorrelationID corr, IEnumerable <Subscription> subscriptions) //use for subscribing { this._messages = new List <Message>(); switch (evtType) { case EventType.SESSION_STATUS: base._type = evtType; MarketMessageSessionOpened msgSessionOpened = new MarketMessageSessionOpened(); this._messages.Add(msgSessionOpened); break; case EventType.SERVICE_STATUS: base._type = evtType; MarketMessageServiceStatus msgServiceStatus = new MarketMessageServiceStatus(corr); this._messages.Add(msgServiceStatus); break; case EventType.SUBSCRIPTION_STATUS: base._type = evtType; foreach (var item in subscriptions) { bool securityError = Types.Rules.IsSecurityError(item.Security); if (securityError) { MarketMessageSubscriptionFailure msgError = new MarketMessageSubscriptionFailure(item); this._messages.Add(msgError); } else { MarketMessageSubscriptionStarted msgSubStatus = new MarketMessageSubscriptionStarted(item); this._messages.Add(msgSubStatus); } } break; case EventType.SUBSCRIPTION_DATA: base._type = evtType; foreach (var item in subscriptions) { bool securityError = Types.Rules.IsSecurityError(item.Security); if (!securityError) { MarketMessageSubscriptionData msgSubData = new MarketMessageSubscriptionData(item, MarketEvent.GenerateFakeMessageData(item)); this._messages.Add(msgSubData); } } break; default: throw new NotImplementedException(string.Format("BEmu.MarketDataRequest.EventMarket.EventMarket: doesn't expect EventType {0}", evtType.ToString())); } }