Exemplo n.º 1
0
        public void ToInstructionReturnCorrectJsonString(long selectionId, Side side, double size, double price)
        {
            var order    = new LimitOrderBuilder(selectionId, side, price, size);
            var expected = order.ExpectedInstructionJson();

            Assert.Equal(expected, order.Object.ToInstruction());
        }
Exemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
0
        public async Task AddReportShouldHandleNullReport()
        {
            var limitOrder  = new LimitOrderBuilder(123, Side.Lay, 2.5, 9.99);
            var instruction = new LimitOrderBuilder(987, Side.Back, 5.5, 11.99).PlaceInstructionReportJson("1", "SUCCESS", "SUCCESS");

            SetPlaceReturnContent(instruction);
            await _orderService.Place("MarketId", new List <LimitOrder> {
                limitOrder.Object
            });
        }
Exemplo n.º 7
0
        public async Task BetIdIsUpdatedWhenOrderIsReplaced()
        {
            var order = new LimitOrderBuilder(12345, Side.Lay, 2, 0.5);

            await SetResults(new List <LimitOrderBuilder> {
                order
            }, "SUCCESS");

            Assert.Equal("2", order.Object.BetId);
        }
Exemplo n.º 8
0
        public async Task ToCancelInstructionShouldReturnNullIfOrderIsComplete(long selectionId, Side side, double size, double price)
        {
            var order = new LimitOrderBuilder(selectionId, side, price, size);

            await SetResults(new List <LimitOrderBuilder> {
                order
            }, "SUCCESS");

            Assert.Null(order.Object.ToCancelInstruction());
        }
Exemplo n.º 9
0
        public async Task ErrorCodeShouldBeRecordedIfOrderFails()
        {
            var order       = new LimitOrderBuilder(12345, Side.Back, 2, 9.99);
            var limitOrders = new List <LimitOrderBuilder> {
                order
            };

            await SetResults(limitOrders, "FAILURE");

            Assert.Equal("TEST_ERROR", order.Object.ErrorCode);
        }
Exemplo n.º 10
0
        public async Task ToCancelInstructionReturnCorrectJsonString(long selectionId, Side side, double size, double price)
        {
            var order = new LimitOrderBuilder(selectionId, side, price, size);

            await SetResults(new List <LimitOrderBuilder> {
                order
            }, "SUCCESS", "EXECUTABLE");

            var expected = $"{{\"betId\":\"{order.Object.BetId}\"}}";

            Assert.Equal(expected, order.Object.ToCancelInstruction());
        }
Exemplo n.º 11
0
        public async Task SetResultsShouldUseCorrectResult(double size)
        {
            var order       = new LimitOrderBuilder(12345, Side.Back, 1.01, size);
            var limitOrders = new List <LimitOrderBuilder>
            {
                new LimitOrderBuilder(98765, Side.Lay, -1, -1),
                new LimitOrderBuilder(12345, Side.Lay, -1, -1),
                order,
            };

            await SetResults(limitOrders, "SUCCESS");

            Assert.Equal(size, order.Object.SizeMatched);
        }
Exemplo n.º 12
0
        public async Task CancelSendsCancelInstruction(long selectionId, Side side, double size, double price)
        {
            var limitOrder  = new LimitOrderBuilder(selectionId, side, price, size);
            var limitOrder2 = new LimitOrderBuilder(1, Side.Back, 2, 10);
            var limitOrders = new List <LimitOrderBuilder> {
                limitOrder, limitOrder2
            };

            await SetResults(limitOrders, "SUCCESS", "EXECUTABLE");

            var cancelInstruction = $"{{\"marketId\":\"MarketId\",\"instructions\":[{limitOrder.Object.ToCancelInstruction()},{limitOrder2.Object.ToCancelInstruction()}]}}";
            await _orderService.Cancel("MarketId", limitOrders.Select(o => o.Object.BetId).ToList());

            Assert.Equal(cancelInstruction, _service.SentParameters["cancelOrders"]);
        }
Exemplo n.º 13
0
 public PlaceInstructionReportStub(
     LimitOrderBuilder instruction,
     string betId,
     string status,
     string orderStatus)
 {
     Instruction         = instruction;
     BetId               = betId;
     Status              = status;
     OrderStatus         = orderStatus;
     PlacedDate          = DateTime.Parse("2013-10-30T14:22:47.000Z", new CultureInfo(1));
     AveragePriceMatched = instruction?.LimitOrder.Price;
     SizeMatched         = instruction?.LimitOrder.Size;
     ErrorCode           = "TEST_ERROR";
 }
Exemplo n.º 14
0
        public async Task SetResultsShouldHandleMissingReport()
        {
            var orders = new PlaceExecutionReportStub("MarketId", "SUCCESS");

            orders.AddReport(new LimitOrderBuilder(98765, Side.Lay, 1.01, 2.00), "1", "SUCCESS", "EXECUTION_COMPLETE");

            var order = new LimitOrderBuilder(12345, Side.Back, 1.01, 2.00);

            orders.AddNullReport(order);

            orders.SetReturnContent(_service);

            await _orderService.Place("MarketId", orders.LimitOrders);

            Assert.Equal(0, order.Object.SizeMatched);
        }
Exemplo n.º 15
0
        public async Task SetResultsShouldUpdateCorrectBetId()
        {
            var order1      = new LimitOrderBuilder(12345, Side.Back, 1.01, 0.8); // betId = 1, newId = 4
            var order2      = new LimitOrderBuilder(98765, Side.Lay, 2, 0.5);     // betId = 2, newId = 5
            var order3      = new LimitOrderBuilder(12345, Side.Lay, 3, 0.5);     // betId = 3, newId = 6
            var limitOrders = new List <LimitOrderBuilder>
            {
                order1,
                order2,
                order3,
            };

            await SetResults(limitOrders, "SUCCESS");

            Assert.Equal("4", order1.Object.BetId);
            Assert.Equal("5", order2.Object.BetId);
            Assert.Equal("6", order3.Object.BetId);
        }
Exemplo n.º 16
0
        public async Task ResultsAreSet(double size, double price, string status)
        {
            var orders = new PlaceExecutionReportStub("MarketId", "SUCCESS");

            orders.AddReport(new LimitOrderBuilder(98765, Side.Lay, -1, -1), "1", "SUCCESS", "EXECUTION_COMPLETE");

            var order = new LimitOrderBuilder(12345, Side.Back, price, size);

            orders.AddReport(order, "2", status, "EXECUTION_COMPLETE");

            orders.SetReturnContent(_service);

            await _orderService.Place("MarketId", orders.LimitOrders);

            Assert.NotEqual("1", order.Object.BetId);
            Assert.Equal("2", order.Object.BetId);
            Assert.Equal(size, order.Object.SizeMatched);
            Assert.Equal(price, order.Object.AveragePriceMatched);
            Assert.Equal(status, order.Object.Status);
            Assert.Equal("EXECUTION_COMPLETE", order.Object.OrderStatus);
            Assert.Equal(DateTime.Parse("2013-10-30T14:22:47.000Z", new DateTimeFormatInfo()), order.Object.PlacedDate);
        }
Exemplo n.º 17
0
 internal void AddNullReport(LimitOrderBuilder order)
 {
     LimitOrders.Add(order.Object);
 }
Exemplo n.º 18
0
 internal void AddReport(LimitOrderBuilder order, string betId, string status, string orderStatus)
 {
     InstructionReports ??= new List <PlaceInstructionReportStub>();
     InstructionReports.Add(order.PlaceInstructionReportObject(betId, status, orderStatus));
     LimitOrders.Add(order.Object);
 }