public void Should_succeeded_when_liquidity_is_available_even_if_one_Market_rejects() { // Given market A: 150 @ $100, market B: 55 @ $101 // When Investor wants to buy 125 stocks @ $100 Then SOR can execute at the requested MarketPrice var marketA = new ApiMarketGateway("NYSE (New York)", sellQuantity: 50, sellPrice: 100M); var rejectingMarket = new ApiMarketGateway("LSE (London)", sellQuantity: 50, sellPrice: 100M, orderPredicate: _ => false); var investorInstructionAdapter = CompositionRootHelper.ComposeTheHexagon(marketA, rejectingMarket); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 50, price: 100M, goodTill: DateTime.Now.AddMinutes(5)); // Subscribes to the instruction's events InstructionExecutedDto instructionExecuted = null; InstructionFailedDto instructionFailed = null; investorInstructionAdapter.Route(investorInstructionDto, (args) => { instructionExecuted = args; }, (args) => { instructionFailed = args; }); Check.That(instructionExecuted).IsNotNull(); Check.That(instructionFailed).IsNull(); Check.That(marketA.SellQuantity).IsEqualTo(0); Check.That(rejectingMarket.SellQuantity).IsEqualTo(50); }
public void Should_failed_when_Order_exceeds_all_Market_capacity_and_partial_execution_not_allowed() { // Given market A: 150 @ $100, market B: 55 @ $101 // When Investor wants to buy 125 stocks @ $100 Then SOR can execute at the requested MarketPrice var marketA = new ApiMarketGateway("NYSE (New York)", sellQuantity: 15, sellPrice: 100M); var marketB = new ApiMarketGateway("CME (Chicago)", sellQuantity: 55, sellPrice: 101M); var investorInstructionAdapter = CompositionRootHelper.ComposeTheHexagon(marketA, marketB); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 125, price: 100M, allowPartialExecution: false); // Subscribes to the instruction's events InstructionExecutedDto instructionExecuted = null; InstructionFailedDto instructionFailed = null; investorInstructionAdapter.Route(investorInstructionDto, (args) => { instructionExecuted = args; }, (args) => { instructionFailed = args; }); // Couldn't execute because order with excessive QuantityOnTheMarket Check.That(instructionFailed.Reason).IsNotNull().And.IsEqualIgnoringCase("Excessive quantity!"); Check.That(instructionExecuted).IsNull(); Check.That(marketA.SellQuantity).IsEqualTo(15); Check.That(marketB.SellQuantity).IsEqualTo(55); }