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

Bithumb fetch_balance() Error(ver 1.9.153) #333

Closed
whtwhtwht53 opened this issue Oct 17, 2017 · 28 comments
Closed

Bithumb fetch_balance() Error(ver 1.9.153) #333

whtwhtwht53 opened this issue Oct 17, 2017 · 28 comments
Assignees

Comments

@whtwhtwht53
Copy link

whtwhtwht53 commented Oct 17, 2017

Code:

bithumb1 = ccxt.bithumb()
bithumb1.apiKey = "*********************"
bithumb1.secret = "**********************"
print(bithumb1.fetch_balance())

Result:

POST https://api.bithumb.com/info/balance 400 Bad Request  (possible reasons: invalid API keys, bad or old nonce, exchange is down or offline, on maintenance, DDoS protection, rate-limiting, {"status":"5100","message":"Bad Request.(Auth Data)"})

I have checked the doc , maybe the reason is that the function privatePostInfoBalance miss a params "currency"

@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

@whtwhtwht53 hi! I'll take a look into it and will get back to you soon! Thx for your report!

P.S. An advice for future: use triple backticks formatting for readability:
```
code
```
or
```
text results
```

I'll be right back )

@kroitor kroitor self-assigned this Oct 17, 2017
@whtwhtwht53
Copy link
Author

whtwhtwht53 commented Oct 17, 2017

Thank you,Igor!

P.S. This is the first issue I opened in GitHub,I will pay attention to it later :)

@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

@whtwhtwht53 can I ask you to paste your verbose output plz? Run this:

bithumb1 = ccxt.bithumb()
bithumb1.apiKey = "*********************"
bithumb1.secret = "**********************"
bithumb1.verbose = True  # ←--------------------------- add this line
print(bithumb1.fetch_balance())

And copy the output here (enclosed in triple backticks). Thx!

@whtwhtwht53
Copy link
Author

Result

https://api.bithumb.com/info/balance POST https://api.bithumb.com/info/balance 
Request: {'Api-Key': '×××××××××××××××××××××', 'Api-Sign': b'qCHx3Sa3yNhQa/KSgTwU1VxJ7dgx5nB8lOCg5WoNSerVZk91qkHrXl7igP/UUOpR05rfEOSUZQUB5+Kp/qIh7A==', 'Api-Nonce': '1508259633554', 'User-Agent': 'ccxt/1.9.153 (+https://github.com/ccxt-dev/ccxt) Python/3.6.1', 'Accept-Encoding': 'gzip, deflate'} endPoint=%2Finfo%2Fbalance

@whtwhtwht53
Copy link
Author

I succeed in getting account by bithumb‘s demo,its endPoint is

'endpoint=%2Finfo%2Fbalance&currency=ETH'

kroitor added a commit that referenced this issue Oct 17, 2017
@kroitor
Copy link
Member

kroitor commented Oct 17, 2017

@whtwhtwht53 can you please update to latest version 1.9.166 (or higher) and retry the same code of yours:

bithumb1 = ccxt.bithumb()
bithumb1.apiKey = "*********************"
bithumb1.secret = "**********************"
bithumb1.verbose = True  # ←--------------------------- keep it for now
print(bithumb1.fetch_balance())

What do you see now having the latest version?

@whtwhtwht53
Copy link
Author

I'sorry that I still cannot get balance,
Result

