dominiktraxl/pykrakenapi

query_private() got an unexpected keyword argument 'data'

Yemeen opened this issue · 16 comments

I'm trying to get account balance like so:

import krakenex
from pykrakenapi import KrakenAPI
api = krakenex.API()
krakenkey = "kraken.key"
api.load_key(krakenkey)
k = KrakenAPI(api)
balance = k.get_account_balance()
print(balance)

and get the following:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-38-c65beab1b420> in <module>
----> 1 k.get_account_balance()

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pykrakenapi/pykrakenapi.py in wrapper(*args, **kwargs)
     51         while True:
     52             try:
---> 53                 result = func(*args, **kwargs)
     54                 return result
     55             except CallRateLimitError as err:

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pykrakenapi/pykrakenapi.py in wrapper(*args, **kwargs)
    131                         try:
    132                             self.api_counter += incr
--> 133                             result = func(*args, **kwargs)
    134                             return result
    135                         except (HTTPError, KrakenAPIError) as err:

/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pykrakenapi/pykrakenapi.py in get_account_balance(self, otp)
    855 
    856         # query
--> 857         res = self.api.query_private('Balance', data=data)
    858 
    859         # check for error

TypeError: query_private() got an unexpected keyword argument 'data'

but when I use Kraken's api I can get a balance although with an error:
balance = api.query_private('Balance') gives the following {'error': [], 'result': {'ZUSD': 'My very large balance bc I am not poor', 'XXBT': 'touche'}}

I thought it might be my kraken.key but I put the key and secret on their own lines??

Thanks for all your hard work!

@Yemeen I am completely lost/new to working with APIs - can pull data using the read me example; however, I am at a loss how to even get my balance? ie, in your above example, where do you put your Private Key in? do you also have to put the Public key in?

running your code as is throws:

FileNotFoundError: [Errno 2] No such file or directory: 'kraken.key'
that said, I get the same error when I use my public or private api key for krakenkey in line 4

You need to place your key in kraken.key. Look in the examples folder!

thanks are you talking about the python3-krakenex examples folder? I don't see any examples folder in this repository

I was actually able to establish a connection by using code found in the krakenex issues page, ie:

import krakenex
from krakenex import API
from pykrakenapi import KrakenAPI

api = krakenex.API()
API_KEY = 'xxxx'
SECRET_KEY = 'yyyy'
api = API(API_KEY, SECRET_KEY)
k = KrakenAPI(api)

balance = k.get_account_balance()
print(balance)

k.get_trades_history()

is this similar to your approach?

also, when I attempt to put a limit buy in:

k.add_standard_order(
    pair='XXBTZUSD', 
    type='buy', 
    ordertype='limit',
    price=10000,
    volume=0.001
    )

it returns:
Out[73]: {'descr': {'order': 'buy 0.00100000 XBTUSD @ limit 10000.0'}}

but the order does not look like its actually being sent to the exchange, ie is not appearing in my account and:

k.get_open_orders( )

returns an empty dataframe

thanks @mans17 ; however as far as I can tell I've passed all the non-optional arguments:
(https://www.kraken.com/features/api#add-standard-order)

@mans17 that did it, thanks!

I was able to send/open a small ETHUSD position, but k.get_open_positions() returns an empty dictionary...any ideas?

actually I looked more closely and the order was for some reason closed which is strange because the market traded through it:

buy/limit | ETH/USD | $1,854.00 | 0.01000000 | $18.54 | Closed | 02-17-21 22:01:59 +0000
-- | -- | -- | -- | -- | -- | --



I tried another order of size 0.03 ETHUSD and that was also "CLOSED" when the market traded through the price, I have no idea why that would happen:

[buy/limit ETH/USD $1,854.00 0.01000000 $18.54 Closed 02-17-21 22:01:59 +0000

](url)

yes and I saw both orders in the market depth AND the offer price went below my bid/bid disappeared ?!?!?!?

...looking closer, the trades did execute, ie they are showing up in get_account_balance() and get_trades_history(); however, when I call get_open_positions(), I get an empty dictionary

plus - the trades are not showing up on kraken.com "Open Positions by Order" BUT they ARE showing in my kraken.com Balances page ?!?

just FYI for anyone reading this thread, I heard back from kraken in regards to this issue and:

_"...open positions are only relevant to margin orders.

Thus, a traditional order, such as a limit or market, will not show up in the open positions tab.

However, you will be able to see this information via the OpenOrders or QueryOrders API Endpoint."_

and:

_BalanceEx Endpoint

The REST API BalanceEx endpoint will provide the information that you are looking for, namely the amount of each account balance currency that is withheld (due to existing open orders, for example).

(Note: this Is a newer endpoint and undocumented)_

The issue seems to be resolved, please reopen if I'm mistaken.