Beispiel #1
0
 protected void NotifySubscribers(IPriceUpdate priceUpdate)
 {
     foreach (var c in _priceUpdateSubscribers)
     {
         c.OnPriceUpdate(priceUpdate);
     }
 }
        private void WaitingForPriceHistory()
        {
            Receive <PriceHistory>(p =>
            {
                if (p.HistoricalPrices.IsEmpty)
                {
                    _commandHandlerActor.Tell(new CommandResponse($"No historical price data for [{_tickerSymbol}] - waiting for updates.", false));
                    BecomePriceUpdates();
                    return;
                }

                _currentPrice = p.CurrentPriceUpdate;
                foreach (var e in p.HistoricalPrices)
                {
                    _commandHandlerActor.Tell(new CommandResponse(e.ToString(), false));
                }

                BecomePriceUpdates();
            });

            Receive <ReceiveTimeout>(t =>
            {
                _commandHandlerActor.Tell(new CommandResponse($"No historical price data for [{_tickerSymbol}] - waiting for updates.", false));
                BecomePriceUpdates();
            });

            ReceiveAny(_ => Stash.Stash());
        }
Beispiel #3
0
        private void WaitingForPriceHistory()
        {
            Receive <PriceAndVolumeSnapshot>(p =>
            {
                if (p.PriceUpdates.Length == 0)
                {
                    _commandHandlerActor.Tell(new CommandResponse($"No historical price data for [{_tickerSymbol}] - waiting for updates.", false));
                    BecomeWaitingForSubscribe();
                    return;
                }

                _currentPrice = p.PriceUpdates.Last();
                foreach (var e in p.PriceUpdates)
                {
                    _commandHandlerActor.Tell(new CommandResponse(e.ToString(), false));
                }

                BecomeWaitingForSubscribe();
            });

            Receive <ReceiveTimeout>(t =>
            {
                _commandHandlerActor.Tell(new CommandResponse($"No historical price data for [{_tickerSymbol}] - waiting for updates.", false));
                BecomeWaitingForSubscribe();
            });

            ReceiveAny(_ => Stash.Stash());
        }
 public int CompareTo(IPriceUpdate other)
 {
     if (other is PriceChanged c)
     {
         return(CompareTo(c));
     }
     throw new ArgumentException();
 }
        public PriceHistory WithPrice(IPriceUpdate update)
        {
            if (!update.StockId.Equals(StockId))
            {
                throw new ArgumentOutOfRangeException($"Expected ticker symbol {StockId} but found {update.StockId}", nameof(update));
            }

            return(new PriceHistory(StockId, HistoricalPrices.Add(update)));
        }
        private void PriceUpdates()
        {
            Receive <IPriceUpdate>(p =>
            {
                _currentPrice = p;
                _commandHandlerActor.Tell(new CommandResponse(p.ToString(), false));
            });

            Receive <Terminated>(t =>
            {
                _commandHandlerActor.Tell(new CommandResponse("Price View Actor terminated."));
                Context.Stop(Self);
            });
        }
Beispiel #7
0
 public async Task WritePriceChanged(IPriceUpdate e)
 {
     await WriteMessage(e.ToString());
 }
Beispiel #8
0
 public void OnPriceUpdate(IPriceUpdate update)
 {
     Console.WriteLine("Symbol: {0}   Bid: {1}   Ask: {2}   Timestamp: {3}", update.Instrument, update.BidPrice,
                       update.AskPrice, update.ServerTimestamp);
 }