Exemplo n.º 1
0
        private void ResolveBidMatching(TradingOrder tradingOrder)
        {
            var matchingAsks = _orderStore
                               .Asks
                               .Where(a => a.Price <= tradingOrder.Price)
                               .OrderBy(_ => _.Price)
                               .ToList(); // best price comes first

            ResolveMatching(tradingOrder, matchingAsks, (matchingAsk, shareToTrade) =>
            {
                var trade = new TradeSettled
                {
                    Price      = tradingOrder.Price,
                    Units      = shareToTrade,
                    AskOrderId = matchingAsk.OrderId,
                    StockId    = _stockId,
                    BidOrderId = tradingOrder.OrderId
                };
                _tradeSettled.Add(trade);
            });
        }
Exemplo n.º 2
0
        private void ResolveAskMatching(TradingOrder tradingOrder)
        {
            var matchingBids = _orderStore
                               .Bids
                               .Where(a => a.Price >= tradingOrder.Price)
                               .OrderByDescending(_ => _.Price) // best price comes first
                               .ToList();

            ResolveMatching(tradingOrder, matchingBids, (matchingBid, shareToTrade) =>
            {
                var trade = new TradeSettled
                {
                    Price      = tradingOrder.Price,
                    Units      = shareToTrade,
                    AskOrderId = tradingOrder.OrderId,
                    StockId    = _stockId,
                    BidOrderId = matchingBid.OrderId
                };
                _tradeSettled.Add(trade);
            });
        }
Exemplo n.º 3
0
        public void Settle_Bid_Order_Should_Publish_Event()
        {
            //arrange
            TradeSettled tradeSettled = null;

            SetupSubscribe <TradeSettled>((ts) => tradeSettled = ts);
            var bid = NewBid(units: 10, price: 99.99m);
            var ask = NewAsk(units: 10, price: 99.99m);

            //act
            _matcher.Tell(bid);
            _matcher.Tell(ask);
            Thread.Sleep(2000);

            //assert
            Assert.NotNull(tradeSettled);
            Assert.Equal(99.99m, tradeSettled.Price);
            Assert.Equal(10, tradeSettled.Units);
            Assert.Equal(ask.Order.OrderId, tradeSettled.AskOrderId);
            Assert.Equal(bid.Order.OrderId, tradeSettled.BidOrderId);
        }
Exemplo n.º 4
0
 private static void NotifyTradeSettled(TradeSettled trade) => Notify(trade);