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

OSX: json.decoder.JSONDecodeError #28

Closed
Lajoix opened this issue Jul 4, 2017 · 5 comments
Closed

OSX: json.decoder.JSONDecodeError #28

Lajoix opened this issue Jul 4, 2017 · 5 comments

Comments

@Lajoix
Copy link

Lajoix commented Jul 4, 2017

Hey,

I'm new to the krakenex API, i'm trying to do the following

import krakenex
import time

class krakencom():
    def __init__(self):
        self.k = krakenex.API(key='abc',secret="def")

    def getEthEur(self):
        self.etheur = self.k.query_public('Ticker', {'pair': 'ETHEUR'})["result"]['XETHZEUR']
        return self.etheur

    def lowestPrice(self, cur):
        lowestPrice = cur['l']
        return lowestPrice

    def highestPrice(self, cur):
        highestPrice = cur['h']
        return highestPrice

    def volume24h(self, cur):
        volume24h = cur['v'][1]
        return volume24h

    def lastTrade(self, cur):
        lastTrade = cur['c']
        return lastTrade


krak = krakencom()
while True:
    eth = krak.getEthEur()
    print(krak.lastTrade(eth))
    time.sleep(0.5)

the out put is

[‘RESULT', 'RESULT]

and after a while ERROR !!!?!
The error happens randomly from the second query

Traceback (most recent call last):
  File "/Users/MYUSER/MYDIR/MYPROJECT/krakapi.py", line 32, in <module>
    eth = krak.getEthEur()
  File "/Users/MYUSER/MYDIR/MYPROJECT/krakapi.py", line 10, in getEthEur
    self.etheur = self.k.query_public('Ticker', {'pair': 'ETHEUR'})["result"]['XETHZEUR']
  File "/usr/local/lib/python3.6/site-packages/krakenex/api.py", line 148, in query_public
    return self._query(urlpath, req, conn)
  File "/usr/local/lib/python3.6/site-packages/krakenex/api.py", line 131, in _query
    return json.loads(ret)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

i'm on OSX 10.11.6 python 3.6.1

many thanks

lj

@veox veox mentioned this issue Jul 4, 2017
@veox
Copy link
Owner

veox commented Jul 4, 2017

i'm trying to do the following

Do describe (not in code) on what it is you're trying to do - the code shows what you're actually doing.

What is the output of krakenex.version.__version__?

Tentatively an issue with OSX decoding the JSON?.. I.e., system-related, not package-related.

Other than that, the code is likely to fail - in krakencom(), you're accessing cur['c'], where cur is the query response received previously from getEthEur()... As far as I remember, the response doesn't have a 'c' key.

@veox
Copy link
Owner

veox commented Jul 4, 2017

Does the (updated) depth.py example give this error? (If so, post it here.)

@veox veox changed the title json.decoder.JSONDecodeError OSX: json.decoder.JSONDecodeError Jul 13, 2017
@jacob-roth
Copy link

jacob-roth commented Jul 29, 2017

I've been getting this too. Using Mac Sierra 10.12.5, Python3.5, krakenex 0.1.4.

Background on my problem: I'm trying to pull all ticker data for all assetpairs at a particular time. I initialize the API as k and use k.query_public(method="Ticker", req={"pair":pair}) for each pair in a list of assetpairs. Sometimes when I run the request on the entire list of 64 assetpairs (from DASHEUR to XZECZUSD), I receive the following error:

Traceback (most recent call last):
.
.
.
  File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/site-packages/krakenex/api.py", line 148, in query_public
    return self._query(urlpath, req, conn)
  File "/MYUSER/anaconda/envs/python3/lib/python3.5/site-packages/krakenex/api.py", line 131, in _query
    return json.loads(ret)
  File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/MYUSER/anaconda/envs/python3/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

As an aside, the issue of c as a key should be fine according to Kraken's API:

<pair_name> = pair name
a = ask array(, , ),
b = bid array(, , ),
c = last trade closed array(, ),
v = volume array(, <last 24 hours>),
p = volume weighted average price array(, <last 24 hours>),
t = number of trades array(, <last 24 hours>),
l = low array(, <last 24 hours>),
h = high array(, <last 24 hours>),
o = today's opening price

and from my testing of the c key with ticker data, it works except for the above error.

@veox
Copy link
Owner

veox commented Jul 31, 2017

@jacob-roth See if PR #17 helps with what you describe.

It's available in current master, and release v1.0.0a0 (not on PyPI, though, since alpha).


EDIT: shorten, said wrong version

@veox
Copy link
Owner

veox commented Aug 6, 2017

In short: the error probably stems from krakenex not (previously) handling a connection error, and passing bogus (non-JSON) response from Connection to API.

Closing as stale.

Request reopen, or open separate issue, if present in latest v1.0.0 alphas.

Otherwise, wait for for v1.0.0 (probably at least a month out); or (if using v0.1.4, which is the current stable ATM) try/except for the JSONDecodeError (ugly and improper, I know - sorry).

@veox veox closed this as completed Aug 6, 2017
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

3 participants