Skip to content

Commit

Permalink
feat: coinbase CanUpdateOrder()
Browse files Browse the repository at this point in the history
  • Loading branch information
Romazes committed Jan 2, 2024
1 parent 4135c91 commit 42c1058
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion Common/Brokerages/CoinbaseBrokerageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,47 @@ public override IFeeModel GetFeeModel(Security security)
/// <param name="request">The requested update to be made to the order</param>
/// <param name="message">If this function returns false, a brokerage message detailing why the order may not be updated</param>
/// <returns><c>true</c> if the brokerage supports updating orders; otherwise, <c>false</c>.</returns>
/// <remarks>Coinbase: Only limit order types, with time in force type of good-till-cancelled can be edited.</remarks>
public override bool CanUpdateOrder(Security security, Order order, UpdateOrderRequest request, out BrokerageMessageEvent message)
{
message = _message;
if (order == null || security == null || request == null)
{
var parameter = order == null ? nameof(order) : nameof(security);
throw new ArgumentNullException(parameter, $"{parameter} parameter cannot be null. Please provide a valid {parameter} for submission.");
}

if (order.Type != OrderType.Limit)
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
$"Order with type {order.Type} can't be modified, only LIMIT.");
return false;
}

if (order.TimeInForce != TimeInForce.GoodTilCanceled)
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
$"Order's parameter 'TimeInForce' is not instance of Good Til Cancelled class.");
return false;
}

if (order.Status is not (OrderStatus.New or OrderStatus.PartiallyFilled or OrderStatus.Submitted or OrderStatus.UpdateSubmitted))
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
$"Order with status {order.Status} can't be modified");
return false;
}

if (request.Quantity.HasValue && !IsOrderSizeLargeEnough(security, Math.Abs(request.Quantity.Value)))
{
message = new BrokerageMessageEvent(BrokerageMessageType.Warning, "NotSupported",
Messages.DefaultBrokerageModel.InvalidOrderQuantity(security, request.Quantity.Value));
return false;
}

message = null;
return true;
}

/// <summary>
/// Evaluates whether exchange will accept order. Will reject order update
/// </summary>
Expand Down

0 comments on commit 42c1058

Please sign in to comment.