From ab171a54f557b300a3b9aaf768c674c5d5cbf0c1 Mon Sep 17 00:00:00 2001 From: Jhonathan Abreu Date: Tue, 14 Nov 2023 12:14:25 -0400 Subject: [PATCH] TEST --- .../BybitBrokerage.Brokerage.cs | 1 + .../BybitBrokerage.Messaging.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs b/QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs index 1934e43..274f564 100644 --- a/QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs +++ b/QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs @@ -129,6 +129,7 @@ public override bool PlaceOrder(Order order) var result = ApiClient.Trade.PlaceOrder(GetBybitProductCategory(order.Symbol), order, useMargin: _algorithm.BrokerageModel.AccountType == AccountType.Margin); order.BrokerId.Add(result.OrderId); + Logging.Log.Trace($"PLACING ORDER: OrderId: {result.OrderId}. Quantity: {order.Quantity}."); OnOrderEvent(new OrderEvent(order, DateTime.UtcNow, OrderFee.Zero, "Bybit Order Event") { Status = OrderStatus.Submitted diff --git a/QuantConnect.BybitBrokerage/BybitBrokerage.Messaging.cs b/QuantConnect.BybitBrokerage/BybitBrokerage.Messaging.cs index e36dcff..be40c2e 100644 --- a/QuantConnect.BybitBrokerage/BybitBrokerage.Messaging.cs +++ b/QuantConnect.BybitBrokerage/BybitBrokerage.Messaging.cs @@ -114,6 +114,7 @@ private void OnUserMessage(WebSocketMessage webSocketMessage) private void HandleOrderExecution(JToken message) { var tradeUpdates = message.ToObject>(JsonSerializer).Data; + var i = 0; foreach (var tradeUpdate in tradeUpdates) { var leanOrder = OrderProvider.GetOrdersByBrokerageId(tradeUpdate.OrderId).FirstOrDefault(); @@ -163,6 +164,16 @@ private void HandleOrderExecution(JToken message) filledQuantity * Math.Sign(leanOrder.Quantity), fee); + var partialFillMessage = string.Empty; + if (status == Orders.OrderStatus.PartiallyFilled) + { + partialFillMessage = $"\nPARTIAL FILL DATA: Partially filled: {accumulatedFilledQuantity + filledQuantity}/{leanOrder.AbsoluteQuantity}"; + } + Log.Trace($"HANDLING EXCECUTION: Order ID: {leanOrder.Id}. Quantity {tradeUpdate.ExecutionQuantity}. \n" + + $"WEBSOCKET MESSAGE DATA: Order quantity: {message["data"][i]["orderQty"]}. Remaining quantity: {message["data"][i]["leavesQty"]}." + + partialFillMessage); + i++; + OnOrderEvent(orderEvent); }