Connected to pydev debugger (build 172.3544.44)
https://api.bithumb.com/info/balance POST https://api.bithumb.com/info/balance 
Request: {'Api-Key': '******************************************', 'Api-Sign': b'aXgSfvlBgEmdtHwt4Vmj2++GWaJfOCnw3UdjO2po4ln4IF/j4g2sQPwxv/kAHc5HvYCZ3V9hGHvoWujAhROYqg==', 'Api-Nonce': '1508335680347', 'User-Agent': 'ccxt/1.9.177 (+https://github.com/ccxt-dev/ccxt) Python/3.6.1', 'Accept-Encoding': 'gzip, deflate'} endPoint=%2Finfo%2Fbalance&currency=ALL
Traceback (most recent call last):
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 269, in fetch
    response = opener.open(request, timeout=int(self.timeout / 1000))
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wht/Apps/pycharm-community-2017.2/helpers/pydev/pydevd.py", line 1599, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/home/wht/Apps/pycharm-community-2017.2/helpers/pydev/pydevd.py", line 1026, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/wht/Apps/pycharm-community-2017.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/wht/LTCBTC/test1.py", line 14, in <module>
    print(bithumb1.fetch_balance())
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3607, in fetch_balance
    }, params))
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3763, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 238, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 276, in fetch
    self.handle_rest_errors(e, e.code, text, url, method)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 324, in handle_rest_errors
    self.raise_error(error, url, method, exception if exception else str(http_status_code), details)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 223, in raise_error
    details,
ccxt.errors.ExchangeNotAvailable: bithumb POST https://api.bithumb.com/info/balance 400 Bad Request  (possible reasons: invalid API keys, bad or old nonce, exchange is down or offline, on maintenance, DDoS protection, rate-limiting, {"status":"5100","message":"Bad Request.(Auth Data)"})

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 ok, thx for reporting back, I'm going to debug it further and will get back to you asap with a fix for it. Hold on, please!

@whtwhtwht53
Copy link
Author

whtwhtwht53 commented Oct 18, 2017

I check demo's Post is 'endpoint=......' not ' endPoint=......' , does it matter?

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 they actually have it different in various demos %)) I'll upload the lowercase "endpoint" and we'll try again, it may be the cause of the problem, yes. Just a second.

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

screen shot 2017-10-18 at 17 23 25

screen shot 2017-10-18 at 17 23 01

screen shot 2017-10-18 at 17 22 50

@whtwhtwht53
Copy link
Author

I fix in my own code

   def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
        endpoint = '/' + self.implode_params(path, params)
        url = self.urls['api'][api] + endpoint
        query = self.omit(params, self.extract_params(path))
        if api == 'public':
            if query:
                url += '?' + self.urlencode(query)
        else:
            body = self.urlencode(self.extend({
                'endpoint': endpoint,            <----------------------
            }, query))
            nonce = str(self.nonce())
            auth = endpoint + "\0" + body + "\0" + nonce
            signature = self.hmac(self.encode(auth), self.encode(self.secret), hashlib.sha512, 'base64')
            headers = {
                'Api-Key': self.apiKey,
                'Api-Sign': signature,
                'Api-Nonce': nonce,
            }

but it still does not work

https://api.bithumb.com/info/balance POST https://api.bithumb.com/info/balance 
Request: {'Api-Key': ' ****', 'Api-Sign': b'Y7c9/SN4fGlknNIEzhpmf3PLcQYyf3d3p9KRny1yWN5WQnc5kWmJ8NRGfjfohwuJ5KGjW4ZXn7OD05Ef7kotYA==', 'Api-Nonce': '1508337881429', 'User-Agent': 'ccxt/1.9.177 (+https://github.com/ccxt-dev/ccxt) Python/3.6.1', 'Accept-Encoding': 'gzip, deflate'} endpoint=%2Finfo%2Fbalance&currency=ALL
Traceback (most recent call last):
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 269, in fetch
    response = opener.open(request, timeout=int(self.timeout / 1000))
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/home/wht/anaconda3/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/wht/LTCBTC/test1.py", line 14, in <module>
    print(bithumb1.fetch_balance())
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3607, in fetch_balance
    }, params))
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3763, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 238, in fetch2
    return self.fetch(request['url'], request['method'], request['headers'], request['body'])
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 276, in fetch
    self.handle_rest_errors(e, e.code, text, url, method)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 324, in handle_rest_errors
    self.raise_error(error, url, method, exception if exception else str(http_status_code), details)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 223, in raise_error
    details,
ccxt.errors.ExchangeNotAvailable: bithumb POST https://api.bithumb.com/info/balance 400 Bad Request  (possible reasons: invalid API keys, bad or old nonce, exchange is down or offline, on maintenance, DDoS protection, rate-limiting, {"status":"5100","message":"Bad Request.(Auth Data)"})

