dominiktraxl / pykrakenapi

A python implementation of the Kraken API.
GNU Lesser General Public License v3.0
225 stars 53 forks source link

query_private() got an unexpected keyword argument 'data' #45

Closed Yemeen closed 3 years ago

Yemeen commented 3 years ago

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!

tsferro2 commented 3 years ago

@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

Yemeen commented 3 years ago

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

tsferro2 commented 3 years ago

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?

tsferro2 commented 3 years ago

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

mans17 commented 3 years ago

This is expected. Kraken API requires to read Every parameters to avoid problems.

Le 17 février 2021 22:22:52 Tucker Sferro notifications@github.com a écrit :

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 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

tsferro2 commented 3 years ago

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 commented 3 years ago

validate=false should help. True IS default.

Le 17 février 2021 22:29:40 Tucker Sferro notifications@github.com a écrit :

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) — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tsferro2 commented 3 years ago

@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?

mans17 commented 3 years ago

Is position already closed ? (Visible as opened on kraken ?)

Le 17 février 2021 23:06:58 Tucker Sferro notifications@github.com a écrit :

@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? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tsferro2 commented 3 years ago

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)

mans17 commented 3 years ago

Since 1854 > 1844 (current level), seems pretty legit to me that you could buy immediatly.

Le 17 février 2021 23:11:06 Tucker Sferro notifications@github.com a écrit :

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

tsferro2 commented 3 years ago

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

tsferro2 commented 3 years ago

...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

tsferro2 commented 3 years ago

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

tsferro2 commented 3 years ago

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)_

dominiktraxl commented 3 years ago

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