QuantConnect / Lean.Brokerages.ByBit

ByBit Brokerage Integration to LEAN
4 stars 5 forks source link

Improve Order Error Message #19

Open AlexCatarino opened 7 months ago

AlexCatarino commented 7 months ago

Expected Behavior

Users are informed of the cause of invalid orders.

Actual Behavior

The algorithm received the following information

2024-03-05T15:05:00.7148461Z TRACE:: LiveTradingResultHandler.OrderEvent(): Time: 03/05/2024 15:05:00 OrderID: 2 EventID: 1 Symbol: BTCUSDT Status: Invalid Quantity: -0.047175 Message: Brokerage failed to place orders: [2] BrokerId:

and we don't know why.

When we inpect the syslog, we can read:

ErrorMessage: Cross Margin Trading not yet supported by the selected coin

2024-03-05T15:05:00.7146835Z ERROR:: BrokerageTransactionHandler.HandleSubmitOrderRequest():  System.Exception: ByBitApiClient request failed: [200] OK, Content: {"retCode":170037,"retMsg":"Cross Margin Trading not yet supported by the selected coin","result":{},"retExtInfo":{},"time":1709651100616}, ErrorCode: 170037 ErrorMessage: Cross Margin Trading not yet supported by the selected coin
   at QuantConnect.Brokerages.Bybit.Api.BybitTradeApiEndpoint.PlaceOrder(BybitProductCategory category, Order order, Boolean useMargin)
   at QuantConnect.Brokerages.Bybit.BybitBrokerage.g.d()
   at QuantConnect.Brokerages.BrokerageConcurrentMessageHandler`1.WithLockedStream(Action code) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/LeanEnterprise/Brokerages/BrokerageConcurrentMessageHandler.cs:line 82
   at QuantConnect.Brokerages.Bybit.BybitBrokerage.PlaceOrder(Order order)

The user should receive that error message instead of "Brokerage failed to place orders" or as a Brokerage Message.

Potential Solution

N/A

Reproducing the Problem

SetHolding("BTCUSDT", 1); then SetHolding("BTCUSDT", 0);

Checklist