Process finished with exit code 1

@whtwhtwht53
Copy link
Author

I update to 1.9.178, It still not works

kroitor added a commit that referenced this issue Oct 18, 2017
@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 just a second, I think I found the problem... I'll update you very shortly.

@whtwhtwht53
Copy link
Author

OK,and I find demo's code has

 utf8_api_sign = api_sign.decode('utf-8')

It decode api_sign to utf-8 , but the Result

'Api-Sign': b'Y7c9/SN4fGlknNIEzhpmf

does it matter

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 we'll see, i'll upload first version of the fix in a few minutes and if it doesn't work, we'll try it with decode as well. One moment, please.

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 can you please try it with v.1.9.179 now? It will either work or it will complain about str vs bytes in Python. If it complains, I'll do another quick fix and it should work after that. Waiting for your reply now.

@whtwhtwht53
Copy link
Author

I use pip in ubuntu ,but the version I can get is 1.9.179,not 180

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

@whtwhtwht53 sorry, it was a typo, the correct number is 1.9.179

@whtwhtwht53
Copy link
Author

Result

Traceback (most recent call last):
  File "/home/wht/LTCBTC/test1.py", line 14, in <module>
    print(bithumb1.fetch_balance())
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3607, in fetch_balance
    }, params))
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3763, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 237, in fetch2
    request = self.sign(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3757, in sign
    'Api-Sign': base64.b64encode(signature),
  File "/home/wht/anaconda3/lib/python3.6/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Alright! We're almost there. I'll upload another small fix now and it should finally work. Just one more minute please.

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Ok, let's update to 1.9.180 now and try it once again... Sorry for bothering you, I just have to defeat this bug.

@whtwhtwht53
Copy link
Author

you don't bother me,I have to defeat this bug ,too :)
it still the same error,;(

Traceback (most recent call last):
  File "/home/wht/LTCBTC/test1.py", line 14, in <module>
    print(bithumb1.fetch_balance())
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3607, in fetch_balance
    }, params))
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3763, in request
    response = self.fetch2(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchange.py", line 237, in fetch2
    request = self.sign(path, api, method, params, headers, body)
  File "/home/wht/anaconda3/lib/python3.6/site-packages/ccxt/exchanges.py", line 3757, in sign
    'Api-Sign': self.decode(base64.b64encode(signature)),
  File "/home/wht/anaconda3/lib/python3.6/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

kroitor added a commit that referenced this issue Oct 18, 2017
@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

That's one nasty bug!

Can you please update now to 1.9.181 and try it? We will eventually find the correct signature encoding, we already made it half through.

@whtwhtwht53
Copy link
Author

It works!!!!!
Result

{"status":"0000","data":{"total_krw":4159422,"in_use_krw":0,"available_krw":4159422,"misu_krw":0,"misu_depo_krw":0,"total_btc":"0.00002113","in_use_btc":"0.00000000","available_btc":"0.00002113","misu_btc":"0.00000000","xcoin_last_btc":"6026000","total_eth":"0.00000000","in_use_eth":"0.00000000","available_eth":"0.00000000","misu_eth":0,"xcoin_last_eth":"345400","total_dash":"0.00000000","in_use_dash":"0.00000000","available_dash":"0.00000000","misu_dash":0,"xcoin_last_dash":"323700","total_ltc":"0.00000000","in_use_ltc":"0.00000000","available_ltc":"0.00000000","misu_ltc":0,"xcoin_last_ltc":"63430","total_etc":"0.00000000","in_use_etc":"0.00000000","available_etc":"0.00000000","misu_etc":0,"xcoin_last_etc":"12580","total_xrp":"0.00000000","in_use_xrp":"0.00000000","available_xrp":"0.00000000","misu_xrp":0,"xcoin_last_xrp":"250","total_bch":"0.00000000","in_use_bch":"0.00000000","available_bch":"0.00000000","misu_bch":0,"xcoin_last_bch":"365000","total_xmr":"0.00000000","in_use_xmr":"0.00000000","available_xmr":"0.00000000","misu_xmr":0,"xcoin_last_xmr":"100670","total_zec":"0.00000000","in_use_zec":"0.00000000","available_zec":"0.00000000","misu_zec":0,"xcoin_last_zec":"251950"}}
{'info': {'status': '0000', 'data': {'total_krw': 4159422, 'in_use_krw': 0, 'available_krw': 4159422, 'misu_krw': 0, 'misu_depo_krw': 0, 'total_btc': '0.00002113', 'in_use_btc': '0.00000000', 'available_btc': '0.00002113', 'misu_btc': '0.00000000', 'xcoin_last_btc': '6026000', 'total_eth': '0.00000000', 'in_use_eth': '0.00000000', 'available_eth': '0.00000000', 'misu_eth': 0, 'xcoin_last_eth': '345400', 'total_dash': '0.00000000', 'in_use_dash': '0.00000000', 'available_dash': '0.00000000', 'misu_dash': 0, 'xcoin_last_dash': '323700', 'total_ltc': '0.00000000', 'in_use_ltc': '0.00000000', 'available_ltc': '0.00000000', 'misu_ltc': 0, 'xcoin_last_ltc': '63430', 'total_etc': '0.00000000', 'in_use_etc': '0.00000000', 'available_etc': '0.00000000', 'misu_etc': 0, 'xcoin_last_etc': '12580', 'total_xrp': '0.00000000', 'in_use_xrp': '0.00000000', 'available_xrp': '0.00000000', 'misu_xrp': 0, 'xcoin_last_xrp': '250', 'total_bch': '0.00000000', 'in_use_bch': '0.00000000', 'available_bch': '0.00000000', 'misu_bch': 0, 'xcoin_last_bch': '365000', 'total_xmr': '0.00000000', 'in_use_xmr': '0.00000000', 'available_xmr': '0.00000000', 'misu_xmr': 0, 'xcoin_last_xmr': '100670', 'total_zec': '0.00000000', 'in_use_zec': '0.00000000', 'available_zec': '0.00000000', 'misu_zec': 0, 'xcoin_last_zec': '251950'}}, 'BCH': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'BTC': {'free': 2.113e-05, 'used': 0.0, 'total': 2.113e-05}, 'DASH': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'ETC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'ETH': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'KRW': {'free': 4159422.0, 'used': None, 'total': 4159422.0}, 'LTC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'XMR': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'XRP': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'ZEC': {'free': 0.0, 'used': 0.0, 'total': 0.0}, 'free': {'BCH': 0.0, 'BTC': 2.113e-05, 'DASH': 0.0, 'ETC': 0.0, 'ETH': 0.0, 'KRW': 4159422.0, 'LTC': 0.0, 'XMR': 0.0, 'XRP': 0.0, 'ZEC': 0.0}, 'used': {'BCH': 0.0, 'BTC': 0.0, 'DASH': 0.0, 'ETC': 0.0, 'ETH': 0.0, 'KRW': None, 'LTC': 0.0, 'XMR': 0.0, 'XRP': 0.0, 'ZEC': 0.0}, 'total': {'BCH': 0.0, 'BTC': 2.113e-05, 'DASH': 0.0, 'ETC': 0.0, 'ETH': 0.0, 'KRW': 4159422.0, 'LTC': 0.0, 'XMR': 0.0, 'XRP': 0.0, 'ZEC': 0.0}}

@whtwhtwht53
Copy link
Author

Thank you for your hard working!! This project is amazing!

@kroitor
Copy link
Member

kroitor commented Oct 18, 2017

Alright! We made it! ) Your help was awesome! Thx for your ivolvement, it really means a lot to us and many other users. Let us know if you have any other difficulties with the library. Cheers!

@kroitor kroitor closed this as completed Oct 18, 2017
@whtwhtwht53
Copy link
Author

OK.If I have other difficulties,I will contact you:) thx for your brilliant work again ~~

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

No branches or pull requests

2 participants