コード例 #1
0
        IObservable <DrasticChange> GetTicksQuery(IStockTicker ticker)
        {
            IObservable <StockTick> ticks =
                Observable.FromEventPattern <EventHandler <StockTick>, StockTick>(
                    h => ticker.StockTick += h,
                    h => ticker.StockTick -= h)
                .Select(tickEvent => tickEvent.EventArgs)
                .Synchronize();

            var drasticChanges =
                from tick in ticks
                group tick by tick.QuoteSymbol
                into company
                from tickPair in company.Buffer(2, 1)
                let changeRatio = Math.Abs((tickPair[1].Price - tickPair[0].Price) / tickPair[0].Price)
                                  where changeRatio > maxChangeRatio
                                  select new DrasticChange()
            {
                Symbol      = company.Key,
                ChangeRatio = changeRatio,
                OldPrice    = tickPair[0].Price,
                NewPrice    = tickPair[1].Price
            };

            return(drasticChanges);
        }
コード例 #2
0
        public StockMonitor(IStockTicker ticker)
        {
            const decimal maxChangeRatio = 0.1m;

            //creating an observable from the StockTick event, each notification will carry only the eventargs and will be synchronized
            IObservable <StockTick> ticks =
                Observable.FromEventPattern <EventHandler <StockTick>, StockTick>(
                    h => ticker.StockTick += h,
                    h => ticker.StockTick -= h)
                .Select(tickEvent => tickEvent.EventArgs)
                .Synchronize();

            DrasticChanges =
                from tick in ticks
                group tick by tick.QuoteSymbol
                into company
                from tickPair in company.Buffer(2, 1)
                let changeRatio = Math.Abs((tickPair[1].Price - tickPair[0].Price) / tickPair[0].Price)
                                  where changeRatio > maxChangeRatio
                                  select new DrasticChange()
            {
                Symbol      = company.Key,
                ChangeRatio = changeRatio,
                OldPrice    = tickPair[0].Price,
                NewPrice    = tickPair[1].Price
            };
        }
コード例 #3
0
 IObservable <DrasticChange> GetTicksMethod(IStockTicker ticker)
 {
     return(Observable.FromEventPattern <EventHandler <StockTick>, StockTick>(
                h => ticker.StockTick += h,
                h => ticker.StockTick -= h)
            .Select(tickEvent => tickEvent.EventArgs)
            .Synchronize()
            .GroupBy(tick => tick.QuoteSymbol)         //groups emits by ticker
            .SelectMany(t => t)
            .Buffer(2, 1)
            .Select(l =>
                    new
     {
         symbol = l[0].QuoteSymbol,
         changeRatio = Math.Abs(l[1].Price - l[0].Price),
         oldPrice = l[0].Price,
         newPrice = l[1].Price
     })
            .Where(cr => cr.changeRatio > maxChangeRatio)
            .Select(cr => new DrasticChange()
     {
         Symbol = cr.symbol,
         ChangeRatio = cr.changeRatio,
         OldPrice = cr.oldPrice,
         NewPrice = cr.newPrice
     }));
 }
コード例 #4
0
ファイル: sample12.cs プロジェクト: causapolis1/docs
 public StockTickerHub(IStockTicker stockTicker)
 {
     if (stockTicker == null)
     {
         throw new ArgumentNullException("stockTicker");
     }
     _stockTicker = stockTicker;
 }
コード例 #5
0
        public RxStockMonitor(IStockTicker ticker)
        {
            // var ticks = GetTicksQuery(ticker);
            var ticks = GetTicksMethod(ticker);

            subscription =
                ticks.Subscribe(change =>
            {
                Console.WriteLine("Stock:{0} has changed with {1} ratio, Old Price:{2} New Price:{3}", change.Symbol,
                                  change.ChangeRatio,
                                  change.OldPrice,
                                  change.NewPrice);
            },
                                ex => { Console.WriteLine($"Error {ex.Message}"); }, //#C
                                () => { Console.WriteLine("Finished"); });           //#C
        }
