krakex
krakex copied to clipboard
Conditional Closes on Limit Order
Hi,
I'm trying to figure out how to add a conditional close to a limit order, specifically a take profit condition. On a standard limit order you would write something like:
Krakex.add_order(pair, "buy", "limit", lot_size, [price: buy_price])
After looking through the Krakex docs and the Kraken API I see another order type called take-profit-limit
. I've tried this as well in the following fashion:
Krakex.add_order(pair, "buy", "take-profit-limit", lot_size, [price: sell_price, price2: buy_price])
But I seem to get back an error of: EGeneral:Invalid arguments:ordertype
If you could give me a hand figuring out where I'm misapplying this it would be greatly appreciated.
@iancharters So, three years to the day and I finally get around to answering you. 😄 Up until today this library actually didn't support conditional closes for several reasons: A) it wasn't documented in Kraken's REST API and B) I hadn't needed it myself. In the meantime A still hasn't changed but B has. I was able to find out how to implement it by reading code in the python client and it turns out it was pretty simple. So, by the off chance that you're still using this library, this is how you can now execute an order with a conditional close:
Krakex.add_order("XRPEUR", "sell", "limit", "20", price: "0.38", close: [ordertype: "limit", price: "0.37"])
That will return something like:
{:ok,
%{
"descr" => %{
"close" => "close position @ limit 0.37000",
"order" => "sell 20.00000000 XRPEUR @ limit 0.38000"
},
"txid" => ["OJAOUK-YWLRG-YM5D7L"]
}}
There's no need to set the type
on a close, i.e. if you're buying the conditional close will be a "sell" and vice-versa. All order types are supported for the conditional close; the three available keyword args are ordertype:
, price:
and price2:
(depending on your order type).
Thanks for bringing this up and sorry again for such an inexcusably late reply. 🤷🏻♂️