Beispiel #1
0
        public void Is_RelatedOrder_Validated_Correctly_Against_Base_MarketOrder_On_Create(
            OrderDirectionContract baseDirection, decimal?slPrice, decimal?tpPrice, OrderRejectReason?rejectReason)
        {
            const string instrument = "EURUSD";
            var          quote      = new InstrumentBidAskPair {
                Instrument = instrument, Bid = 1.55M, Ask = 1.57M
            };

            _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(quote));

            var orderRequest = new OrderPlaceRequest
            {
                AccountId     = Accounts[0].Id,
                CorrelationId = Guid.NewGuid().ToString(),
                Direction     = baseDirection,
                InstrumentId  = instrument,
                Type          = OrderTypeContract.Market,
                StopLoss      = slPrice,
                TakeProfit    = tpPrice,
                Volume        = 1
            };

            if (!rejectReason.HasValue)
            {
                Assert.DoesNotThrowAsync(async() =>
                                         await _validateOrderService.ValidateRequestAndCreateOrders(orderRequest));
            }
            else
            {
                var ex1 = Assert.ThrowsAsync <ValidateOrderException>(() =>
                                                                      _validateOrderService.ValidateRequestAndCreateOrders(orderRequest));

                Assert.That(ex1.RejectReason == rejectReason);
            }
        }
Beispiel #2
0
        public void Is_Order_ExpectedOpenPrice_Validated_Correctly(OrderDirectionContract direction, OrderTypeContract orderType,
                                                                   decimal?price, bool isValid)
        {
            const string instrument = "EURUSD";
            var          quote      = new InstrumentBidAskPair {
                Instrument = instrument, Bid = 1.55M, Ask = 1.57M
            };

            _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(quote));

            var request = new OrderPlaceRequest
            {
                AccountId     = Accounts[0].Id,
                CorrelationId = Guid.NewGuid().ToString(),
                Direction     = direction,
                InstrumentId  = instrument,
                Type          = orderType,
                Price         = price,
                Volume        = 1
            };

            if (isValid)
            {
                Assert.DoesNotThrowAsync(async() =>
                                         await _validateOrderService.ValidateRequestAndCreateOrders(request));
            }
            else
            {
                var ex = Assert.ThrowsAsync <ValidateOrderException>(() =>
                                                                     _validateOrderService.ValidateRequestAndCreateOrders(request));

                Assert.That(ex.RejectReason == OrderRejectReason.InvalidExpectedOpenPrice);
                StringAssert.Contains($"{quote.Bid}/{quote.Ask}", ex.Comment);
            }
        }