public void PublishPriceTest() { RabbitMQPublisher.RMQFactory.Instance().HostName = hostName; var channel = RabbitMQPublisher.RMQFactory.Instance().GetRMQChannel(KaiTrade.Interfaces.MQExchanges.DEFAULT); Assert.IsNotNull(channel); RabbitMQPublisher.RMQ rmqHelper = new RabbitMQPublisher.RMQ(); KaiTrade.Interfaces.IPXUpdate pxu = new L1PriceSupport.PXUpdateBase(); pxu.Mnemonic = "DELL"; pxu.BidPrice = 22M; pxu.BidSize = 101; pxu.OfferPrice = 23M; pxu.OfferSize = 99; rmqHelper.PublishPrice("DELL", pxu); }
public void PublishPriceListenTest() { RabbitMQPublisher.RMQFactory.Instance().HostName = hostName; var channel = RabbitMQPublisher.RMQFactory.Instance().GetRMQChannel(KaiTrade.Interfaces.MQExchanges.DEFAULT); Assert.IsNotNull(channel); listner = new RabbitMQPublisher.RMQListner(); listner.SubscribeInfo(); listner.OnRMQMessage += OnRMQMessage; listner.SubscribePricesRMQ("DELL"); RabbitMQPublisher.RMQ rmqHelper = new RabbitMQPublisher.RMQ(); KaiTrade.Interfaces.IPXUpdate pxu = new L1PriceSupport.PXUpdateBase(); pxu.Mnemonic = "DELL"; pxu.BidPrice = 22M; pxu.BidSize = 101; pxu.OfferPrice = 23M; pxu.OfferSize = 99; rmqHelper.PublishPrice("DELL", pxu); System.Threading.Thread.Sleep(10000); }
/// <summary> /// publish a quote for the given mnemonic /// </summary> /// <param name="myMnemonic">mnemonic/subject key</param> /// <param name="instrument">CQG instrument that has changed</param> private void publishQuote(string myMnemonic, CQGInstrument instrument) { try { L1PriceSupport.PXUpdateBase pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = myMnemonic; if (instrument.Bid.IsValid) { pxupdate.BidSize = instrument.Bid.Volume; pxupdate.BidPrice = (decimal)instrument.Bid.Price; pxupdate.Ticks = instrument.Bid.ServerTimestamp.Ticks; } if (instrument.Ask.IsValid) { pxupdate.OfferSize = instrument.Ask.Volume; pxupdate.OfferPrice = (decimal)instrument.Ask.Price; pxupdate.Ticks = instrument.Ask.ServerTimestamp.Ticks; } if (instrument.Trade.IsValid) { switch (instrument.Trade.Type) { /* case eQuoteType.qtTrade: pxupdate.TradePrice = (decimal)instrument.Trade.Price; pxupdate.TradeVolume = instrument.Trade.Volume; pxupdate.LastTradeTicks = instrument.Trade.ServerTimestamp.Ticks; break; */ case eQuoteType.qtDayHigh: pxupdate.DayHigh = (decimal)instrument.Trade.Price; pxupdate.TradePrice = 0; pxupdate.TradeVolume = 0; break; case eQuoteType.qtDayLow: pxupdate.DayLow = (decimal)instrument.Trade.Price; pxupdate.TradePrice = 0; pxupdate.TradeVolume = 0; break; case eQuoteType.qtDayOpen: //myPub.Open = instrument.Trade.Price.ToString(); break; default: pxupdate.TradePrice = null; pxupdate.TradeVolume = null; break; } pxupdate.Ticks = instrument.Timestamp.Ticks; } else { pxupdate.TradePrice = 0; pxupdate.TradeVolume = 0; } ApplyPriceUpdate(pxupdate); } catch (Exception myE) { log.Error("publishQuote", myE); } }
/// <summary> /// publish a quote for the given mnemonic /// </summary> /// <param name="myMnemonic">mnemonic/subject key</param> /// <param name="instrument">CQG instrument that has changed</param> private void publishTradeUpdate(string myMnemonic, CQGInstrument instrument, CQGQuote quote) { try { L1PriceSupport.PXUpdateBase pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = myMnemonic; pxupdate.DriverTag = "T"; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.trade; if (instrument.Bid.IsValid) { pxupdate.BidSize = instrument.Bid.Volume; pxupdate.BidPrice = (decimal)instrument.Bid.Price; pxupdate.Ticks = instrument.Bid.ServerTimestamp.Ticks; } if (instrument.Ask.IsValid) { pxupdate.OfferSize = instrument.Ask.Volume; pxupdate.OfferPrice = (decimal)instrument.Ask.Price; pxupdate.Ticks = instrument.Ask.ServerTimestamp.Ticks; } pxupdate.TradePrice = (decimal)quote.Price; pxupdate.ServerTicks = quote.ServerTimestamp.Ticks; if (quote.HasVolume) { pxupdate.TradeVolume = quote.Volume; } ApplyPriceUpdate(pxupdate); } catch (Exception myE) { log.Error("publishTradeUpdate", myE); } }
/// <summary> /// This event is fired when any of the instrument quotes or dynamic instrument properties are changed. /// </summary> /// <param name="instrument">Changed instrument.</param> /// <param name="quotes">Collection of changed quotes.</param> /// <param name="props">Collection of changed dynamic properties. </param> private void cel_InstrumentChanged(CQGInstrument instrument, CQGQuotes quotes, CQGInstrumentProperties props) { try { lock (m_InstrToken1) { try { if (!_publisherRegister.ContainsKey(instrument.FullName)) { return; } if (!_pXContexts.ContainsKey(instrument.FullName)) { _pXContexts.Add(instrument.FullName, new DriverBase.PXUpdateContext(instrument.FullName)); } L1PriceSupport.PXUpdateBase pxupdate = null; if (quotes.Count > 0) { foreach (CQGQuote quote in quotes) { switch (quote.Type) { case eQuoteType.qtTrade: pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = instrument.FullName; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.trade; pxupdate.DriverTag = "Q"; if (quote.HasVolume) { pxupdate.TradeVolume = quote.Volume; } else { pxupdate.TradeVolume = 0; } pxupdate.TradePrice = (decimal)quote.Price; pxupdate.ServerTicks = quote.ServerTimestamp.Ticks; if (_pXContexts[instrument.FullName].IsUpdatedTrade(pxupdate)) { ApplyPriceUpdate(pxupdate); } break; case eQuoteType.qtAsk: pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = instrument.FullName; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.ask; pxupdate.DriverTag = "Q"; if (quote.HasVolume) { pxupdate.OfferSize = quote.Volume; } else { pxupdate.OfferSize = 0; } pxupdate.OfferPrice = (decimal)quote.Price; pxupdate.ServerTicks = quote.ServerTimestamp.Ticks; if (_pXContexts[instrument.FullName].IsUpdatedOffer(pxupdate)) { ApplyPriceUpdate(pxupdate); } break; case eQuoteType.qtBid: pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = instrument.FullName; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.bid; pxupdate.DriverTag = "Q"; if (quote.HasVolume) { pxupdate.BidSize = quote.Volume; } else { pxupdate.BidSize = 0; } pxupdate.BidPrice = (decimal)quote.Price; pxupdate.ServerTicks = quote.ServerTimestamp.Ticks; if (_pXContexts[instrument.FullName].IsUpdatedBid(pxupdate)) { ApplyPriceUpdate(pxupdate); } break; default: pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = instrument.FullName; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.none; pxupdate.DriverTag = "Q"; if (instrument.Bid.IsValid) { pxupdate.BidSize = instrument.Bid.Volume; pxupdate.BidPrice = (decimal)instrument.Bid.Price; pxupdate.Ticks = instrument.Bid.ServerTimestamp.Ticks; } if (instrument.Ask.IsValid) { pxupdate.OfferSize = instrument.Ask.Volume; pxupdate.OfferPrice = (decimal)instrument.Ask.Price; pxupdate.Ticks = instrument.Ask.ServerTimestamp.Ticks; } pxupdate.TradePrice = (decimal)instrument.Trade.Price; pxupdate.ServerTicks = instrument.ServerTimestamp.Ticks; if (instrument.Trade.HasVolume) { pxupdate.TradeVolume = instrument.Trade.Volume; } ApplyPriceUpdate(pxupdate); //publishQuote(instrument); break; } } } else { } // there were no quotes pxupdate = new L1PriceSupport.PXUpdateBase(m_ID); pxupdate.Mnemonic = instrument.FullName; pxupdate.UpdateType = KaiTrade.Interfaces.PXUpdateType.none; pxupdate.DriverTag = "I"; if (instrument.Bid.IsValid) { pxupdate.BidSize = instrument.Bid.Volume; pxupdate.BidPrice = (decimal)instrument.Bid.Price; pxupdate.Ticks = instrument.Bid.ServerTimestamp.Ticks; } if (instrument.Ask.IsValid) { pxupdate.OfferSize = instrument.Ask.Volume; pxupdate.OfferPrice = (decimal)instrument.Ask.Price; pxupdate.Ticks = instrument.Ask.ServerTimestamp.Ticks; } if (instrument.Trade.IsValid) { pxupdate.TradePrice = (decimal)instrument.Trade.Price; pxupdate.ServerTicks = instrument.Ask.ServerTimestamp.Ticks; if (instrument.Trade.HasVolume) { pxupdate.TradeVolume = instrument.Trade.Volume; } } ApplyPriceUpdate(pxupdate); //publishQuote(instrument); } catch (Exception ex) { log.Error("cel_InstrumentChanged", ex); } } } catch { } }