示例#1
0
        public void Serialize_Doesnotthrowexception_Max()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MaxValue, Timestamp = int.MaxValue, RemainingQuantity = int.MaxValue, CancelReason = CancelReason.ValidityExpired, Cost = Quantity.MaxValue, Fee = Quantity.MaxValue
            }, bytes);
        }
        public void Serialize_Doesnotthrowexception_Min()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue, Fee = Quantity.MinValue, MessageSequence = long.MinValue
            }, bytes);
        }
        public void Deserialize_Doesnotthrowexception_Min()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MinValue, cancelledOrder.OrderId);
            Assert.Equal(int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Cost);
        }
        public void Deserialize_Doesnotthrowexception()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 12345678, RemainingQuantity = 56789, Timestamp = 404, CancelReason = CancelReason.ValidityExpired, Cost = 12.13m
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal((OrderId)12345678, cancelledOrder.OrderId);
            Assert.Equal(56789, cancelledOrder.RemainingQuantity);
            Assert.Equal(404, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)12.13m, cancelledOrder.Cost);
        }
示例#5
0
        public void Deserialize_Doesnotthrowexception_Min()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = ulong.MinValue, Timestamp = long.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, RemainingOrderAmount = decimal.MinValue
            });
            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(56, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(ulong.MinValue, cancelledOrder.OrderId);
            Assert.Equal((Quantity)int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(long.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)decimal.MinValue, cancelledOrder.RemainingOrderAmount);
        }
示例#6
0
        public void Deserialize_Doesnotthrowexception_Max()
        {
            var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MaxValue, Timestamp = int.MaxValue, RemainingQuantity = int.MaxValue, CancelReason = CancelReason.ValidityExpired, RemainingOrderAmount = decimal.MaxValue
            });

            var messageLength = BitConverter.ToInt32(bytes, 0);

            Assert.Equal(52, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MaxValue, cancelledOrder.OrderId);
            Assert.Equal((Quantity)int.MaxValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MaxValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)decimal.MaxValue, cancelledOrder.RemainingOrderAmount);
        }
示例#7
0
        public void Deserialize_Doesnotthrowexception_Min()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue, Fee = Quantity.MinValue
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(68, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal(OrderId.MinValue, cancelledOrder.OrderId);
            Assert.Equal(int.MinValue, cancelledOrder.RemainingQuantity);
            Assert.Equal(int.MinValue, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.UserRequested, cancelledOrder.CancelReason);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Cost);
            Assert.Equal(Quantity.MinValue, cancelledOrder.Fee);
        }
示例#8
0
        public void Deserialize_Doesnotthrowexception()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(new CancelledOrder {
                OrderId = 12345678, RemainingQuantity = 56789, Timestamp = 404, CancelReason = CancelReason.ValidityExpired, Cost = 12.13m, Fee = 92.005m
            }, bytes);
            var messageLength = BitConverter.ToInt32(bytes.Slice(0));

            Assert.Equal(68, messageLength);
            var cancelledOrder = CancelledOrderSerializer.Deserialize(bytes);

            Assert.Equal((OrderId)12345678, cancelledOrder.OrderId);
            Assert.Equal(56789, cancelledOrder.RemainingQuantity);
            Assert.Equal(404, cancelledOrder.Timestamp);
            Assert.Equal(CancelReason.ValidityExpired, cancelledOrder.CancelReason);
            Assert.Equal((Quantity)12.13m, cancelledOrder.Cost);
            Assert.Equal((Quantity)92.005m, cancelledOrder.Fee);
        }
 public void Serialize_Doesnotthrowexception_Min()
 {
     var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
         OrderId = OrderId.MinValue, Timestamp = int.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, Cost = Quantity.MinValue
     });
 }
        public void Serialize_ThrowsExecption_IfNullPassed()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => CancelledOrderSerializer.Serialize(null));

            Assert.Equal("cancelledOrder", ex.ParamName);
        }
 public void Serialize_Doesnotthrowexception_Max()
 {
     var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
         OrderId = OrderId.MaxValue, Timestamp = int.MaxValue, RemainingQuantity = int.MaxValue, CancelReason = CancelReason.ValidityExpired, Cost = Quantity.MaxValue
     });
 }
示例#12
0
 public void Serialize_Doesnotthrowexception_Min()
 {
     var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
         OrderId = ulong.MinValue, Timestamp = long.MinValue, RemainingQuantity = int.MinValue, CancelReason = CancelReason.UserRequested, RemainingOrderAmount = decimal.MinValue
     });
 }
        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);
        }
 public void cancelBinarySerialize()
 {
     var bytes = CancelledOrderSerializer.Serialize(new CancelledOrder {
         OrderId = 1201, CancelReason = CancelReason.UserRequested, RemainingQuantity = 2000, Timestamp = 234
     });
 }
示例#15
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
            };
        }
示例#16
0
        public void CancelBinarySerialize()
        {
            Span <byte> bytes = stackalloc byte[CancelledOrderSerializer.MessageSize];

            CancelledOrderSerializer.Serialize(cancelledOrder, bytes);
        }