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

            int    id       = nextOrderId++;
            string globexId = id.ToString();

            ordersToClients[id] = (FixTcpClient)sender;
            orderInfos[id]      = new OrderInfo(globexId, request.ClientOrderId,
                                                request.CorrelationClientOrderId, request.Account,
                                                request.IsManualOrder, request.PreTradeAnonymity);
            orderIds[globexId] = id;

            var book = books[request.Contract];

            int minQty        = request.MinQuantity ?? 0;
            int maxVisibleQty = request.MaxVisibleQuantity ?? int.MaxValue;
            SelfMatchPreventionInstruction smpMode = request.SelfMatchPreventionInstruction ?? SelfMatchPreventionInstruction.CancelResting;

            switch (request.OrderType)
            {
            case OrderType.Limit:
                book.CreateLimitOrder(id, request.TimeInForce, request.ExpireDate,
                                      request.Side, request.Price, request.Quantity,
                                      minQty, maxVisibleQty,
                                      request.SelfMatchPreventionId, smpMode);
                break;

            case OrderType.Market:
                book.CreateMarketOrder(id, request.TimeInForce, request.ExpireDate,
                                       request.Side, request.Quantity,
                                       minQty, maxVisibleQty,
                                       request.SelfMatchPreventionId, smpMode);
                break;

            case OrderType.MarketLimit:
                book.CreateMarketLimitOrder(id, request.TimeInForce, request.ExpireDate,
                                            request.Side, request.Quantity,
                                            minQty, maxVisibleQty,
                                            request.SelfMatchPreventionId, smpMode);
                break;

            case OrderType.Stop:
                book.CreateStopOrder(id, request.TimeInForce, request.ExpireDate,
                                     request.Side, request.StopPrice, request.Quantity,
                                     minQty, maxVisibleQty,
                                     request.SelfMatchPreventionId, smpMode);
                break;

            case OrderType.StopLimit:
                book.CreateStopLimitOrder(id, request.TimeInForce, request.ExpireDate,
                                          request.Side, request.Price, request.StopPrice, request.Quantity,
                                          minQty, maxVisibleQty,
                                          request.SelfMatchPreventionId, smpMode);
                break;
            }
        }