Example #1
0
        private void HandleUpdateRequest(object sender, CancelReplaceRequest request)
        {
            if (!books.ContainsKey(request.Contract))
            {
                ((FixTcpClient)sender).Send(new BusinessLevelReject(request, BusinessLevelRejectReason.UnknownSecurity));
                return;
            }

            var book = books[request.Contract];
            var id   = orderIds[request.OrderId];

            if (!book.Contains(id))
            {
                ((FixTcpClient)sender).Send(new BusinessLevelReject(request, BusinessLevelRejectReason.UnknownId));
                return;
            }

            int maxVisibleQty = request.MaxVisibleQuantity ?? int.MaxValue;

            switch (request.OrderType)
            {
            case OrderType.Limit:
                book.UpdateLimitOrder(id, request.Price, request.Quantity, maxVisibleQty);
                break;

            case OrderType.Market:
                book.UpdateLimitOrder(id, request.Price, request.Quantity, maxVisibleQty);
                break;

            case OrderType.MarketLimit:
                book.UpdateLimitOrder(id, request.Price, request.Quantity, maxVisibleQty);
                break;

            case OrderType.Stop:
                book.UpdateLimitOrder(id, request.Price, request.Quantity, maxVisibleQty);
                break;

            case OrderType.StopLimit:
                book.UpdateLimitOrder(id, request.Price, request.Quantity, maxVisibleQty);
                break;
            }
        }
Example #2
0
        public static Message GetMessage(byte[] data)
        {
            MessageType type = GetType(data);

            Message mes = null;

            if (type == MessageType.Logon)
            {
                mes = new Logon();
            }
            else if (type == MessageType.Heartbeat)
            {
                mes = new Heartbeat();
            }
            else if (type == MessageType.TestRequest)
            {
                mes = new TestRequest();
            }
            else if (type == MessageType.SequenceReset)
            {
                mes = new SequenceReset();
            }
            else if (type == MessageType.ResendRequest)
            {
                mes = new ResendRequest();
            }
            else if (type == MessageType.SessionLevelReject)
            {
                mes = new SessionLevelReject();
            }
            else if (type == MessageType.BusinessLevelReject)
            {
                mes = new BusinessLevelReject();
            }
            else if (type == MessageType.Logout)
            {
                mes = new Logout();
            }
            else if (type == MessageType.OrderSingle)
            {
                mes = new NewOrder();
            }
            else if (type == MessageType.OrderCancelReplaceRequest)
            {
                mes = new CancelReplaceRequest();
            }
            else if (type == MessageType.OrderCancelRequest)
            {
                mes = new CancelRequest();
            }
            else if (type == MessageType.OrderCancelReject)
            {
                mes = new CancelReject();
            }
            else if (type == MessageType.ExecutionReport)
            {
                var os = GetOrderStatus(data);

                if (os == OrderStatus.New)
                {
                    mes = new NewOrderAck();
                }
                else if (os == OrderStatus.Replaced)
                {
                    mes = new CancelReplaceAck();
                }
                else if (os == OrderStatus.Cancelled)
                {
                    mes = new CancelAck();
                }
                else if (os == OrderStatus.Rejected)
                {
                    mes = new Reject();
                }
                else if (os == OrderStatus.PartiallyFilled)
                {
                    mes = new Fill(true);
                }
                else if (os == OrderStatus.Filled)
                {
                    mes = new Fill(false);
                }
                else if (os == OrderStatus.Expired)
                {
                    mes = new Expire();
                }
            }

            mes.Decode(data);

            return(mes);
        }