yasinkuyu / binance-trader

💰 Cryptocurrency Trading Bot for Binance (Experimental)
2.51k stars 826 forks source link

Issue 160 fixed; 'Signature for this request is not valid' error message #192

Closed ykartal closed 6 years ago

ykartal commented 6 years ago

/myTrades endpoint support added _sign method updated to avoid 'Signature for this request is not valid' error message

Plarkass commented 6 years ago

Hi, Issue still present price:0.00069853 buyp:0.00068826 sellp:0.00069513-bid:0.00068825 ask:0.00069725 spread:1.31 m: Signature for this request is not valid.

ykartal commented 6 years ago

Hi, Did you try get_myTrades(symbol, limit)

Plarkass commented 6 years ago

It work fot the test that you ask get_myTrades(symbol, limit)

i update python-binance to the lastest version v0.6.5 import config

from BinanceAPI import BinanceAPI from Messages import Messages client = BinanceAPI(config.api_key, config.api_secret) test = client.get_myTrades('ENJBTC', 50) print test

result : [{u'orderId': 1672948, u'isBuyer': True, u'price': u'0.00000632', u'isMaker': False, u'qty': u'4.00000000', u'commission': u'0.00400000', u'time': 1513809949705, u'commissionAsset': u'ENJ', u'id': 167068, u'isBestMatch': True}, {u'orderId': 1734916, u'isBuyer': False, u'price': u'0.00000604', u'isMaker': False, u'qty': u'3.00000000', u'commission': u'0.00000002', u'time': 1513928429292, u'commissionAsset': u'BTC', u'id': 177698, u'isBestMatch': True}, {u'orderId': 1765875, u'isBuyer': True, u'price': u'0.00000782', u'isMaker': False, u'qty': u'50.00000000', u'commission': u'0.05000000', u'time': 1513992621461, u'commissionAsset': u'ENJ', u'id': 182838, u'isBestMatch': True}, {u'orderId': 1837196, u'isBuyer': True, u'price': u'0.00001170', u'isMaker': False, u'qty': u'526.00000000', u'commission': u'0.52600000', u'time': 1514080173457, u'commissionAsset': u'ENJ', u'id': 205698, u'isBestMatch': True}, {u'orderId': 2027676, u'isBuyer': False, u'price': u'0.00001186', u'isMaker': True, u'qty': u'500.00000000', u'commission': u'0.00000593', u'time': 1514628359113, u'commissionAsset': u'BTC', u'id': 272271, u'isBestMatch': True}, {u'orderId': 2091359, u'isBuyer': True, u'price': u'0.00001420', u'isMaker': False, u'qty': u'106.00000000', u'commission': u'0.10600000', u'time': 1514714012470, u'commissionAsset': u'ENJ', u'id': 291257, u'isBestMatch': True}, {u'orderId': 2243594, u'isBuyer': False, u'price': u'0.00001700', u'isMaker': True, u'qty': u'91.00000000', u'commission': u'0.00000155', u'time': 1515046235957, u'commissionAsset': u'BTC', u'id': 355550, u'isBestMatch': True}, {u'orderId': 2316684, u'isBuyer': True, u'price': u'0.00002223', u'isMaker': True, u'qty': u'26.00000000', u'commission': u'0.02600000', u'time': 1515096213466, u'commissionAsset': u'ENJ', u'id': 388364, u'isBestMatch': True}, {u'orderId': 2316684, u'isBuyer': True, u'price': u'0.00002223', u'isMaker': True, u'qty': u'160.00000000', u'commission': u'0.16000000', u'time': 1515096228849, u'commissionAsset': u'ENJ', u'id': 388369, u'isBestMatch': True}]

Plarkass commented 6 years ago

I still have this issue:

price:0.00017451 buyp:0.00017452 sellp:0.00017678-bid:0.00017451 ask:0.00017719 spread:1.54 m: Signature for this request is not valid. price:0.00017451 buyp:0.00017452 sellp:0.00017678-bid:0.00017451 ask:0.00017719 spread:1.54 m: Signature for this request is not valid. price:0.00017451 buyp:0.00017452 sellp:0.00017678-bid:0.00017451 ask:0.00017719 spread:1.54 m: Signature for this request is not valid.

Do you have any suggestion ?

ykartal commented 6 years ago

Could you send your running code? We do not know which method you are calling.

Plarkass commented 6 years ago

I thanks for your reply.

I get price:0.00017451 buyp:0.00017452 sellp:0.00017678-bid:0.00017451 ask:0.00017719 spread:1.54 m: Signature for this request is not valid.

when i do: python trader.py --symbol TNTETH

i can get the same with : python balance.py
1 -) Print orders 2 -) Scan profits 3 -) List balances 4 -) Check balance Enter option number: Ex: 2 1 Enter symbol: Ex: XVGBTC XVGBTC XVGBTC Orders {u'msg': u'Signature for this request is not valid.', u'code': -1022}

I try to reset my API key

Plarkass commented 6 years ago

Hi, for info, I ever try with an another account of a friend and I got same error.

Could you provide all requirements for that is necessary

ykartal commented 6 years ago

Hi, I could not find any time to check about error.

This part(signing code) is working with myTrades endpoint. So maybe we might also check and update the sell/order baseUrl (I only guess but replacing baseUrl by baseURL_v3 may work)

PS: I will send a code commit when take a time to check and fix that issue

melexov commented 6 years ago

i also have the same problem:

price:218.34000000 buyp:217.69000000 sellp:217.68000000-bid:217.68000000 ask:218.35000000 spread:0.31 m: Signature for this request is not valid.

price:218.35000000 buyp:217.71000000 sellp:217.70000000-bid:217.70000000 ask:218.35000000 spread:0.30 m: Signature for this request is not valid.

this error occurred when bot tried to place buy|sell order. already tried hints from sammchardy/python-binance#5 without success.

probably something wrong here:

h = urlencode(data) b = bytearray() b.extend(self.secret.encode()) signature = hmac.new(b, msg=h.encode('utf-8'), digestmod=hashlib.sha256). hexdigest() data.update({"signature": signature}) return data

original binance api

ordered_data = self._order_params(data) query_string = '&'.join(["{}={}".format(d[0], d[1]) for d in ordered_data]) m = hmac.new(self.API_SECRET.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256) return m.hexdigest()

thanks

melexov commented 6 years ago

update

now works fine: https://github.com/yasinkuyu/binance-trader/issues/196#issuecomment-366102278 with the old version or BinanceAPI.py

h = self.secret + "|" + urlencode(data) signature = hashlib.sha256(h.encode('utf-8')).hexdigest() data.update({"signature": signature}) return data

ykartal commented 6 years ago

As I said before, using base_url_v3 is also works, I think v3 api have more endpoints . So I sent a new commit. Please take it and try again. See pull request on https://github.com/yasinkuyu/binance-trader/pull/204

Plarkass commented 6 years ago

Thanks, Test in progress