QuantConnect / QuantConnect/Lean.Brokerages.ByBit

Support orders placed outside of the algorithm (brokerage-side orders)

Open
#45 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
7
Forks
15
Avg merge
3h 8m
Merged PRs (30d)
1

Description

Description

Orders placed outside the algorithm (Bybit web/app, or another system on the same account) are silently dropped. The private WebSocket subscribes to the account-wide order and execution topics (BybitBrokerage.Messaging.cs:586), so their updates do arrive, but both handlers bail out on an unknown brokerage id — HandleOrderExecution at BybitBrokerage.Messaging.cs:119-120 and HandleOrderUpdate at BybitBrokerage.Messaging.cs:207-208 both do if (leanOrder == null) continue;. The algorithm never learns about the order or the position it creates.

Expected behaviour

Follow the pattern already implemented in TradeStation, Alpaca, Interactive Brokers, Binance and ClearStreet, and proposed for Tradier in QuantConnect/Lean.Brokerages.Tradier#53:

  1. When an order update arrives for a brokerage id the IOrderProvider does not know, convert it to a LEAN Order and offer it through OnNewBrokerageOrderNotification(new NewBrokerageOrderNotificationEventArgs(order)).
  2. If the brokerage message handler accepts it (LEAN assigns order.Id != 0), emit Submitted plus any fills the order already had, and keep tracking it through the normal update path from then on.
  3. If it is declined (order.Id == 0), leave the order alone and do not emit further events for it — the algorithm must keep running.
  4. Orders that cannot be represented in LEAN (unsupported order types, multi-leg/combo, missing price fields) should raise a single message rather than terminating the algorithm, and GetOpenOrders should skip them instead of failing the launch.
  5. Offer each unknown order only once, so repeated updates for the same id do not re-notify.

Tests

Unit tests covering the accepted, declined, unconvertible and partial-fill paths, plus a live/paper run with an order placed outside the algorithm.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BybitBrokerage.Messaging.cs at the cited HandleOrderExecution and HandleOrderUpdate locations, then compare the existing TradeStation, Alpaca, Interactive Brokers, Binance and ClearStreet implementations. Trace IOrderProvider and the brokerage message conversion path before adding unit coverage for accepted, declined, unconvertible and partial-fill orders; done means unknown orders are handled once without stopping the algorithm, including in a live or paper run.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, fintech-quant
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.