Daily-resolution market orders converted to MarketOnClose are rejected by brokerage models without MarketOnClose

未关闭
#10,042 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
58/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp

调研方向

Start with QCAlgorithm.ConvertMarketOrderIfRequired and the brokerage models' CanSubmitOrder supported order types, especially Tradier, Tastytrade, Public, and Webull. Run the supplied daily-resolution SPY reproduction with Tradier and inspect the order type and status. Done means converted orders are accepted and fill at the close when the original market order is supported.

由索引模型根据 Issue 内容生成。

描述

Expected Behavior

In a backtest, a market order placed during market hours on an equity subscribed only at daily resolution is converted to MarketOnClose (or MarketOnOpen within the MOC buffer) by QCAlgorithm.ConvertMarketOrderIfRequired (#9534). The converted order should be accepted by the brokerage model whenever the original market order would have been, and fill at the close.

Actual Behavior

Brokerage models whose supported order types include Market but not MarketOnClose reject the converted order, so every such market order comes back Invalid:

BrokerageModel declared unable to submit order: [1] Warning - Code: NotSupported - The TradierBrokerageModel does not support MarketOnClose order type. Only supports [Limit,Market,StopMarket,StopLimit]

The user called MarketOrder, which the model supports, and the order never fills. Live trading does not convert, so the same algorithm behaves differently live and in backtest.

Models with the same supported-type pattern (from reading their CanSubmitOrder sets): TradierBrokerageModel (reproduced below), TastytradeBrokerageModel, PublicBrokerageModel, WebullBrokerageModel.

Potential Solution

A suggestion; whoever fixes it picks the approach: let a model accept a MarketOnClose/MarketOnOpen order that Lean created from a market order as a backtest execution proxy, or skip the conversion when the brokerage model doesn't support the target type.

Reproducing the Problem
public class DailyMarketOrderMocRepro : QCAlgorithm
{
    private Symbol _spy;
    public override void Initialize()
    {
        SetStartDate(2013, 10, 7);
        SetEndDate(2013, 10, 11);
        SetCash(100000);
        SetBrokerageModel(BrokerageName.TradierBrokerage);
        _spy = AddEquity("SPY", Resolution.Daily).Symbol;
        Schedule.On(DateRules.EveryDay(_spy), TimeRules.AfterMarketOpen(_spy, 30), () =>
        {
            var ticket = MarketOrder(_spy, 1);
            Log($"{Time} type={ticket.OrderType} status={ticket.Status}");
        });
    }
}

Output on master: every day logs type=MarketOnClose status=Invalid with the message above.

System Information

master (06eb5cb31)

Checklist
  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
主要语言
C#
星标
22.4k
派生
5.4k
平均合并
1 天 17 小时
30 天内合并 PR
63

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

QuantConnect/Lean 的其他 Issue

查看 QuantConnect/Lean 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。