Exemple #1
0
        private void MarketSimulatorTimerStep(object arg)
        {
            int?conflationIntervalInMilleseconds = null;

            lock (this._syncroot) //protect _subscriptions
            {
                List <Subscription> subsToUse = new List <Subscription>();

                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;
                    }
                }

                MarketDataRequest.EventMarket evt = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_DATA, null, subsToUse);

                if (this._asyncHandler != null)
                {
                    this._asyncHandler(evt, this);
                }
            }

            this._marketSimulatorTimer.Change(conflationIntervalInMilleseconds.GetValueOrDefault((int)Types.RandomDataGenerator.TimeBetweenMarketDataEvents().TotalMilliseconds), Timeout.Infinite);
        }
Exemple #2
0
        public void Subscribe(IList <Subscription> subscriptionList)
        {
            lock (this._syncroot) //protect _subscriptions
                this._subscriptions.AddRange(subscriptionList);

            MarketDataRequest.EventMarket evtSubStatus = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, null, subscriptionList);
            if (this._asyncHandler != null)
            {
                this._asyncHandler(evtSubStatus, this);
            }
        }
Exemple #3
0
        public bool StartAsync()
        {
            this._sessionState = SessionStateType.started;
            MarketDataRequest.EventMarket evtSessionStatus = new MarketDataRequest.EventMarket(Event.EventType.SESSION_STATUS, null, null);
            MarketDataRequest.EventMarket evtServiceStatus = new MarketDataRequest.EventMarket(Event.EventType.SERVICE_STATUS, new CorrelationID(), null);

            if (this._asyncHandler != null)
            {
                this._asyncHandler(evtSessionStatus, this);
                this._asyncHandler(evtServiceStatus, this);
            }

            return(true);
        }
Exemple #4
0
 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.EventMarket evtSubCancel = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, this._subscriptions[i]);
                 if (this._asyncHandler != null)
                 {
                     this._asyncHandler(evtSubCancel, this);
                 }
                 this._subscriptions.RemoveAt(i);
             }
         }
     }
 }
Exemple #5
0
        private void MarketSimulatorTimerStep(object arg)
        {
            int? conflationIntervalInMilleseconds = null;

            lock (this._syncroot) //protect _subscriptions
            {
                List<Subscription> subsToUse = new List<Subscription>();                

                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;
                }

                MarketDataRequest.EventMarket evt = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_DATA, null, subsToUse);

                if (this._asyncHandler != null)
                    this._asyncHandler(evt, this);
            }

            this._marketSimulatorTimer.Change(conflationIntervalInMilleseconds.GetValueOrDefault((int)Types.RandomDataGenerator.TimeBetweenMarketDataEvents().TotalMilliseconds), Timeout.Infinite);
        }
Exemple #6
0
 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.EventMarket evtSubCancel = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, this._subscriptions[i]);
                 if (this._asyncHandler != null)
                 {
                     this._asyncHandler(evtSubCancel, this);
                 }
                 this._subscriptions.RemoveAt(i);
             }
         }
     }
 }
Exemple #7
0
        public void Subscribe(IList<Subscription> subscriptionList)
        {
            lock (this._syncroot) //protect _subscriptions
                this._subscriptions.AddRange(subscriptionList);

            MarketDataRequest.EventMarket evtSubStatus = new MarketDataRequest.EventMarket(Event.EventType.SUBSCRIPTION_STATUS, null, subscriptionList);
            if (this._asyncHandler != null)
            {
                this._asyncHandler(evtSubStatus, this);
            }
        }
Exemple #8
0
        public bool StartAsync()
        {
            this._sessionState = SessionStateType.started;
            MarketDataRequest.EventMarket evtSessionStatus = new MarketDataRequest.EventMarket(Event.EventType.SESSION_STATUS, null, null);
            MarketDataRequest.EventMarket evtServiceStatus = new MarketDataRequest.EventMarket(Event.EventType.SERVICE_STATUS, new CorrelationID(), null);

            if (this._asyncHandler != null)
            {
                this._asyncHandler(evtSessionStatus, this);
                this._asyncHandler(evtServiceStatus, this);
            }
            
            return true;
        }
Exemple #9
0
        internal EventMarket(EventType evtType, CorrelationID corr, IEnumerable <Subscription> subscriptions) //use for subscribing
        {
            this._messages = new List <Message>();

            switch (evtType)
            {
            case EventType.SESSION_STATUS:
                base._type = evtType;
                MessageMarketSessionOpened msgSessionOpened = new MessageMarketSessionOpened();
                this._messages.Add(msgSessionOpened);
                break;

            case EventType.SERVICE_STATUS:
                base._type = evtType;
                MessageMarketServiceStatus msgServiceStatus = new MessageMarketServiceStatus(corr);
                this._messages.Add(msgServiceStatus);
                break;

            case EventType.SUBSCRIPTION_STATUS:
                base._type = evtType;
                foreach (var item in subscriptions)
                {
                    MessageMarketSubscriptionStarted msgSubStatus = new MessageMarketSubscriptionStarted(item);
                    this._messages.Add(msgSubStatus);
                }
                break;

            case EventType.SUBSCRIPTION_DATA:
                base._type = evtType;
                foreach (var item in subscriptions)
                {
                    MessageMarketSubscriptionData msgSubData = new MessageMarketSubscriptionData(item, EventMarket.GenerateFakeMessageData(item));
                    this._messages.Add(msgSubData);
                }
                break;

            default:
                throw new NotImplementedException(string.Format("BEmu.MarketDataRequest.EventMarket.EventMarket: doesn't expect EventType {1}", evtType.ToString()));
            }
        }