bt-ccxt-store-cn icon indicating copy to clipboard operation
bt-ccxt-store-cn copied to clipboard

样例文件中报错,不知如何解决?

Open chuzheng88 opened this issue 3 years ago • 5 comments

Buy_order 示例文件运行后报错如下:

`HTTPError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch(self, url, method, headers, body) 658 self.logger.debug("%s %s, Response: %s %s %s", method, url, http_status_code, headers, http_response) --> 659 response.raise_for_status() 660

C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self) 952 if http_error_msg: --> 953 raise HTTPError(http_error_msg, response=self) 954

HTTPError: 400 Client Error: Bad Request for url: https://api.binance.com/api/v3/order

During handling of the above exception, another exception occurred:

BadRequest Traceback (most recent call last) C:\Users\ADMINI~1\AppData\Local\Temp\2/ipykernel_5980/3713414783.py in 17 18 # Run the strategy ---> 19 cerebro.run()

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in run(self, **kwargs) 1125 # let's skip process "spawning" 1126 for iterstrat in iterstrats: -> 1127 runstrat = self.runstrategies(iterstrat) 1128 self.runstrats.append(runstrat) 1129 if self._dooptimize:

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in runstrategies(self, iterstrat, predata) 1296 self._runnext_old(runstrats) 1297 else: -> 1298 self._runnext(runstrats) 1299 1300 for strat in runstrats:

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in _runnext(self, runstrats) 1628 self._check_timers(runstrats, dt0, cheat=False) 1629 for strat in runstrats: -> 1630 strat._next() 1631 if self._event_stop: # stop if requested 1632 return

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\strategy.py in _next(self) 345 346 def _next(self): --> 347 super(Strategy, self)._next() 348 349 minperstatus = self._getminperstatus()

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\lineiterator.py in _next(self) 269 minperstatus = self._getminperstatus() 270 if minperstatus < 0: --> 271 self.next() 272 elif minperstatus == 0: 273 self.nextstart() # only called for the 1st value

C:\Users\ADMINI~1\AppData\Local\Temp\2/ipykernel_5980/1888998214.py in next(self) 14 # size x price should be >10 USDT at a minimum at Binance 15 # make sure you use a price that is below the market price if you don't want to actually buy ---> 16 self.order = self.buy(size=10, exectype=Order.Limit, price=35000) 17 # And immediately cancel the buy order 18 self.cancel(self.order);

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\strategy.py in buy(self, data, size, price, plimit, exectype, valid, tradeid, oco, trailamount, trailpercent, parent, transmit, **kwargs) 931 932 if size: --> 933 return self.broker.buy( 934 self, data, 935 size=abs(size), price=price, plimit=plimit,

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtbroker.py in buy(self, owner, data, size, price, plimit, exectype, valid, tradeid, oco, trailamount, trailpercent, **kwargs) 300 del kwargs['parent'] 301 del kwargs['transmit'] --> 302 return self._submit(owner, data, exectype, 'buy', size, price, kwargs) 303 304 def sell(self, owner, data, size, price=None, plimit=None,

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtbroker.py in _submit(self, owner, data, exectype, side, amount, price, params) 287 params = params['params'] if 'params' in params else params 288 params['created'] = created # Add timestamp of order creation for backtesting --> 289 ret_ord = self.store.create_order(symbol=data.p.dataname, order_type=order_type, side=side, amount=amount, price=price, params=params) 290 order = CCXTOrder(owner, data, exectype, side, amount, price, ret_ord) 291 self.open_orders.append(order)

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtstore.py in retry_method(self, *args, **kwargs) 138 time.sleep(self.exchange.rateLimit / 1000) 139 try: --> 140 return method(self, *args, **kwargs) 141 except (NetworkError, ExchangeError): 142 if i == self.retries - 1:

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtstore.py in create_order(self, symbol, order_type, side, amount, price, params) 166 def create_order(self, symbol, order_type, side, amount, price, params): 167 # returns the order --> 168 return self.exchange.create_order(symbol=symbol, type=order_type, side=side, 169 amount=amount, price=price, params=params) 170

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in create_order(self, symbol, type, side, amount, price, params) 2722 params = self.omit(params, 'stopPrice') 2723 request['stopPrice'] = self.price_to_precision(symbol, stopPrice) -> 2724 response = getattr(self, method)(self.extend(request, params)) 2725 return self.parse_order(response, market) 2726

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in inner(_self, params, context) 499 if context is not None: 500 inner_kwargs['context'] = params --> 501 return entry(_self, **inner_kwargs) 502 return inner 503 to_bind = partialer()

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in request(self, path, api, method, params, headers, body, config, context) 4953 4954 def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}): -> 4955 response = self.fetch2(path, api, method, params, headers, body, config, context) 4956 # a workaround for {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."} 4957 if (api == 'private') or (api == 'wapi'):

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch2(self, path, api, method, params, headers, body, config, context) 546 self.lastRestRequestTimestamp = self.milliseconds() 547 request = self.sign(path, api, method, params, headers, body) --> 548 return self.fetch(request['url'], request['method'], request['headers'], request['body']) 549 550 def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}):

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch(self, url, method, headers, body) 673 except HTTPError as e: 674 details = ' '.join([self.id, method, url]) --> 675 skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body) 676 if not skip_further_error_handling: 677 self.handle_http_status_code(http_status_code, http_status_text, url, method, http_response)

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody) 4931 return True 4932 feedback = self.id + ' ' + body -> 4933 self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback) 4934 raise ExchangeError(feedback) 4935 if not success:

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in throw_exactly_matched_exception(self, exact, string, message) 564 def throw_exactly_matched_exception(self, exact, string, message): 565 if string in exact: --> 566 raise exactstring 567 568 def throw_broadly_matched_exception(self, broad, string, message):

BadRequest: binance {"code":-1104,"msg":"Not all sent parameters were read; read '11' parameter(s) but was sent '12'."}

`

