Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add order giving me invalid Key error. #134

Closed
mshark5 opened this issue Sep 13, 2021 · 5 comments
Closed

Add order giving me invalid Key error. #134

mshark5 opened this issue Sep 13, 2021 · 5 comments

Comments

@mshark5
Copy link

mshark5 commented Sep 13, 2021

Versions

OS:       Windows 10
Python:   3.9
krakenex: latest

What are you trying to achieve?

I am trying to add a limit order. I haven't changed my code in 6 months and it was working perfectly until about four days ago. When I call my balance, it works perfectly. I have created new API Keys to see if the Keys were the issue, but still get the same error on when trying to add an order.

# code sample
import krakenex
import math
import time


def round_down(n, decimals=8):
    multiplier = 10 ** decimals
    return math.floor(n * multiplier) / multiplier

k = krakenex.API()
k.load_key('kraken.key.py')
quote_symbol = 'KEEPUSD'
symbol = 'KEEPUSD'
round_price = 5
quote = k.query_public('Ticker', {'pair': quote_symbol})
USD2 = 800
bp = round(float(str(quote["result"][symbol]["b"][0])), round_price)
bv = round_down(USD2 / bp)
b1 = k.query_private('AddOrder',
                         {'pair': quote_symbol, 'type': 'buy', 'ordertype': 'limit', 'leverage': 'none', 'volume':
                             bv, 'price': bp, 'expiretm': '+10'})
print(b1)

What do you expect to happen?

The limit order to be placed successfully.

What happens instead?

An Invalid API KEY error occurs.

# error message
{'error': ['EAPI:Invalid key']}
@mshark5
Copy link
Author

mshark5 commented Sep 14, 2021

I forgot to add this email from kraken support. I guess they recently updated the add orders endpoint? I don't really know.

Delilah K. (Kraken Support)Sep 8, 2021, 23:15 PDTHello ,Thank you for stressing your use of the krakenex wrapper. It turns out there have been multiple reports from clients regarding this wrapper specifically. The code perhaps should be updated to reflect recent changes made to our REST API endpoints, specifically the AddOrders endpoint. And since this is a third party resource, we are unable to assist with the modifications to that code base in particular as that would be the responsibility of the repo owner.

(formatting edited by @veox)

@veox
Copy link
Owner

veox commented Sep 14, 2021

Search shows something similar in issue #124, and the best explanation then was this:

As to the nature of the rather-misleading error...

{
  "error": [
    "EAPI:Invalid key"
  ]
}

This is probably because the nested data (dict-in-a-dict) is mangled beyond recognition during serialisation. The server then can't even decode the message.

Which could indeed be explained by "recent changes to REST API endpoints"...


... Except that I've just tried your code near-verbatim (replaced KEEPUSD with KEEPEUR, and USD2 = 10), and it worked fine. :/

% ipython
Python 3.9.6 (default, Jun 30 2021, 10:22:16)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: # code sample
   ...: import krakenex
   ...: import math
   ...: import time
   ...:
   ...:
   ...: def round_down(n, decimals=8):
   ...:     multiplier = 10 ** decimals
   ...:     return math.floor(n * multiplier) / multiplier
   ...:
   ...: k = krakenex.API()
   ...: k.load_key('kraken-trade.key')
   ...: quote_symbol = 'KEEPEUR'
   ...: symbol = 'KEEPEUR'
   ...: round_price = 5
   ...: quote = k.query_public('Ticker', {'pair': quote_symbol})
   ...: USD2 = 10
   ...: bp = round(float(str(quote["result"][symbol]["b"][0])), round_price)
   ...: bv = round_down(USD2 / bp)
   ...: b1 = k.query_private('AddOrder',
   ...:                          {'pair': quote_symbol, 'type': 'buy', 'ordertype': 'limit', 'leverage': 'none', 'volum
   ...: e':
   ...:                              bv, 'price': bp, 'expiretm': '+10'})
   ...: print(b1)
{'error': [], 'result': {'txid': ['OORDER-ORDER-ORDERO'], 'descr': {'order': 'buy 28.18966003 KEEPEUR @ limit 0.35474'}}}

In [2]: krakenex.version.__version__
Out[2]: '2.1.0'

In [3]:

I've tried disabling the "Create & Modify Orders" permission on the key, but then the error is different:

{'error': ['EGeneral:Permission denied']}

BTW, I had to force-reload Kraken's key permission editing page (CTRL+r or the like), because it kept showing the same settings after being edited.


Anyway, I can't reproduce the error.

  • Are you sure the key/secret are copied over correctly? EDIT: And that the key has not expired?
  • Is the error produced with the exact code that you've shown?

@veox
Copy link
Owner

veox commented Sep 14, 2021

BTW, you may also want to look through

https://github.com/veox/python3-krakenex/issues?q=EAPI%3AInvalid+key

@veox
Copy link
Owner

veox commented Sep 14, 2021

As I understand, you now have several key files to work with.

You could try setting the key/secret values manually in the script for testing purposes. Like:

k.key = 'KEY-STRING'
k.secret = 'SECRET-STRING'

If that works, then it's something with formatting in kraken.key.py.

@mshark5
Copy link
Author

mshark5 commented Sep 14, 2021

Thank you so much for your help I ended up figuring it out.

For the last 6 months I had my API key and Secret listed in the kraken.key.py as strings:

"keykeykeykeykeykeykeykey"
"secretsecretsecretsecret"

But I guess after the recent update to the add orders endpoint I can't have them as strings. It just has to be:

keykeykeykeykey
secretsecretsecretsecret

Sorry for wasting you time, as I see the example has it listed this way without strings. I guess when I first started building my program I programmed it with strings and it worked perfectly until a recent update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants