Exemplo n.º 1
0
        public void ToInstructionRoundsSizeToTwoDecimalsPlaces(double size, double rounded)
        {
            var order    = new LimitOrder(1, Side.Back, 1.01, size);
            var expected = new LimitOrderBuilder(1, Side.Back, 1.01, rounded).ExpectedInstructionJson();

            Assert.Equal(expected, order.ToInstruction());
        }
Exemplo n.º 2
0
        public void HandleBelowMinimumStakeForLayOrders(double size, double price, double expectedSize, double expectedPrice)
        {
            var order    = new LimitOrder(12345, Side.Lay, price, size);
            var expected = new LimitOrderBuilder(12345, Side.Lay, expectedPrice, expectedSize).ExpectedInstructionJson();

            Assert.Equal(expected, order.ToInstruction());
        }
Exemplo n.º 3
0
        public void PriceIsRoundedToNearestValidPrice(double price, double expectedPrice)
        {
            var order    = new LimitOrder(1, Side.Back, price, 2);
            var expected = new LimitOrderBuilder(1, Side.Back, expectedPrice, 2).ExpectedInstructionJson();

            Assert.Equal(expected, order.ToInstruction());
        }
Exemplo n.º 4
0
        public void InitialPriceForSmallOrdersIsValid(double size, double validPrice)
        {
            var order    = new LimitOrder(12345, Side.Lay, validPrice, size);
            var expected = new LimitOrderBuilder(12345, Side.Lay, validPrice, 2)
                           .ExpectedInstructionJson();

            Assert.Equal(expected, order.ToInstruction());
        }
Exemplo n.º 5
0
        public void ToInstructionReturnsNullIfProfitRatioIsInvalid(double price, double size)
        {
            var layOrder = new LimitOrder(12345, Side.Lay, price, size);

            Assert.Null(layOrder.ToInstruction());

            var backOrder = new LimitOrder(12345, Side.Back, price, size);

            Assert.Null(backOrder.ToInstruction());
        }
Exemplo n.º 6
0
        public async Task LimitOrderIsPlaced(string marketId, long selectionId, Side side, double price, double size)
        {
            var limitOrder = new LimitOrder(selectionId, side, price, size);
            await _orderService.Place(marketId, new List <LimitOrder> {
                limitOrder
            });

            var expected = $"{{\"marketId\":\"{marketId}\",\"instructions\":[{limitOrder.ToInstruction()}]}}";

            Assert.Equal(expected, _exchange.SentParameters["placeOrders"]);
        }
Exemplo n.º 7
0
        public async Task MultipleLimitOrdersArePlaced()
        {
            var order1      = new LimitOrder(12345, Side.Back, 1.01, 2.00);
            var order2      = new LimitOrder(98765, Side.Lay, 1000, 9.99);
            var limitOrders = new List <LimitOrder> {
                order1, order2
            };
            await _orderService.Place("MarketId", limitOrders);

            var expected = $"{{\"marketId\":\"MarketId\",\"instructions\":[{order1.ToInstruction()},{order2.ToInstruction()}]}}";

            Assert.Equal(expected, _exchange.SentParameters["placeOrders"]);
        }
Exemplo n.º 8
0
        public async Task DoNotPlaceOrdersOfZeroSize()
        {
            var validOrder = new LimitOrder(1, Side.Lay, 2.5, 9.99);
            var orders     = new List <LimitOrder>
            {
                validOrder,
                new LimitOrder(2, Side.Back, 2.5, 0),
            };

            await _orderService.Place("1.2345", orders);

            var expected = $"{{\"marketId\":\"1.2345\",\"instructions\":[{validOrder.ToInstruction()}]}}";

            Assert.Equal(expected, _exchange.SentParameters["placeOrders"]);
        }
Exemplo n.º 9
0
        public async Task DoNotPlaceOrdersWithAnInvalidProfitRatio()
        {
            var validOrder   = new LimitOrder(1, Side.Lay, 2.5, 9.99);
            var invalidOrder = new LimitOrder(1, Side.Lay, 1.09, 0.08);
            var orders       = new List <LimitOrder>
            {
                validOrder,
                invalidOrder,
            };

            await _orderService.Place("1.2345", orders);

            var expected = $"{{\"marketId\":\"1.2345\",\"instructions\":[{validOrder.ToInstruction()}]}}";

            Assert.Equal(expected, _exchange.SentParameters["placeOrders"]);
        }
Exemplo n.º 10
0
        public async Task BelowMinimumLimitOrdersArePlacedWithReference(string marketId, long selectionId, Side side, double size, double price, string reference)
        {
            var limitOrder = new LimitOrder(selectionId, side, price, size);
            await _orderService.Place(marketId, new List <LimitOrder> {
                limitOrder
            }, reference);

            var placeInstruction   = $"{{\"marketId\":\"{marketId}\",\"customerStrategyRef\":\"{reference}\",\"instructions\":[{limitOrder.ToInstruction()}]}}";
            var cancelInstruction  = $"{{\"marketId\":\"{marketId}\",\"instructions\":[{limitOrder.ToBelowMinimumCancelInstruction()}]}}";
            var replaceInstruction = $"{{\"marketId\":\"{marketId}\",\"customerStrategyRef\":\"{reference}\",\"instructions\":[{limitOrder.ToBelowMinimumReplaceInstruction()}]}}";

            Assert.Equal(placeInstruction, _exchange.SentParameters["placeOrders"]);
            Assert.Equal(cancelInstruction, _exchange.SentParameters["cancelOrders"]);
            Assert.Equal(replaceInstruction, _exchange.SentParameters["replaceOrders"]);
        }