/// <summary>
        ///     Adds an order for the given contract and market side with the given properties
        /// </summary>
        /// <returns>The added order</returns>
        public IOrder AddOrder(long orderID,
                               Contract contract,
                               OrderType orderType,
                               MarketSide marketSide,
                               decimal price,
                               decimal quantity,
                               string clOrdID,
                               TradingAccount account)
        {
            var order = new Order(orderID,
                                  orderType,
                                  contract,
                                  marketSide,
                                  price,
                                  quantity,
                                  clOrdID,
                                  account);

            var stack = _market.GetOrCreate(
                contract,
                () =>
                    {
                        var os = OrderStackFactory.CreateStandardSortedStack(_orderMatcher);
                        os.OrdersMatched += OnOrdersMatched;
                        return os;
                    });
            stack.AddOrder(order);
            return order;
        }
示例#2
0
        public Message CreateNewOrderSingleMessage(string symbol,
                                                   MarketSide marketSide,
                                                   string clOrdID,
                                                   TradingAccount account,
                                                   decimal price,
                                                   decimal quantity,
                                                   OrderType orderType,
                                                   string execID)
        {
            var fOrdType = TranslateFixFields.Translate(orderType);
            var fSide = TranslateFixFields.Translate(marketSide);
            var fSymbol = new Symbol(symbol);
            var fTransactTime = new TransactTime(DateTime.Now);
            var fClOrdID = new ClOrdID(clOrdID);

            var nos = new NewOrderSingle(fClOrdID,
                                         fSymbol,
                                         fSide,
                                         fTransactTime,
                                         fOrdType)
            {
                OrderQty = new OrderQty(quantity),
                TimeInForce = new TimeInForce(TimeInForce.GOOD_TILL_CANCEL)
            };

            if (orderType == OrderType.Limit)
                nos.Price = new Price(price);

            return nos;
        }
示例#3
0
        /// <summary>
        /// Adds an order to the system with the given properties
        /// </summary>
        /// <param name="sessionID">The FIX Session ID</param>
        /// <param name="orderType">
        /// The type of order, currently only Limit orders are supported
        /// </param>
        /// <param name="symbol">The symbol for the order</param>
        /// <param name="marketSide">The side of the market for the order</param>
        /// <param name="clOrdID">The FIX ClOrdID for the order, set by the client</param>
        /// <param name="account">The trading account associated with the order</param>
        /// <param name="quantity">The quantity of the order</param>
        /// <param name="price">The price of the order, may be null for market orders</param>
        /// <returns>The new order after it has been added</returns>
        /// <exception cref="FixATServerException">If the order is rejected</exception>
        public IOrder AddOrder(FixSessionID sessionID,
                               OrderType orderType,
                               string symbol,
                               MarketSide marketSide,
                               string clOrdID,
                               TradingAccount account,
                               decimal quantity,
                               decimal? price = null)
        {
            // A more complete system would look the contract up in a contract store
            var contract = new Contract(symbol);

            // TODO Replace this with a better mechanism (esp if more order types are supported)
            decimal orderPrice;
            switch (orderType)
            {
                case OrderType.Limit:
                    {
                        if (!price.HasValue)
                            throw new FixATServerException("Limit order must specify a price");
                        orderPrice = price.Value;
                        break;
                    }

                    // Uncomment this if and when market orders are supported
                    //case OrderType.Market:
                    //    {
                    //        if (price.HasValue)
                    //            throw new FixATServerException(
                    //                "Market order should not have a specified price");

                    //        orderPrice = GetMarketPrice(contract, marketSide);
                    //        break;
                    //    }

                default:
                    throw new FixATServerException(
                        string.Format("Order Type {0} not supported", orderType));
            }

            if (OrderWouldLeadToACrossedMarket(marketSide, contract, orderPrice))
                throw new FixATServerException("Order would lead to a crossed market");

            var order = _orderRepository.AddOrder(CreateOrderID(),
                                                  contract,
                                                  orderType,
                                                  marketSide,
                                                  orderPrice,
                                                  quantity,
                                                  clOrdID,
                                                  account);

            _orderOwners[order.ID] = sessionID;

            return order;
        }
示例#4
0
文件: Order.cs 项目: naziway/testtask
 public Order(long id,
              OrderType orderType,
              Contract contract,
              MarketSide marketSide,
              decimal price,
              decimal quantity,
              string clOrdID,
              TradingAccount tradingAccount)
 {
     ID = id;
     OrderType = orderType;
     Contract = contract;
     MarketSide = marketSide;
     Price = price;
     Quantity = quantity;
     LastUpdateTime = DateTime.UtcNow;
     ClOrdID = clOrdID;
     Account = tradingAccount;
     OriginalQuantity = quantity;
 }
示例#5
0
文件: Order.cs 项目: mjheller/wpffix
 public Order(long id,
              OrderType orderType,
              Contract contract,
              MarketSide marketSide,
              decimal price,
              decimal quantity,
              string clOrdID,
              TradingAccount tradingAccount)
 {
     ID               = id;
     OrderType        = orderType;
     Contract         = contract;
     MarketSide       = marketSide;
     Price            = price;
     Quantity         = quantity;
     LastUpdateTime   = DateTime.UtcNow;
     ClOrdID          = clOrdID;
     Account          = tradingAccount;
     OriginalQuantity = quantity;
 }
示例#6
0
        public Message CreateRejectNewOrderExecutionReport(string symbol,
                                                           MarketSide marketSide,
                                                           string clOrdID,
                                                           decimal orderQuantity,
                                                           TradingAccount account,
                                                           string execID,
                                                           string rejectionReason,
                                                           int? rejectionCode = null)
        {
            var exReport = new ExecutionReport(
               new OrderID("unknown orderID"),
               new ExecID(execID),
               new ExecType(ExecType.REJECTED),
               new OrdStatus(OrdStatus.REJECTED),
               new Symbol(symbol),
               TranslateFixFields.Translate(marketSide),
               new LeavesQty(0m),
               new CumQty(0m),
               new AvgPx(0m))
            {
                ClOrdID = new ClOrdID(clOrdID),
                OrderQty = new OrderQty(orderQuantity)
            };

            if (rejectionCode.HasValue)
            {
                exReport.OrdRejReason = new OrdRejReason(rejectionCode.Value);
            }

            if (TradingAccount.IsSet(account))
            {
                exReport.Account = new Account(account.Name);
            }

            return exReport;
        }