internal static OrderHitStatus HitAutoClosePrice(Order order, Quotation newQuotation, DateTime baseTime) { if (order.AutoLimitPrice != null || order.AutoStopPrice != null) { bool isBuyForClose = !order.IsBuy; Price marketPrice = HitCommon.CalculateMarketPrice(isBuyForClose, newQuotation); if (order.AutoLimitPrice != null) { int result = Price.Compare(marketPrice, order.AutoLimitPrice, !newQuotation.IsNormal); if ((!isBuyForClose && result >= 0) || (isBuyForClose && result <= 0)) //Sell High Buy Low { return(OrderHitStatus.ToAutoLimitClose); } } if (order.AutoStopPrice != null) { int result = Price.Compare(marketPrice, order.AutoStopPrice, !newQuotation.IsNormal); if ((!isBuyForClose && result <= 0) || (isBuyForClose && result >= 0)) //Sell Low Buy High { return(OrderHitStatus.ToAutoStopClose); } } } return(OrderHitStatus.None); }
internal static OrderHitStatus HitSpotOrder(Order order, HitOrderSettings hitOrderSettings, Quotation quotation, DateTime baseTime) { if (!order.ShouldSportOrderDelayFill && order.HitStatus.IsFinal()) { return(OrderHitStatus.None); } Price marketPrice = HitCommon.CalculateMarketPrice(order.IsBuy, quotation); if (ShouldCancelSpotOrder(order, marketPrice, quotation.IsNormal)) { return(OrderHitStatus.ToCancel); } if (order.DQMaxMove <= 0) { return(OrderHitStatus.None); } if (!hitOrderSettings.IncreaseHitCount()) { return(OrderHitStatus.None); } Price bestPrice = CalculateBestPriceForSportOrder(order, marketPrice); if (bestPrice != null) { order.BestPrice = bestPrice; order.BestTime = baseTime; } if (order.ShouldAutoFill && !order.ShouldSportOrderDelayFill && Math.Abs(order.HitCount) >= order.Instrument().HitTimes) { return(OrderHitStatus.ToAutoFill); } return(OrderHitStatus.Hit); }
internal static OrderHitStatus HitMarketAndLimitOrder(Order order, HitOrderSettings hitOrderSettings, Quotation newQuotation, DateTime baseTime, bool ignoreHitTimes) { Price marketPrice = HitCommon.CalculateMarketPrice(order.IsBuy, newQuotation); if (!IsHitPrice(order, newQuotation, marketPrice)) { return(OrderHitStatus.None); } if (!hitOrderSettings.IncreaseHitCount()) { return(OrderHitStatus.None); } if (ShouldUseNewHitPrice(order, newQuotation)) { order.BestPrice = marketPrice; order.BestTime = baseTime; } else { return(OrderHitStatus.None); } return(order.CalculateLimitMarketHitStatus(ignoreHitTimes)); }