Giter VIP home page Giter VIP logo

lean.brokerages.bybit's Issues

Exception during funding when running live

When running live and there is an open position when funding happens an exception is thrown and the algo stops. Apparently, I never had a trade open during funding when I was initially testing this brokerage ๐Ÿ™ˆ

Expected Behavior

The brokerage handles the funding ws message properly.

Actual Behavior

A serialization exception is thrown cause there is no OrderType which equals UNKNOWN

Potential Solution

Add UNKNOWN to the OrderType enum and handle the funding message properly. @Martin-Molinero do we need to submit an order update when funding occurs?

Reproducing the Problem

Having an open order when funding occurs. I unfortunately don't have the exact log anymore.

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

Order can not always be canceled

Expected Behavior

Orders are being canceled at all times without issues.

Actual Behavior

Some orders can not always be canceled, it happens in multiple occasions but It seems I found one way to reliably reproduce it. (See reproducing the problem)

Potential Solution

Don't raise an error when the status is CancelPending here:

if (order.Status is OrderStatus.Canceled or OrderStatus.CancelPending)
{
OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Warning, -1,
"Order already canceled or cancellation submitted"));
return;
}

It seems that sometimes the order status is already CancelPending even though the cancel request was never sent to the brokerage.

Reproducing the Problem

  • Create an empty algo using the bybit brokerage. Which calls liquidate after startup.
  • Manually create an order in the exchange
  • Start the algorithm, the following error should pop up:
20231129 06:56:56.592 ERROR:: Brokerage Warning: Order already canceled or cancellation submitted
20231129 06:56:56.593 ERROR:: Brokerage failed to cancel order with id 1

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

Improve Order Error Message

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

  • 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

Zero Stop Price From Open Stop Market Order on Deployment

Expected Behavior

LEAN fetches open orders from Bybit and creates the LEAN orders accordingly.

Actual Behavior

StopMarketOrders have zero stop prices. LimitOrders have non-zero limit prices as expected.

Reproducing the Problem

Place StopMarketOrder orders with Binance Futures, and stop the algorithm. Redeploy and verify the new stop price is zero.

System Information

Observed with LEAN CLI.

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

Data Downloader

  • Review data downloader so it fits the expected pattern and behavior following other brokerage implementations:
    - The downloader should be able to be initialized by the composer, see error below
    - ...
Error Message:
 ---> System.MissingMethodException: Cannot dynamically create an instance of type 'QuantConnect.Brokerages.Bybit.ToolBox.BybitBrokerageDownloader'. Reason: No parameterless constructor
defined.
   at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at QuantConnect.Util.Composer.GetExportedValueByTypeName[T](String typeName, Boolean forceTypeNameOnExisting) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Util/Composer.cs:line 290
   at QuantConnect.Lean.Engine.DataFeeds.DownloaderDataProvider..ctor() in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/DataFeeds/DownloaderDataProvider.cs:line 57
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at QuantConnect.Util.Composer.GetExportedValueByTypeName[T](String typeName, Boolean forceTypeNameOnExisting) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Util/Composer.cs:line 290
   at QuantConnect.Lean.Engine.LeanEngineAlgorithmHandlers.FromConfiguration(Composer composer, Boolean researchMode) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/LeanEngineAlgorithmHandlers.cs:line 208

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.