Beispiel #1
0
        public void Should_rely_on_values_for_unicity()
        {
            var goodTill      = DateTime.Now;
            var dtoIdentifier = new InvestorInstructionIdentifierDto();

            var instruction          = new InvestorInstructionDto(dtoIdentifier, Way.Buy, 1, 1.1M, true, goodTill);
            var identicalInstruction = new InvestorInstructionDto(dtoIdentifier, Way.Buy, 1, 1.1M, true, goodTill);
            var dictionary           = new Dictionary <InvestorInstructionDto, int>();

            dictionary[instruction]          = 2;
            dictionary[identicalInstruction] = 3;

            Check.That(dictionary[instruction]).IsEqualTo(3);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public void Should_rely_on_values_for_equality()
        {
            var       investorInstructionIdentifier = 42;
            const Way Way      = Way.Buy;
            var       quantity = 1;
            var       price    = 23.3M;
            var       allowPartialExecution = true;
            var       goodTill = DateTime.Now;

            var dtoIdentifier              = new InvestorInstructionIdentifierDto();
            var firstInstruction           = new InvestorInstructionDto(dtoIdentifier, Way, quantity, price, allowPartialExecution, goodTill);
            var secondIdenticalInstruction = new InvestorInstructionDto(dtoIdentifier, Way, quantity, price, allowPartialExecution, goodTill);

            Check.That(firstInstruction).IsEqualTo(secondIdenticalInstruction);

            allowPartialExecution = false;
            var slightlyDifferentInstruction = new InvestorInstruction(investorInstructionIdentifier, Way, quantity, price, allowPartialExecution, goodTill);

            Check.That(slightlyDifferentInstruction).IsNotEqualTo(firstInstruction);
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }