dominiktraxl/pykrakenapi

EOrder:Invalid position

Closed this issue · 1 comments

actualTradeID = str(['SOME-REF-ID'])
actualTrade = k.get_open_positions(actualTradeID)

actualTradeID is of str type and it was previously of type list. If I put actualTradeID in get_open_positions while keeping its list type, it returns me the same error.

['SOME-REF-ID'] is the exact ID of an open position.

The issue is coming from the Kraken's rest API. Here's two workarounds :

"The transaction ID filtering option for the OpenPositions endpoint does not currently work as described in the API documentation. Our developers are aware of this discrepancy, and hopefully a resolution will be provided in an upcoming API release.

In the meantime, open positions will need to be filtered by parsing the JSON to retrieve the entry with the appropriate transaction ID, or perhaps using the consolidation parameter (consolidate=market), which would return a response with open positions combined based upon their underlying market:

$ ./krakenapi OpenPositions consolidation=market

{"error":[],"result":[{"pair":"XXBTZUSD","positions":"3","type":"buy","leverage":"5.00000","cost":"54.48520","fee":"0.14712","vol":"0.00600000","vol_closed":"0.00000000","margin":"10.89704"},{"pair":"XXBTZEUR","positions":"1","type":"buy","leverage":"5.00000","cost":"16.12180","fee":"0.04353","vol":"0.00200000","vol_closed":"0.00000000","margin":"3.22436"}]}

Another alternative would be using the TradesHistory endpoint with an end parameter of the desired transaction id, such as:
$ ./krakenapi TradesHistory end=T3UBYN-GXDTI-LKV5Y7

{"error":[],"result":{"trades":{"T3UBYN-GXDTI-LKV5Y7":{"ordertxid":"OAXG2J-XW2VR-J4BAXM","postxid":"TKH2SE-M7IF5-CFI7LT","posstatus":"open","pair":"XXBTZUSD","time":1583565776.4587,"type":"buy","ordertype":"market","price":"9080.80000","cost":"18.16160","fee":"0.04904","vol":"0.00200000","margin":"3.63232","misc":""} ...

which would return the relevant entry as the first entry in the list (after which the rest of the list could be ignored). Note that most of the same information would be returned, with the exception of a couple of fields such as vol_closed and terms."