How to open and cancel orders

In the following example you can see how to set up a buy order and cancel it shortly after. The parameter "userref" restrict results to given user reference ID of your choice (32-bit signed number):

# open new buy order
buy_vol   = '0.02' 
buy_price = '150'  
buy  = k.query_private('AddOrder', {'pair':pair, 'type':'buy', 'ordertype':'limit', 'leverage':'none', 'volume':buy_vol, 'price':buy_price, 'userref':ref_buy})
print buy
# close buy order in case it exists
close_buy = k.query_private('CancelOrder', {'txid':ref_buy})
print close_buy 


See our API documentation about the "CancelOrder" call:

https://www.kraken.com/help/api#cancel-open-order