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

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

Open
chuzheng88 opened this issue Feb 24, 2022 · 5 comments
Open

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

chuzheng88 opened this issue Feb 24, 2022 · 5 comments

Comments

@chuzheng88
Copy link

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
Copy link
Author

请问,该如何解决?

@phonegapX
Copy link
Owner

phonegapX commented Feb 24, 2022 via email

@chuzheng88
Copy link
Author

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

报错如下:
image

感谢大佬之前的回复。

@phonegapX
Copy link
Owner

phonegapX commented Feb 27, 2022 via email

@chuzheng88
Copy link
Author

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

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

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

image

image

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