JKorf / Kraken.Net

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

KrakenRestClient.SpotApi.Trading.PlaceOrderAsync error #83

Closed Piggy69 closed 1 year ago

Piggy69 commented 1 year ago

When I send and order to Kraken using

await _krakenClient.SpotApi.Trading.PlaceOrderAsync(symbol, side,type,quantity,clientOrderId,price,secondaryPrice,**timeInForce**,**validateOnly=true**,ct)

I receive an error stating An item with the same key has already been added. Key: timeinforce

If I send the same order without specifying the timeInForce parameter, the call completes successfully. Please note that I cannot remove and test the behavior without the validateOnly=true parameter (really first steps of Kraken integration).

The exact call is: WebCallResult<KrakenPlacedOrder> dispatchResult = await _krakenClient.SpotApi.Trading.PlaceOrderAsync(symbol: dispatchArguments.Symbol, side: dispatchArguments.KrakenOrderSide, type: dispatchArguments.KrakenSpotOrderType, quantity: dispatchArguments.Quantity ?? 0, clientOrderId: Convert.ToUInt32(dispatchArguments.InternalOrderId), price: dispatchArguments.Price, secondaryPrice: dispatchArguments.Price2, timeInForce: Kraken.Net.Enums.TimeInForce.GTC, validateOnly: true, ct: cancellationToken);

Where the real values of the parameters are symbol:BTCUSD side: buy type: limit quantity: 0.001 price: 22220 secondaryPrice:null clientOrderId (a long converted to uint)

The full exception stack is: System.ArgumentException HResult=0x80070057 Message=An item with the same key has already been added. Key: timeinforce Source=System.Private.CoreLib StackTrace: at System.ThrowHelper.ThrowAddingDuplicateWithKeyArgumentException[T](T key) at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at CryptoExchange.Net.ExtensionMethods.AddOptionalParameter(Dictionary2 parameters, String key, Object value) at Kraken.Net.Clients.SpotApi.KrakenRestClientSpotApiTrading.d9.MoveNext() at OrdersManager.KrakenOrdersApi.KrakenSpotRawOrderDispatcher.d6.MoveNext() in C:\Develop\Projects\Repos\CFXQ\FeedManager\OrdersManager\KrakenOrdersApi\KrakenSpotRawOrderDispatcher.cs:line 97 at OrdersManager.CommonOrdersApi.OrderDispatcherBase1.<>c__DisplayClass36_0.<<SendNewOrder>b__0>d.MoveNext() in C:\Develop\Projects\Repos\CFXQ\FeedManager\OrdersManager\CommonOrdersApi\OrderDispatcherBase.cs:line 108 at Polly.Retry.AsyncRetryEngine.<ImplementationAsync>d__01.MoveNext() at Polly.AsyncPolicy1.<ExecuteAsync>d__13.MoveNext() at OrdersManager.CommonOrdersApi.OrderDispatcherBase1.d__36.MoveNext() in C:\Develop\Projects\Repos\CFXQ\FeedManager\OrdersManager\CommonOrdersApi\OrderDispatcherBase.cs:line 108

This exception was originally thrown at this call stack: [External Code] OrdersManager.KrakenOrdersApi.KrakenSpotRawOrderDispatcher.SendNewOrderCore(OrdersManager.OrderObjects.RawAlgoOrder, OrdersManager.OrderObjects.DispatchOrderArguments, System.Threading.CancellationToken) in KrakenSpotRawOrderDispatcher.cs OrdersManager.CommonOrdersApi.OrderDispatcherBase.SendNewOrder.AnonymousMethod__0() in OrderDispatcherBase.cs [External Code] OrdersManager.CommonOrdersApi.OrderDispatcherBase.SendNewOrder(OrdersManager.OrderObjects.MarketOrderBase, OrdersManager.OrderObjects.DispatchOrderArguments, System.Threading.CancellationToken) in OrderDispatcherBase.cs`

JKorf commented 1 year ago

Hi, turns out there was indeed a bug in the PlaceOrder endpoint causing your issue. Should be fixed in the latest version