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
101 stars 53 forks source link

Cannot add TrailingStopLimit Order #114

Open Toradar opened 3 weeks ago

Toradar commented 3 weeks ago

Describe the bug The price/secondaryPrice can only be passed as decimal, but Kraken requires a prefix in the price field input for Trailing Stop/Trailing Stop Limit orders, which is optional for other order types. Although the Trailing Stop/Trailing Stop Limit orders are supported, there is no no option to set a prefix.

To Reproduce Place an Order of type TrailingStop or TrailingStopLimit, e.g.

var order = await _krakenRestClient.SpotApi.Trading.PlaceOrderAsync( symbol: "XETHZEUR", type: OrderType.TrailingStopLimit, side: OrderSide.Buy, quantity: 0.04, price: 24.78, // Trailing offset, Kraken expects the "+" or "%" prefix secondaryPrice: 23.544 // Trailing Limit order offset, Kraken expects the "+" or "%" prefix );

Expected behavior The Order can be placed.

Debug logging Request Body: nonce=638602247173715770&ordertype=trailing-stop-limit&pair=ETH%2fEUR&price=24.78&price2=23.544&trading_agreement=agree&type=buy&volume=0.04

ErrorMessage: EGeneral:Invalid arguments:price

According to https://docs.kraken.com/rest/#tag/Spot-Trading/operation/addOrder:

Trailing Stops: Must use a relative price for this field, namely the + prefix, from which the direction will be automatic based on if the original order is a buy or sell (no need to use - or #). The % suffix also works for these order types to use a relative percentage price.

JKorf commented 3 weeks ago

Hi, you're right. It a bit of a pain as I'd like to take the price field types a decimal type, but then you can't specify the '+' or '%' signs as you found. In the latest version I've added the pricePrefixOperator, priceSuffixOperator, secondaryPricePrefixOperator and secondaryPriceSuffixOperator parameters to PlaceOrderAsync so you can specify them manually as sort of a workaround.