Exemplo n.º 1
0
        public void start()
        {
            PublishInstruments();
            var instrs           = GetInstruments();
            var baseSubscription = instrs.Select(instr =>
            {
                Console.WriteLine("Subscribing to instrument {0} on {1}", instr,
                                  Thread.CurrentThread.ManagedThreadId);
                return(Observable.Create <FieldsUpdatedEventArgs>(obs =>
                                                                  new Subscription(instr, this._dispatcher, PriceSubscriptionType.InsideMarket, obs)).Catch <FieldsUpdatedEventArgs, Exception>(
                           ex =>
                {
                    Console.WriteLine(ex.Message);
                    return Observable.Empty <FieldsUpdatedEventArgs>();
                }));
            }
                                                 )
                                   .Merge()
                                   .Publish()
                                   .RefCount();


            baseSubscription.Subscribe(e =>
            {
                var mosaicPrice = PriceTransformer.ToMosaicPrice(e);
                var payload     = JsonConvert.SerializeObject(mosaicPrice);
                //Settled and Indicative settle prices for futures should be published on njkafka. Rest all should be on
                if (e.Fields.Instrument.Product.Type != ProductType.Option)
                {
                    _njKafkaClient.Publish("dev-tt-live-prices", mosaicPrice.InstrumentKey, payload);
                }

                //All prices should be published to awsk kafka
                if (e.Fields.Instrument.Product.Type == ProductType.Future)
                {
                    _awsKafkaClient.Publish("dev-tt-settles-futures", mosaicPrice.InstrumentKey, payload);
                }
                else if (e.Fields.Instrument.Product.Type == ProductType.Option)
                {
                    _awsKafkaClient.Publish("dev-tt-settles-options", mosaicPrice.InstrumentKey, payload);
                }
            });
        }
Exemplo n.º 2
0
        public void start()
        {
            PublishInstruments();
            var instrs           = GetInstruments();
            var baseSubscription = instrs.Select(instr =>
            {
                Console.WriteLine("Subscribing to instrument {0} on {1}", instr,
                                  Thread.CurrentThread.ManagedThreadId);
                tt2qep[instr.InstrumentDetails.Name] = instr.ToSymbol();
                qep2tt[instr.ToSymbol()]             = instr.InstrumentDetails.Name;
                return(Observable.Create <FieldsUpdatedEventArgs>(obs =>
                                                                  new Subscription(instr, _dispatcher, PriceSubscriptionType.MarketDepth, obs)).Catch <FieldsUpdatedEventArgs, Exception>(
                           ex =>
                {
                    Console.WriteLine(ex.Message);
                    return Observable.Empty <FieldsUpdatedEventArgs>();
                }));
            }
                                                 )
                                   .Merge()
                                   .Publish()
                                   .RefCount();


            var kafkaPublish = baseSubscription
                               .SubscribeOn(NewThreadScheduler.Default)
                               .ObserveOn(NewThreadScheduler.Default)
                               .Subscribe(d =>
            {
                //Console.WriteLine("Data {0} {1}", d, Thread.CurrentThread.ManagedThreadId);
                var mosaicPrice = PriceTransformer.ToMosaicPrice(d);
                // return ttData;
                _njKafkaClient.Publish("dev-tt-live-prices", mosaicPrice.InstrumentKey, JsonConvert.SerializeObject(mosaicPrice));
            }
                                          );

            _disposable.Add(kafkaPublish);
        }