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

Đang mở
#10,042 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend, fintech-quant

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
C#
Star
22.4k
Fork
5.4k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
63

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của QuantConnect/Lean

Tất cả issue của QuantConnect/Lean

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.