Skip to content

Commit

Permalink
TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Nov 14, 2023
1 parent dbfb055 commit ab171a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions QuantConnect.BybitBrokerage/BybitBrokerage.Brokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions QuantConnect.BybitBrokerage/BybitBrokerage.Messaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private void OnUserMessage(WebSocketMessage webSocketMessage)
private void HandleOrderExecution(JToken message)
{
var tradeUpdates = message.ToObject<BybitDataMessage<BybitTradeUpdate[]>>(JsonSerializer).Data;
var i = 0;
foreach (var tradeUpdate in tradeUpdates)
{
var leanOrder = OrderProvider.GetOrdersByBrokerageId(tradeUpdate.OrderId).FirstOrDefault();
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit ab171a5

Please sign in to comment.