Пример #1
0
        public void Serialize_Doesnotthrowexception_Max()
        {
            Span <byte> bytes = stackalloc byte[BookRequestSerializer.MessageSize];

            BookRequestSerializer.Serialize(new BookRequest {
                LevelCount = Int32.MaxValue
            }, bytes);
        }
        public void Deserialize_Doesnotthrowexception_Max()
        {
            var bytes = BookRequestSerializer.Serialize(new BookRequest {
                LevelCount = int.MaxValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(11, messageLength);
            var cancelRequest = BookRequestSerializer.Deserialize(bytes);

            Assert.Equal(int.MaxValue, cancelRequest.LevelCount);
        }
Пример #3
0
        public void Deserialize_Doesnotthrowexception()
        {
            Span <byte> bytes = stackalloc byte[BookRequestSerializer.MessageSize];

            BookRequestSerializer.Serialize(new BookRequest {
                LevelCount = 12345678
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(11, messageLength);
            var cancelRequest = BookRequestSerializer.Deserialize(bytes);

            Assert.Equal(12345678, cancelRequest.LevelCount);
        }
 public void bookRequestBinarySerialize()
 {
     var msg = BookRequestSerializer.Serialize(new BookRequest {
     });
 }
        public SerializeBenchmark()
        {
            book = new Book();
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, IsTip = false, OpenQuantity = 1000, OrderId = 3434, Price = 234
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, IsTip = false, OpenQuantity = 1000, OrderId = 3434, Price = 235
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, IsTip = false, OpenQuantity = 1000, OrderId = 3435, Price = 236
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, IsTip = false, OpenQuantity = 1000, OrderId = 3436, Price = 237
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, IsTip = false, OpenQuantity = 1000, OrderId = 3437, Price = 238
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, IsTip = false, OpenQuantity = 1000, OrderId = 3438, Price = 239
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, IsTip = false, OpenQuantity = 1000, OrderId = 3439, Price = 240
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, IsTip = false, OpenQuantity = 1000, OrderId = 3440, Price = 241
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, IsTip = false, OpenQuantity = 1000, OrderId = 3441, Price = 242
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, IsTip = false, OpenQuantity = 1000, OrderId = 3442, Price = 243
            });
            bid = book.BidSide.Select(x => new KeyValuePair <Price, Quantity>(x.Key, x.Value.Quantity)).ToList();
            ask = book.AskSide.Select(x => new KeyValuePair <Price, Quantity>(x.Key, x.Value.Quantity)).ToList();

            var order = new Order {
                CancelOn = 12345678, IsBuy = true, OrderId = 56789, Price = 404, OpenQuantity = 1000
            };
            var orderWrapper = new OrderWrapper()
            {
                Order = order, OrderCondition = OrderCondition.ImmediateOrCancel, StopPrice = 9534, TotalQuantity = 7878234
            };

            orderJsonString       = JsonConvert.SerializeObject(orderWrapper);
            orderBinarySerialized = OrderSerializer.Serialize(orderWrapper);
            orderMsgPck           = MessagePackSerializer.Serialize(new Order2 {
                IsBuy = true, IsTip = false, OpenQuantity = 100, OrderId = 1001, Price = 400, Quantity = 100, Sequnce = 0, StopPrice = 0
            });

            fillJsonString = JsonConvert.SerializeObject(new Fill {
                MakerOrderId = 10001, MatchQuantity = 2000, MatchRate = 2400, TakerOrderId = 9999, Timestamp = 10303
            });
            fillBinary = FillSerializer.Serialize(new Fill {
                MakerOrderId = 10001, MatchQuantity = 2000, MatchRate = 2400, TakerOrderId = 9999, Timestamp = 10303
            });

            cancelJsonString = JsonConvert.SerializeObject(new CancelledOrder {
                OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
            });
            cancelBinary = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
            });

            cancelRequestJsonString = JsonConvert.SerializeObject(new CancelRequest {
                OrderId = 1023
            });
            cancelRequestBinary = CancelRequestSerializer.Serialize(new CancelRequest {
                OrderId = 1023
            });

            orderTriggerBinary = OrderTriggerSerializer.Serialize(new OrderTrigger {
                OrderId = 3453, Timestamp = 35345
            });
            orderTriggerJsonString = JsonConvert.SerializeObject(new OrderTrigger {
                OrderId = 3453, Timestamp = 35345
            });

            bookRequestBinary     = BookRequestSerializer.Serialize(new BookRequest {
            });
            bookRequestJsonString = JsonConvert.SerializeObject(new BookRequest {
            });
            bookRequest2          = MessagePackSerializer.Serialize(new BookRequest2 {
            });

            bookJsonString = JsonConvert.SerializeObject(new BookDepth {
                Bid = bid, Ask = ask, LTP = 100, TimeStamp = 1234
            });
            bookBinary = BookSerializer.Serialize(book, 5, 100, 1234);
        }
Пример #6
0
        public void Serialize_ThrowsExecption_IfNullPassed()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => BookRequestSerializer.Serialize(null, null));

            Assert.Equal("bookRequest", ex.ParamName);
        }
 public void Serialize_Doesnotthrowexception_Min()
 {
     var bytes = BookRequestSerializer.Serialize(new BookRequest {
         LevelCount = Int32.MinValue
     });
 }
