Skip to content

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

Open

Description

@AlexCatarino

Description

Orders placed outside the algorithm (Coinbase Advanced Trade UI/app, or another system on the same account) are silently dropped. The brokerage subscribes to the account-wide user channel, so their updates arrive, but CoinbaseBrokerage.Messaging.cs:201-205 does if (leanOrder == null) continue; on an unknown brokerage id. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions