コード例 #1
0
ファイル: Utils.cs プロジェクト: stone89son/liquibook.NET
        internal static bool AddAndVerify(OrderBook orderBook, IOrder order, bool matchExpected, bool completeExpected = false,
                                          OrderConditions conditions = 0)
        {
            var matched = orderBook.Add(order, conditions);

            if (matched == matchExpected)
            {
                if (completeExpected)
                {
                    return(OrderState.Complete == (order as SimpleOrder)?.State);
                }
                else if ((conditions & OrderConditions.ImmediateOrCancel) != 0)
                {
                    return(OrderState.Cancelled == (order as SimpleOrder)?.State);
                }
                else
                {
                    return(OrderState.Accepted == (order as SimpleOrder)?.State);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        public OrderTracker(Order order, OrderConditions conditions)
        {
            Order      = order;
            Conditions = conditions;

            Open = order.Quantity;
        }
コード例 #3
0
 public FillChecker(IOrder order, Quantity filledQuantity, int filledCost, OrderConditions conditions = 0)
 {
     Order = order;
     ExpectedFilledQuantity = (order as SimpleOrder).FilledQuantity + filledQuantity;
     ExpectedOpenQuantity   = (order as SimpleOrder).OrderQty - ExpectedFilledQuantity;
     ExpectedFilledCost     = (order as SimpleOrder).FilledCost + filledCost;
     Conditions             = conditions;
 }
コード例 #4
0
 protected virtual bool ValidateOrder(Order order, OrderConditions conditions)
 {
     if (order.Quantity == 0)
     {
         OnRejected(order, "Quantity must be positive", Transaction);
         return(false);
     }
     return(true);
 }
コード例 #5
0
 public SimpleOrder(bool isBuy, Price price, Quantity quantity, Price stopPrice, OrderConditions conditions = 0)
 {
     IsBuy      = isBuy;
     Price      = price;
     OrderQty   = quantity;
     StopPrice  = stopPrice;
     Conditions = conditions;
     OrderId    = ++LastOrderId;
     State      = OrderState.New;
 }
コード例 #6
0
 public SimpleOrder(bool isBuy, Price price, Quantity quantity, Price stopPrice, OrderConditions conditions = 0, string orderIdExt = null, string orderDomain = null)
 {
     IsBuy       = isBuy;
     Price       = price;
     OrderQty    = quantity;
     StopPrice   = stopPrice;
     Conditions  = conditions;
     OrderId     = ++LastOrderId;
     State       = OrderState.New;
     OrderIdExt  = string.IsNullOrEmpty(orderIdExt) ? string.Empty : orderIdExt;
     OrderDomain = string.IsNullOrEmpty(orderDomain) ? string.Empty : orderDomain;
 }
コード例 #7
0
        public OrderTracker(IOrder order, OrderConditions condition, bool liquibookOrderKnowsConditions = false)
        {
            Order         = order;
            _openQuantity = order.OrderQty;
            Reserved      = 0;
            Conditions    = condition;

            if (liquibookOrderKnowsConditions)
            {
                if (order.AllOrNone)
                {
                    Conditions = condition | OrderConditions.AllOrNone;
                }

                if (order.ImmediateOrCancel)
                {
                    Conditions = condition | OrderConditions.ImmediateOrCancel;
                }
            }
        }
コード例 #8
0
        public virtual bool Add(Order order, OrderConditions conditions = OrderConditions.None)
        {
            ++Transaction;

            bool matched = false;

            if (!ValidateOrder(order, conditions))
            {
                // rejected
            }
            else
            {
                double       price   = SortPrice(order);
                OrderTracker tracker = new OrderTracker(order, conditions);

                matched = AddOrder(tracker, price);
                if (matched)
                {
                    // add tracker.Filled to OnAccepted
                    OnAccepted(order, Transaction, tracker.Filled);
                }
                else
                {
                    OnAccepted(order, Transaction, 0);
                }

                if (tracker.IsImmediate && !tracker.IsFilled)
                {
                    // cancel order, transaction
                    OnCanceled(order, 0, Transaction);
                }

                // update this, transaction
                OnBookUpdated(Transaction);
            }

            return(matched);
        }