public void Should_decrease_available_quantity_for_the_market_when_an_order_is_sent()
        {
            var marketGateway = new ApiMarketGateway(marketName: "euronext", sellQuantity: 50, sellPrice: 100M);

            var order = marketGateway.CreateMarketOrder(ApiMarketWay.Buy, quantity: 10);

            marketGateway.Send(order);

            Check.That(marketGateway.SellQuantity).IsEqualTo(40);
        }
        public void Should_Notify_LimitOrder_execution()
        {
            var marketGateway = new ApiMarketGateway(marketName: "euronext", sellQuantity: 50, sellPrice: 100M);

            var executed = false;
            var order    = marketGateway.CreateLimitOrder(ApiMarketWay.Buy, price: 100M, quantity: 10, allowPartial: false);

            marketGateway.OrderExecuted += (s, a) => executed = true;
            marketGateway.Send(order);

            Check.That(executed).IsTrue();
            Check.That(marketGateway.SellQuantity).IsEqualTo(40);
        }
        public void Should_failed_to_execute_order_when_quantity_is_excessive()
        {
            var marketGateway = new ApiMarketGateway(marketName: "euronext", sellQuantity: 50, sellPrice: 100M);

            var order = marketGateway.CreateMarketOrder(ApiMarketWay.Buy, quantity: 100);

            bool   failed        = false;
            string failureReason = null;

            marketGateway.OrderFailed += (s, failedEventArgs) =>
            {
                failed        = true;
                failureReason = failedEventArgs.FailureCause;
            };

            marketGateway.Send(order);

            Check.That(failed).IsTrue();
            Check.That(failureReason).IsEqualTo("Excessive quantity!");
        }
        public void Should_support_partial_execution_for_LimitOrder()
        {
            var marketGateway = new ApiMarketGateway(marketName: "euronext", sellQuantity: 50, sellPrice: 100M);

            var executed = false;
            var order    = marketGateway.CreateLimitOrder(ApiMarketWay.Buy, price: 100M, quantity: 110, allowPartial: true);

            var execQuantity = 0;

            marketGateway.OrderExecuted += (s, a) =>
            {
                executed     = true;
                execQuantity = a.Quantity;
            };
            marketGateway.Send(order);

            Check.That(execQuantity).IsEqualTo(50);
            Check.That(executed).IsTrue();
            Check.That(marketGateway.SellQuantity).IsEqualTo(0);
        }
        public void Should_not_execute_LimitOrder_when_price_is_too_high()
        {
            var marketGateway = new ApiMarketGateway(marketName: "euronext", sellQuantity: 50, sellPrice: 100M);

            var    executed      = false;
            bool   failed        = false;
            string failureReason = null;
            var    order         = marketGateway.CreateLimitOrder(ApiMarketWay.Buy, price: 101M, quantity: 10, allowPartial: false);

            marketGateway.OrderExecuted += (s, a) => executed = true;
            marketGateway.OrderFailed   += (s, failedEventArgs) =>
            {
                failed        = true;
                failureReason = failedEventArgs.FailureCause;
            };
            marketGateway.Send(order);

            Check.That(executed).IsFalse();
            Check.That(failed).IsTrue();
            Check.That(failureReason).IsEqualTo("Invalid price");
            Check.That(marketGateway.SellQuantity).IsEqualTo(50);
        }