chuzheng88 avatar Feb 24 '22 01:02 chuzheng88

请问,该如何解决?

chuzheng88 avatar Feb 24 '22 01:02 chuzheng88

 params['created'] = created 这个注释?

---原始邮件--- 发件人: @.> 发送时间: 2022年2月24日(周四) 上午9:02 收件人: @.>; 抄送: @.***>; 主题: [phonegapX/bt-ccxt-store-cn] 样例文件中报错,不知如何解决? (Issue #3)

Buy_order 示例文件运行后报错如下:

`HTTPError Traceback (most recent call last) C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch(self, url, method, headers, body) 658 self.logger.debug("%s %s, Response: %s %s %s", method, url, http_status_code, headers, http_response) --> 659 response.raise_for_status() 660

C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py in raise_for_status(self) 952 if http_error_msg: --> 953 raise HTTPError(http_error_msg, response=self) 954

HTTPError: 400 Client Error: Bad Request for url: https://api.binance.com/api/v3/order

During handling of the above exception, another exception occurred:

BadRequest Traceback (most recent call last) C:\Users\ADMINI~1\AppData\Local\Temp\2/ipykernel_5980/3713414783.py in 17 18 # Run the strategy ---> 19 cerebro.run()

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in run(self, **kwargs) 1125 # let's skip process "spawning" 1126 for iterstrat in iterstrats: -> 1127 runstrat = self.runstrategies(iterstrat) 1128 self.runstrats.append(runstrat) 1129 if self._dooptimize:

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in runstrategies(self, iterstrat, predata) 1296 self._runnext_old(runstrats) 1297 else: -> 1298 self._runnext(runstrats) 1299 1300 for strat in runstrats:

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\cerebro.py in _runnext(self, runstrats) 1628 self._check_timers(runstrats, dt0, cheat=False) 1629 for strat in runstrats: -> 1630 strat._next() 1631 if self._event_stop: # stop if requested 1632 return

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\strategy.py in _next(self) 345 346 def _next(self): --> 347 super(Strategy, self)._next() 348 349 minperstatus = self._getminperstatus()

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\lineiterator.py in _next(self) 269 minperstatus = self._getminperstatus() 270 if minperstatus < 0: --> 271 self.next() 272 elif minperstatus == 0: 273 self.nextstart() # only called for the 1st value

C:\Users\ADMINI~1\AppData\Local\Temp\2/ipykernel_5980/1888998214.py in next(self) 14 # size x price should be >10 USDT at a minimum at Binance 15 # make sure you use a price that is below the market price if you don't want to actually buy ---> 16 self.order = self.buy(size=10, exectype=Order.Limit, price=35000) 17 # And immediately cancel the buy order 18 self.cancel(self.order);

C:\ProgramData\Anaconda3\lib\site-packages\backtrader-1.9.76.123-py3.9.egg\backtrader\strategy.py in buy(self, data, size, price, plimit, exectype, valid, tradeid, oco, trailamount, trailpercent, parent, transmit, **kwargs) 931 932 if size: --> 933 return self.broker.buy( 934 self, data, 935 size=abs(size), price=price, plimit=plimit,

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtbroker.py in buy(self, owner, data, size, price, plimit, exectype, valid, tradeid, oco, trailamount, trailpercent, **kwargs) 300 del kwargs['parent'] 301 del kwargs['transmit'] --> 302 return self._submit(owner, data, exectype, 'buy', size, price, kwargs) 303 304 def sell(self, owner, data, size, price=None, plimit=None,

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtbroker.py in _submit(self, owner, data, exectype, side, amount, price, params) 287 params = params['params'] if 'params' in params else params 288 params['created'] = created # Add timestamp of order creation for backtesting --> 289 ret_ord = self.store.create_order(symbol=data.p.dataname, order_type=order_type, side=side, amount=amount, price=price, params=params) 290 order = CCXTOrder(owner, data, exectype, side, amount, price, ret_ord) 291 self.open_orders.append(order)

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtstore.py in retry_method(self, *args, **kwargs) 138 time.sleep(self.exchange.rateLimit / 1000) 139 try: --> 140 return method(self, *args, **kwargs) 141 except (NetworkError, ExchangeError): 142 if i == self.retries - 1:

C:\ProgramData\Anaconda3\lib\site-packages\bt_ccxt_store-1.0-py3.9.egg\ccxtbt\ccxtstore.py in create_order(self, symbol, order_type, side, amount, price, params) 166 def create_order(self, symbol, order_type, side, amount, price, params): 167 # returns the order --> 168 return self.exchange.create_order(symbol=symbol, type=order_type, side=side, 169 amount=amount, price=price, params=params) 170

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in create_order(self, symbol, type, side, amount, price, params) 2722 params = self.omit(params, 'stopPrice') 2723 request['stopPrice'] = self.price_to_precision(symbol, stopPrice) -> 2724 response = getattr(self, method)(self.extend(request, params)) 2725 return self.parse_order(response, market) 2726

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in inner(_self, params, context) 499 if context is not None: 500 inner_kwargs['context'] = params --> 501 return entry(_self, **inner_kwargs) 502 return inner 503 to_bind = partialer()

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in request(self, path, api, method, params, headers, body, config, context) 4953 4954 def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}): -> 4955 response = self.fetch2(path, api, method, params, headers, body, config, context) 4956 # a workaround for {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."} 4957 if (api == 'private') or (api == 'wapi'):

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch2(self, path, api, method, params, headers, body, config, context) 546 self.lastRestRequestTimestamp = self.milliseconds() 547 request = self.sign(path, api, method, params, headers, body) --> 548 return self.fetch(request['url'], request['method'], request['headers'], request['body']) 549 550 def request(self, path, api='public', method='GET', params={}, headers=None, body=None, config={}, context={}):

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in fetch(self, url, method, headers, body) 673 except HTTPError as e: 674 details = ' '.join([self.id, method, url]) --> 675 skip_further_error_handling = self.handle_errors(http_status_code, http_status_text, url, method, headers, http_response, json_response, request_headers, request_body) 676 if not skip_further_error_handling: 677 self.handle_http_status_code(http_status_code, http_status_text, url, method, http_response)

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\binance.py in handle_errors(self, code, reason, url, method, headers, body, response, requestHeaders, requestBody) 4931 return True 4932 feedback = self.id + ' ' + body -> 4933 self.throw_exactly_matched_exception(self.exceptions['exact'], error, feedback) 4934 raise ExchangeError(feedback) 4935 if not success:

C:\ProgramData\Anaconda3\lib\site-packages\ccxt\base\exchange.py in throw_exactly_matched_exception(self, exact, string, message) 564 def throw_exactly_matched_exception(self, exact, string, message): 565 if string in exact: --> 566 raise exactstring 567 568 def throw_broadly_matched_exception(self, broad, string, message):

BadRequest: binance {"code":-1104,"msg":"Not all sent parameters were read; read '11' parameter(s) but was sent '12'."}

`

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>

phonegapX avatar Feb 24 '22 02:02 phonegapX

非常感谢,create order 成功,但是cancel order的时候又出现error了,如下: image

报错如下: image

感谢大佬之前的回复。

chuzheng88 avatar Feb 26 '22 03:02 chuzheng88

这个应该是字段名称不同造成的

---原始邮件--- 发件人: @.> 发送时间: 2022年2月26日(周六) 中午11:25 收件人: @.>; 抄送: @.@.>; 主题: Re: [phonegapX/bt-ccxt-store-cn] 样例文件中报错,不知如何解决? (Issue #3)

非常感谢,create order 成功,但是cancel order的时候又出现error了,如下:

报错如下:

感谢大佬之前的回复。

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

phonegapX avatar Feb 27 '22 02:02 phonegapX

这个应该是字段名称不同造成的

这个情况从哪里开始排查比较好?

另外,我想在每次启动的时候可以通过getposition获得货币的已有数量,但是每次getposition的时候都是0。感觉这一点很奇怪,下面这两种方式 ,获取到的position都是0

image

image

chuzheng88 avatar Mar 01 '22 01:03 chuzheng88