QuantConnect / QuantConnect/Lean.Brokerages.ByBit
Support orders placed outside of the algorithm (brokerage-side orders)
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:
- When an order update arrives for a brokerage id the
IOrderProviderdoes not know, convert it to a LEANOrderand offer it throughOnNewBrokerageOrderNotification(new NewBrokerageOrderNotificationEventArgs(order)). - If the brokerage message handler accepts it (LEAN assigns
order.Id != 0), emitSubmittedplus any fills the order already had, and keep tracking it through the normal update path from then on. - If it is declined (
order.Id == 0), leave the order alone and do not emit further events for it — the algorithm must keep running. - 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
GetOpenOrdersshould skip them instead of failing the launch. - 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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