コード例 #6
0
        static void Main(string[] args)
        {
            string     baseAddress = "soap.udp://224.0.0.1:40000";
            UdpBinding myBinding   = new UdpBinding();
            ChannelFactory <IStockTicker> factory = new ChannelFactory <IStockTicker>(myBinding, new EndpointAddress(baseAddress));
            IStockTicker proxy = factory.CreateChannel();

            while (true)
            {
                // This will continue to mulicast stock information
                proxy.SendStockInfo(GetStockInfo());
                int x = proxy.ResponseStockInfo(GetStockInfo());
                Console.WriteLine(String.Format("sent stock info at {0}, the cound is {1}", DateTime.Now, x));
                // Wait for one second before sending another update
                System.Threading.Thread.Sleep(new TimeSpan(0, 0, 1));
            }
        }
コード例 #7
0
        public RxStockMonitor(IStockTicker ticker)
        {
            const decimal maxChangeRatio = 0.1m;

            //creating an observable from the StockTick event, each notification will carry only the eventargs and will be synchronized
            IObservable <StockTick> ticks =
                Observable.FromEventPattern <EventHandler <StockTick>, StockTick>(
                    h => ticker.StockTick += h,
                    h => ticker.StockTick -= h)
                .Select(tickEvent => tickEvent.EventArgs)
                .Synchronize();

            var drasticChanges =
                from tick in ticks
                group tick by tick.QuoteSymbol
                into company
                from tickPair in company.Buffer(2, 1)
                let changeRatio = Math.Abs((tickPair[1].Price - tickPair[0].Price) / tickPair[0].Price)
                                  where changeRatio > maxChangeRatio
                                  select new DrasticChange()
            {
                Symbol      = company.Key,
                ChangeRatio = changeRatio,
                OldPrice    = tickPair[0].Price,
                NewPrice    = tickPair[1].Price
            };

            DrasticChanges = drasticChanges;

            _subscription =
                drasticChanges.Subscribe(change =>
            {
                Console.WriteLine("Stock:{0} has changed with {1} ratio, Old Price:{2} New Price:{3}", change.Symbol,
                                  change.ChangeRatio,
                                  change.OldPrice,
                                  change.NewPrice);
            },
                                         ex => { /* code that handles erros */ },                       //#C
                                         () => { /* code that handles the observable completenss */ }); //#C
        }
コード例 #8
0
        public RxStockMonitor(IStockTicker ticker)
        {
            const decimal maxChangeRatio = 0.1m;

            //creating an observable from the StockTick event, each notification will carry only the eventargs and will be synchronized
            IObservable<StockTick> ticks =
                    Observable.FromEventPattern<EventHandler<StockTick>, StockTick>(
                        h => ticker.StockTick += h,
                        h => ticker.StockTick -= h)
                        .Select(tickEvent => tickEvent.EventArgs)
                        .Synchronize();

            var drasticChanges =
                from tick in ticks
                group tick by tick.QuoteSymbol
                into company
                from tickPair in company.Buffer(2, 1)
                let changeRatio = Math.Abs((tickPair[1].Price - tickPair[0].Price) / tickPair[0].Price)
                where changeRatio > maxChangeRatio
                select new DrasticChange()
                {
                    Symbol = company.Key,
                    ChangeRatio = changeRatio,
                    OldPrice = tickPair[0].Price,
                    NewPrice = tickPair[1].Price
                };

            DrasticChanges = drasticChanges;

            _subscription =
                drasticChanges.Subscribe(change =>
                    {
                        Console.WriteLine("Stock:{0} has changed with {1} ratio, Old Price:{2} New Price:{3}", change.Symbol,
                            change.ChangeRatio,
                            change.OldPrice,
                            change.NewPrice);
                    },
                    ex => { /* code that handles erros */}, //#C
                    () => {/* code that handles the observable completenss */}); //#C
        }
コード例 #9
0
 public StockTickerHub(IStockTicker stockTicker)
 {
     _stockTicker = stockTicker;
 }
コード例 #10
0
 public StockQuoteHub(IStockTicker stockTicker)
 {
     _stockTicker = stockTicker;
 }
コード例 #11
0
        //public StockTickerHub() :
        //    this(StockTicker.Instance)
        //{

        //}

        public StockTickerHub(IStockTicker stockTicker, ILifetimeScope lifetimeScope)
        {
            _stockTicker   = stockTicker;
            _lifetimeScope = lifetimeScope.BeginLifetimeScope();
        }
コード例 #12
0
 //Remove this constructor
 //public StockTickerHub() : this(StockTicker.Instance) { }
 //Changing this to the interface
 public StockTickerHub(IStockTicker stockTicker)
 {
     _stockTicker = stockTicker;
 }