Skip to content

Commit

Permalink
Gate.io: Add handling for FOK orders when placing new orders (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
BZ-CO authored Feb 12, 2025
1 parent a6e5527 commit da476f6
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,43 @@ ExchangeOrderRequest order
var payload = await GetNoncePayloadAsync();
AddOrderToPayload(order, payload);

JToken responseToken = await MakeJsonRequestAsync<JToken>(
JToken responseToken;
try
{
responseToken = await MakeJsonRequestAsync<JToken>(
"/spot/orders",
payload: payload,
requestMethod: "POST"
);
);
}
catch (Exception e)
{
// Gate.io returns HTTP status code 400 when an order can't be filled.
if (string.Equals(
e.Message,
"{\"label\":\"FOK_NOT_FILL\",\"message\":\"Order cannot be filled completely\"}",
StringComparison.OrdinalIgnoreCase))
{
var result = new ExchangeOrderResult
{
Amount = order.Amount,
AmountFilled = 0,
Price = order.Price,
AveragePrice = 0,
Message = string.Empty,
OrderId = string.Empty,
OrderDate = DateTime.UtcNow,
MarketSymbol = order.MarketSymbol,
IsBuy = order.IsBuy,
ClientOrderId = order.ClientOrderId,
Result = ExchangeAPIOrderResult.Canceled
};

return result;
}

throw;
}

return ParseOrder(responseToken);
}
Expand Down

0 comments on commit da476f6

Please sign in to comment.