public void Should_stop_sending_Orders_to_a_Market_after_3_rejects() { var rejectingMarket = new ApiMarketGateway("LSE (London)", sellQuantity: 100, sellPrice: 100M, orderPredicate: order => false); var investorInstructionAdapter = CompositionRootHelper.ComposeTheHexagon(rejectingMarket); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 50, price: 100M, goodTill: DateTime.Now.AddMinutes(5)); investorInstructionAdapter.Route(investorInstructionDto, (args) => { }, (args) => { }); Check.That(rejectingMarket.TimesSent).IsEqualTo(3); Check.That(rejectingMarket.SellQuantity).IsEqualTo(100); }
public void Should_execute_Instruction_when_there_is_enough_liquidity_on_the_Markets() { // Given market A: 100 @ $100, market B: 55 @ $100 // When Investor wants to buy 125 stocks @ $100 Then SOR can execute at the requested MarketPrice var marketA = new ApiMarketGateway("NYSE (New York)", sellQuantity: 100, sellPrice: 100M); var marketB = new ApiMarketGateway("CME (Chicago)", sellQuantity: 55, sellPrice: 100M); var investorInstructionAdapter = CompositionRootHelper.ComposeTheHexagon(marketA, marketB); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 125, price: 100M); InstructionExecutedDto instructionExecuted = null; investorInstructionAdapter.Route(investorInstructionDto, (args) => { instructionExecuted = args; }, null); Check.That(instructionExecuted).HasFieldsWithSameValues(new { Way = Way.Buy, Quantity = 125, Price = 100M }); Check.That(marketA.SellQuantity).IsEqualTo(19); Check.That(marketB.SellQuantity).IsEqualTo(11); }
static void Main(string[] args) { var marketA = new ApiMarketGateway("NYSE (New York)", sellQuantity: 150, sellPrice: 100M); var marketB = new ApiMarketGateway("CME (Chicago)", sellQuantity: 55, sellPrice: 101M); var investorAdapter = CompositionRootHelper.ComposeTheHexagon(marketA, marketB); System.Console.WriteLine("SOR connected to markets: {0} and {1}", marketA.MarketName, marketB.MarketName); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 125, price: 100M); System.Console.WriteLine(); System.Console.WriteLine("Type 'Enter' to submit the following investor instruction: [{0}]\n\n", investorInstructionDto); System.Console.ReadLine(); investorAdapter.Route(investorInstructionDto, arg => { System.Console.WriteLine("Instruction executed: [{0}]", arg); }, eventArgs => {}); System.Console.WriteLine(); System.Console.WriteLine("Type 'Enter' to exit"); System.Console.ReadLine(); }
public void Should_execute_Orders_on_weighted_average_of_available_quantities() { // 25 premier ; 75 % sur le second marché // Given market A: 100 @ $100, market B: 50 @ $100 // When Investor wants to buy 75 stocks @ $100 Then SOR can execute at the requested MarketPrice // And execution is: 50 stocks on MarketA and 25 stocks on MarketB var marketA = new ApiMarketGateway("NYSE (New York)", sellQuantity: 100, sellPrice: 100M); var marketB = new ApiMarketGateway("CME (Chicago)", sellQuantity: 50, sellPrice: 100M); var investorInstructionAdapter = CompositionRootHelper.ComposeTheHexagon(marketA, marketB); var investorInstructionDto = new InvestorInstructionDto(Way.Buy, quantity: 75, price: 100M); InstructionExecutedDto instructionExecuted = null; investorInstructionAdapter.Route(investorInstructionDto, (args) => { instructionExecuted = args; }, null); Check.That(instructionExecuted).HasFieldsWithSameValues(new { Way = Way.Buy, Quantity = 75, Price = 100M }); Check.That(marketA.SellQuantity).IsEqualTo(50); Check.That(marketB.SellQuantity).IsEqualTo(25); }
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); }