public int GetLevelByPrice(double price, SmartQuant.OrderSide Side) { price = Math.Min(price, UpperLimitPrice); price = Math.Max(price, LowerLimitPrice); int index = (int)((Side == SmartQuant.OrderSide.Buy) ? Math.Ceiling(price / TickSize) : Math.Floor(price / TickSize)); return(index); }
public static PositionSide ToPositionSide(this OrderSide side) { switch (side) { case OrderSide.Buy: return(PositionSide.Long); default: return(PositionSide.Short); } }
public double FixPrice(MarketDataRecord record, double price, SmartQuant.OrderSide Side, double tickSize) { double LowerLimitPrice = record.DepthMarket.LowerLimitPrice; double UpperLimitPrice = record.DepthMarket.UpperLimitPrice; //没有设置就直接用 if (tickSize > 0) { decimal remainder = ((decimal)price % (decimal)tickSize); if (remainder != 0) { if (Side == SmartQuant.OrderSide.Buy) { price = Math.Round(Math.Ceiling(price / tickSize) * tickSize, 6); } else { price = Math.Round(Math.Floor(price / tickSize) * tickSize, 6); } } else { //正好能整除,不操作 } } if (0 == UpperLimitPrice && 0 == LowerLimitPrice) { //涨跌停无效 _TdApi.GetLog().Warn("Symbol:{0},Symbol_Dot_Exchange:{1},LowerLimitPrice && UpperLimitPrice 为0,没有进行价格修正", record.Symbol, record.Symbol_Dot_Exchange); } else { //防止价格超过涨跌停 if (price >= UpperLimitPrice) { price = UpperLimitPrice; } else if (price <= LowerLimitPrice) { price = LowerLimitPrice; } } return(price); }
public MonoPositionRecord GetPositionRecord(SmartQuant.OrderSide Side, OpenCloseType OpenClose) { switch (OpenClose) { case OpenCloseType.Open: return(Side == SmartQuant.OrderSide.Buy ? Long : Short); case OpenCloseType.Close: case OpenCloseType.CloseToday: return(Side == SmartQuant.OrderSide.Buy ? Short : Long); default: MessageBox.Show("GetPositionRecord"); break; } return(null); }
// 在对手价上加一定跳数 public double GetMatchPrice(Instrument instrument, SmartQuant.OrderSide side, double jump) { double price = GetMatchPrice(instrument, side); if (side == SmartQuant.OrderSide.Buy) { price += jump * TickSize; } else { price -= jump * TickSize; } // 修正一下价格 price = FixPrice(price, side); return(price); }
public double GetMatchPrice(Instrument instrument, SmartQuant.OrderSide side) { if (side == SmartQuant.OrderSide.Sell) { Bid bid = framework.DataManager.GetBid(instrument); if (bid != null) { return(bid.Price); } } if (side == SmartQuant.OrderSide.Buy) { Ask ask = framework.DataManager.GetAsk(instrument); if (ask != null) { return(ask.Price); } } Trade trade = framework.DataManager.GetTrade(instrument); if (trade != null) { return(trade.Price); } Bar bar = framework.DataManager.GetBar(instrument); if (bar != null) { return(bar.Close); } return(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); }
private static (double close, double closeToday) GetCloseInfo(Strategy strategy, Instrument instrument, OrderSide side, double qty = Double.MaxValue) { var position = strategy.GetPosition(instrument); var rules = instrument.GetTradingRules(); (double closeQty, double closeTodayQty) = GetCloseQty(); double closeToday; double close; if (rules.StrictCloseToday) { closeQty -= closeTodayQty; closeToday = Math.Min(qty, closeTodayQty); qty -= closeToday; if (Math.Abs(qty) < Double.Epsilon) { return(close, closeToday); } } close = Math.Min(qty, closeQty); return(close, closeToday); #region local (double close, double closeToday) GetCloseQty() { (closeToday, close) = side == OrderSide.Buy ? position.Short.GetCanCloseQty() : position.Long.GetCanCloseQty(); if (!rules.DisableCloseToday) { return(close, closeToday); } close -= closeToday; closeToday = 0; return(close, closeToday); } #endregion }
public MonoPositionRecord GetPositionRecord(DualPositionRecord record, SmartQuant.OrderSide Side, OpenCloseType OpenClose) { return(record.GetPositionRecord(Side, OpenClose)); }
public double FixPrice(double price, SmartQuant.OrderSide Side) { return(GetPriceByLevel(GetLevelByPrice(price, Side))); }
public PositionRecord GetPositionRecord(OrderSide side, OrderOffsetFlag offsetFlag) { return(offsetFlag.IsOpen ? side == OrderSide.Buy ? Long : Short : side == OrderSide.Buy ? Short : Long); }