public void ConsumerSubscribe(IMarketDataConsumer <T> cons) { //Experiment: test to see if spreading the load between two straggler handlers improves performance /*if (!_disruptorHasStarted) * { * BufferEventHandler<T> newHandler = new BufferEventHandler<T>(); * newHandler.ThrowEvent += cons.NewDataHandler; * _eventHandlers.Add(newHandler); * } * else * {*/ if (_numExtraHandlersAdded % 2 == 0) { stragglerHandlers.Enqueue(cons); } else { stragglerHandlers2.Enqueue(cons); } _numExtraHandlersAdded++; //} }
public bool AddTradeConsumer(InstrInfo[] instruments, IMarketDataConsumer <TradeInfo> consumer) { string instrumentsString = Utilities.InstrToStr(instruments); if (_tradeSubsciberDictionary.ContainsKey(instrumentsString)) { //this implies that a dataconsumer has alread subscribed, and thus that we are //already subscribed to this quote's feed if (_tradeSubsciberDictionary[instrumentsString].Contains(consumer)) { return(false); } else { _tradeSubsciberDictionary[instrumentsString].Add(consumer); } } else { //first time we are hearing about this instrument _tradeSubsciberDictionary[instrumentsString] = new List <IMarketDataConsumer <TradeInfo> >(5); _tradeSubsciberDictionary[instrumentsString].Add(consumer); SubscribeToTradeFeed(instruments); } return(_tradeFeed.AddTradeConsumer(instrumentsString, consumer)); }
public void ConsumerUnsubscribe(IMarketDataConsumer <T> cons) { if (stragglerHandlers.Contains <IMarketDataConsumer <T> >(cons)) { lock (stragglerHandlers) { //WILL HAVE TO WRITE THIS EVENTUALLY } } }
public void getLastSpreadQuote(InstrInfo[] instruments, IMarketDataConsumer <QuoteBook> cons) { Console.WriteLine(_spreadInitialQuotes.Keys.Count); ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { GetSpreadQuote(instruments, cons); }), null); }
public bool AddTradeConsumer(string instrumentName, IMarketDataConsumer <TradeInfo> consumer) { if (_tradeFeedBuffers.ContainsKey(instrumentName)) { _tradeFeedBuffers[instrumentName].ConsumerSubscribe(consumer); return(true); } else { _tradeFeedBuffers[instrumentName] = new TradeFeedBuffer(instrumentName); _tradeFeedBuffers[instrumentName].ConsumerSubscribe(consumer); return(false); } }
public void GetSpreadQuote(InstrInfo[] instruments, IMarketDataConsumer <QuoteBook> cons) { if (instruments.Length > 1) { Console.WriteLine("Getting spread quote..."); FastOMS.Data_Structures.QuoteBook qb = new Data_Structures.QuoteBook(); while (!_spreadInitialQuotes.TryGetValue(Utilities.InstrToStr(instruments), out qb)) { Thread.Sleep(1000); Console.WriteLine("waiting for spread quote"); } cons.NewDataHandler(qb); } }
public bool AddQuoteConsumer(string instrumentName, IMarketDataConsumer <QuoteBook> consumer) { if (_quoteFeedBuffers.ContainsKey(instrumentName)) { _quoteFeedBuffers[instrumentName].ConsumerSubscribe(consumer); return(true); } else { bool success = _quoteFeedBuffers.TryAdd(instrumentName, new QuoteFeedBuffer(instrumentName)); // _quoteFeedBuffers[instrumentName] = new QuoteFeedBuffer(instrumentName); _quoteFeedBuffers[instrumentName].ConsumerSubscribe(consumer); return(false); } }
public void RemoveTradeConsumer(InstrInfo[] instruments, IMarketDataConsumer <TradeInfo> consumer) { string instrumentsString = Utilities.InstrToStr(instruments); if (_tradeSubsciberDictionary.ContainsKey(instrumentsString)) { //this implies that a dataconsumer has alread subscribed, and thus that we are //already subscribed to this quote's feed if (_tradeSubsciberDictionary[instrumentsString].Contains(consumer)) { _tradeSubsciberDictionary[instrumentsString].Remove(consumer); if (_quoteSubsciberDictionary[instrumentsString].Count == 0) { //UnsubscribeFromInstrumentTrades(instruments); _tradeFeed._tradeFeedBuffers[instrumentsString].ConsumerUnsubscribe(consumer); } } } else { return; } }
public bool AddQuoteConsumer(InstrInfo[] instruments, IMarketDataConsumer <QuoteBook> consumer) { Console.WriteLine("add quote consumer: " + Utilities.InstrToStr(instruments)); string instrumentsString = Utilities.InstrToStr(instruments); if (_quoteSubsciberDictionary.ContainsKey(instrumentsString)) { //this implies that a dataconsumer has alread subscribed, and thus that we are //already subscribed to this quote's feed if (_quoteSubsciberDictionary[instrumentsString].Contains(consumer)) { return(false); } else { _quoteSubsciberDictionary[instrumentsString].Add(consumer); } } else { //first time we are hearing about this instrument _quoteSubsciberDictionary[instrumentsString] = new List <IMarketDataConsumer <QuoteBook> >(5); _quoteSubsciberDictionary[instrumentsString].Add(consumer); if (instruments.Length > 1) { SubscribeToSpreadQuoteFeed(instruments); } else { SubscribeToQuoteFeed(instruments); } } return(_quoteFeed.AddQuoteConsumer(instrumentsString, consumer)); }