예제 #1
0
        private static Order Deviation(Order order,
                                       OrderDeviationMode mode, int threshold,
                                       OrderDeviationMethod method,
                                       OrderPriceAdjustMethod adjustMethod,
                                       byte slippage, byte maxTry)
        {
            var info = GetOrderInfo(order);

            if (mode == OrderDeviationMode.Disabled)
            {
                info.DeviationMode = mode;
            }
            else
            {
                switch (info.DeviationMode)
                {
                case OrderDeviationMode.QuoteAndTrade:
                case OrderDeviationMode.Trade:
                case OrderDeviationMode.Time:
                    info.DeviationMode |= mode;
                    break;

                default:
                    info.DeviationMode = mode;
                    break;
                }
            }
            info.DeviationInfo.Threshold         = threshold;
            info.DeviationInfo.Method            = method;
            info.DeviationInfo.PriceAdjustMethod = adjustMethod;
            info.DeviationInfo.Slippage          = slippage;
            info.DeviationInfo.MaxTry            = maxTry;
            return(order);
        }
예제 #2
0
        public static Order OpenShort(this Strategy strategy, Instrument instrument, double qty,
                                      OrderPriceAdjustMethod method = OrderPriceAdjustMethod.MatchPrice)
        {
            double price = GetOrderPrice(instrument, OrderSide.Sell, method);

            return(OpenShort(strategy, instrument, qty, price));
        }
예제 #3
0
        public static Order Market2Limit(this Order order, OrderPriceAdjustMethod method, byte slippage = 1)
        {
            var info = GetOrderInfo(order);

            info.Market2Limit.PriceAdjustMethod = method;
            info.Market2Limit.Slippage          = slippage;
            return(order);
        }
 public void LoadForm(BinaryReader reader)
 {
     PriceAdjustMethod = (OrderPriceAdjustMethod)reader.ReadByte();
     Method            = (OrderDeviationMethod)reader.ReadByte();
     Slippage          = reader.ReadByte();
     MaxTry            = reader.ReadByte();
     TryCount          = reader.ReadByte();
     Threshold         = reader.ReadInt32();
 }
예제 #5
0
        private static double GetOrderPrice(Instrument instrument, OrderSide side, OrderPriceAdjustMethod method)
        {
            var    rules = instrument.GetTradingRules();
            double price;

            if (rules.HasMarketOrder)
            {
                price = Double.NaN;
            }
            else
            {
                if (side == OrderSide.Buy)
                {
                    price = method == OrderPriceAdjustMethod.MatchPrice ? instrument.Ask.Price : instrument.GetUpperLimitPrice();
                }
                else
                {
                    price = method == OrderPriceAdjustMethod.MatchPrice ? instrument.Bid.Price : instrument.GetLowerLimitPrice();
                }
            }

            return(price);
        }
예제 #6
0
 public static Order TradeDeviation(this Order order, byte priceOffset,
                                    OrderPriceAdjustMethod adjustMethod = OrderPriceAdjustMethod.MatchPrice, byte slippage = 1, byte maxTry = 3)
 {
     return(PriceDeviation(order, priceOffset, OrderDeviationMode.Trade, adjustMethod, slippage, maxTry));
 }
예제 #7
0
 public static Order TimeDeviation(this Order order, int timeout,
                                   OrderPriceAdjustMethod adjustMethod = OrderPriceAdjustMethod.MatchPrice, byte slippage = 1, byte maxTry = 3)
 {
     return(Deviation(order, OrderDeviationMode.Time, timeout, OrderDeviationMethod.PriceAdjust, adjustMethod, slippage, maxTry));
 }
예제 #8
0
 private static Order PriceDeviation(Order order, byte priceOffset, OrderDeviationMode mode,
                                     OrderPriceAdjustMethod adjustMethod = OrderPriceAdjustMethod.MatchPrice, byte slippage = 1, byte maxTry = 3)
 {
     return(Deviation(order, mode, priceOffset, OrderDeviationMethod.PriceAdjust, adjustMethod, slippage, maxTry));
 }
예제 #9
0
 public static OrderList CloseShort(this Strategy strategy, Instrument instrument, double qty,
                                    OrderPriceAdjustMethod method = OrderPriceAdjustMethod.MatchPrice)
 {
     return(CloseShort(strategy, instrument, qty, GetOrderPrice(instrument, OrderSide.Buy, method)));
 }
예제 #10
0
 public static OrderList CloseShort(this InstrumentStrategy strategy, double qty,
                                    OrderPriceAdjustMethod method = OrderPriceAdjustMethod.MatchPrice)
 {
     return(CloseShort(strategy, strategy.Instrument, qty, method));
 }
예제 #11
0
 public static Order OpenLong(this InstrumentStrategy strategy, double qty, OrderPriceAdjustMethod method = OrderPriceAdjustMethod.MatchPrice)
 {
     return(OpenLong(strategy, strategy.Instrument, qty, method));
 }
예제 #12
0
 public OrderAgent DefaultMarket2Limit(OrderPriceAdjustMethod method, byte slippage = 0)
 {
     Info.Market2Limit.PriceAdjustMethod = method;
     Info.Market2Limit.Slippage          = slippage;
     return(this);
 }