JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.02k stars 420 forks source link

UsdFutures Limit Order with `TimeInForce` Type `GoodTillDate` Fails #1386

Closed roman-ivanchuk closed 1 week ago

roman-ivanchuk commented 1 week ago

Attempting to place a USD Futures limit order with timeInForce set to GoodTillDate fails due to incorrect timestamp format. The error message indicates that the goodTillDate timestamp must be in milliseconds rather than seconds.

Steps to Reproduce:

  1. Use the following code to place a USD Futures limit order:

    var binanceRestClient = new BinanceRestClient(options => {
        options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
    });
    var goodTillDate = new DateTime(2024, 6, 24, 18, 0, 0);
    
    var orderResult = await binanceRestClient.UsdFuturesApi.Trading.PlaceOrderAsync(
        symbol: "USDCUSDT",
        side: OrderSide.Buy,
        type: FuturesOrderType.Limit,
        quantity: 10m,
        price: 0.9m,
        timeInForce: TimeInForce.GoodTillDate,
        goodTillDate: goodTillDate);
    
    if (!orderResult.Success)
    {
        throw new Exception(orderResult?.Error?.Message);
    }
  2. Observe the error message received:

    The goodTillDate timestamp must be greater than the current time plus 600 seconds and smaller than 253402300799000.
  3. Check the request body sent in the orderResult object:

    goodTillDate=1719252000
  4. Place the same order via the Binance UI and check the request body sent in the network tab of the developer tools:

    goodTillDate=1719252000448

Observed Behavior: The goodTillDate timestamp is sent in seconds (goodTillDate=1719252000), which causes the order to fail.

Expected Behavior: The goodTillDate timestamp should be sent in milliseconds (goodTillDate=1719252000448), as this format executes successfully via the Binance UI.

Additional Context:

Proposed Solution: Change AddOptionalSeconds to AddOptionalMilliseconds in the library code to send the goodTillDate timestamp in the correct format.

parameters.AddOptionalMilliseconds("goodTillDate", goodTillDate);

References: