From cd6d3ac2041fe3ba55aa8137fcbcec385a818aa3 Mon Sep 17 00:00:00 2001 From: BZ-CO <30245815+BZ-CO@users.noreply.github.com> Date: Wed, 12 Feb 2025 20:57:45 +0200 Subject: [PATCH] Gate.io: Add handling for FOK orders when placing new orders --- .../API/Exchanges/GateIo/ExchangeGateIoAPI.cs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs index 8535d69c..b1519761 100644 --- a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs @@ -343,11 +343,43 @@ ExchangeOrderRequest order var payload = await GetNoncePayloadAsync(); AddOrderToPayload(order, payload); - JToken responseToken = await MakeJsonRequestAsync( + JToken responseToken; + try + { + responseToken = await MakeJsonRequestAsync( "/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); }