Пример #8
0
        public SerializeBenchmark()
        {
            book = new Book();
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, OpenQuantity = 1000, OrderId = 3434, Price = 234
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, OpenQuantity = 1000, OrderId = 3434, Price = 235
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, OpenQuantity = 1000, OrderId = 3435, Price = 236
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, OpenQuantity = 1000, OrderId = 3436, Price = 237
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = true, OpenQuantity = 1000, OrderId = 3437, Price = 238
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, OpenQuantity = 1000, OrderId = 3438, Price = 239
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, OpenQuantity = 1000, OrderId = 3439, Price = 240
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, OpenQuantity = 1000, OrderId = 3440, Price = 241
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, OpenQuantity = 1000, OrderId = 3441, Price = 242
            });
            book.AddOrderOpenBook(new Order {
                CancelOn = 1000, IsBuy = false, OpenQuantity = 1000, OrderId = 3442, Price = 243
            });
            bid = book.BidSide.Select(x => new KeyValuePair <Price, Quantity>(x.Key, x.Value.Quantity)).ToList();
            ask = book.AskSide.Select(x => new KeyValuePair <Price, Quantity>(x.Key, x.Value.Quantity)).ToList();

            var order = new Order()
            {
                CancelOn = 12345678, IsBuy = true, OrderId = 56789, Price = 404, OpenQuantity = 1000, OrderCondition = OrderCondition.ImmediateOrCancel, StopPrice = 9534, TotalQuantity = 7878234
            };

            orderJsonString = JsonConvert.SerializeObject(order);

            orderBinarySerialized = new byte[OrderSerializer.MessageSize];
            OrderSerializer.Serialize(order, orderBinarySerialized);

            orderMsgPck = MessagePackSerializer.Serialize(new Order2 {
                IsBuy = true, IsTip = false, OpenQuantity = 100, OrderId = 1001, Price = 400, Quantity = 100, Sequnce = 0, StopPrice = 0
            });

            fillJsonString = JsonConvert.SerializeObject(new Fill {
                MakerOrderId = 10001, MatchQuantity = 2000, MatchRate = 2400, TakerOrderId = 9999, Timestamp = 10303
            });
            fillBinary = new byte[FillSerializer.MessageSize];
            FillSerializer.Serialize(new Fill {
                MakerOrderId = 10001, MatchQuantity = 2000, MatchRate = 2400, TakerOrderId = 9999, Timestamp = 10303
            }, fillBinary);

            cancelJsonString = JsonConvert.SerializeObject(new CancelledOrder {
                OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
            });
            cancelBinary = new byte[CancelledOrderSerializer.MessageSize];
            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
            }, cancelBinary);

            cancelRequestJsonString = JsonConvert.SerializeObject(new CancelRequest {
                OrderId = 1023
            });
            cancelRequestBinary = new byte[CancelRequestSerializer.MessageSize];
            CancelRequestSerializer.Serialize(new CancelRequest {
                OrderId = 1023
            }, cancelRequestBinary);

            orderTriggerBinary = new byte[OrderTriggerSerializer.MessageSize];
            OrderTriggerSerializer.Serialize(new OrderTrigger {
                OrderId = 3453, Timestamp = 35345
            }, orderTriggerBinary);
            orderTriggerJsonString = JsonConvert.SerializeObject(new OrderTrigger {
                OrderId = 3453, Timestamp = 35345
            });

            bookRequestBinary = new byte[BookRequestSerializer.MessageSize];
            BookRequestSerializer.Serialize(new BookRequest {
            }, bookRequestBinary);
            bookRequestJsonString = JsonConvert.SerializeObject(new BookRequest {
            });
            bookRequest2Bytes     = MessagePackSerializer.Serialize(new BookRequest2 {
            });

            bookDepth      = new BookDepth(1234, 100, bid, ask);
            bookJsonString = JsonConvert.SerializeObject(bookDepth);
            bookBinary     = new byte[OrderSerializer.MessageSize];
            BookSerializer.Serialize(bookDepth, bookBinary);

            fill = new Fill {
                MakerOrderId = 10001, MatchQuantity = 2000, MatchRate = 2400, TakerOrderId = 9999, Timestamp = 10303
            };
            order2 = new Order2 {
                IsBuy = true, IsTip = false, OpenQuantity = 100, OrderId = 1001, Price = 400, Quantity = 100, Sequnce = 0, StopPrice = 0
            };
            this.order = new Order {
                IsBuy = true, OpenQuantity = 100, OrderId = 1001, Price = 400, Sequnce = 0, TotalQuantity = 100, OrderCondition = OrderCondition.None, StopPrice = 0
            };
            cancelledOrder = new CancelledOrder {
                OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
            };
            cancelRequest = new CancelRequest {
                OrderId = 1023
            };
            orderTrigger = new OrderTrigger {
                OrderId = 3453, Timestamp = 35345
            };
            bookRequest = new BookRequest {
                LevelCount = 50
            };
            bookRequest2 = new BookRequest2 {
                LevelCount = 50
            };
        }
Пример #9
0
        public void BookRequestBinarySerialize()
        {
            Span <byte> bytes = stackalloc byte[BookRequestSerializer.MessageSize];

            BookRequestSerializer.Serialize(bookRequest, bytes);
        }