public void ShouldExecuteInstructionWhenThereIsEnoughLiquidityOnOneMarket() { // Given market A: 150 @ $100, market B: 55 @ $101 // When Investor wants to buy 125 stocks @ $100 Then SOR can execute at the requested price var marketA = new Market { SellQuantity = 150, SellPrice = 100M }; var marketB = new Market { SellQuantity = 55, SellPrice = 101M }; var marketsInvolved = new[] { marketA, marketB }; ICanRouteOrders canRouteOrders = null;//new OrderRoutingService(marketsInvolved); ICanReceiveMarketData canReceiveMarketData = new MarketDataProvider(marketsInvolved); IProvideMarkets provideMarkets = new MarketProvider(marketsInvolved); var sor = new SmartOrderRoutingEngine(provideMarkets, canRouteOrders, canReceiveMarketData); var investorInstructionDto = new InvestorInstructionDto(new InvestorInstructionIdentifierDto(), Way.Buy, quantity: 125, price: 100M); OrderExecutedEventArgs orderExecutedEventArgs = null; sor.Subscribe(investorInstructionDto.UniqueIdentifier, (args) => { orderExecutedEventArgs = args; }, null); //investorInstruction.Executed += (sender, args) => { orderExecutedEventArgs = args; }; // orderRequest.Route(); ? sor.Route(investorInstructionDto); // TODO :introduce autoreset event instead Check.That(orderExecutedEventArgs).HasFieldsWithSameValues(new { Way = Way.Buy, Quantity = 125, Price = 100M }); }
/// <summary> /// Acts like a composition root for the SOR Hexagonal Architecture. /// </summary> /// <param name="marketGateways">The list of ApiMarketGateway the SOR must interact with.</param> /// <returns>The adapter we must use as Investors in order to give investment instructions.</returns> public static InvestorInstructionsAdapter ComposeTheHexagon(params ApiMarketGateway[] marketGateways) { // Step1: instantiates the adapter(s) the (SOR) domain will need to work with through the Dependency Inversion principle. var marketGatewaysAdapter = new MarketsAdapter(marketGateways); // Step2: instantiates the SOR domain entry point. var sor = new SmartOrderRoutingEngine(marketGatewaysAdapter, marketGatewaysAdapter, marketGatewaysAdapter); // Step3: instantiates the adapters we will use to interact with our domain. var investorInstructionAdapter = new InvestorInstructionsAdapter(sor); return(investorInstructionAdapter); }
private static SmartOrderRoutingEngine CreateSmartOrderRoutingEngine(Market[] markets) { var routingEngine = new SmartOrderRoutingEngine(new MarketProvider(markets), null, new MarketDataProvider(markets)); return routingEngine; }