pylivetrader: Maximum bars error in latest version

I’m requesting 1d history for 200d, and it’s throwing an error now, after updating to 0.3.0. No code changes and downgrading back to 0.2.0 fixes it. Though the error could be in the alpaca-trade-api library, the version of that didn’t change it seems. I can reopen there if it is.

The call:

self._ohlc_daily = self._data.history(
        self.security,
        ['open', 'close', 'high', 'low'],
        200,
        '1d') \
    .dropna()

Logs:

[2020-05-18 08:59:52.356279] DEBUG: reversion: sell_queue restored: {'TDOC': Asset(d2eb2ae7-fb5e-47d8-a0bf-ff77f0f47f94, symbol=TDOC, asset_name=TDOC, exchange=NYSE)}
[2020-05-18 08:59:52.357221] INFO: reversion: Creating pipeline
[2020-05-18 08:59:52.375289] DEBUG: reversion: Running before trading starts
[2020-05-18 08:59:53.145132] INFO: pipeline_live.data.alpaca.pricing_loader: chart_range=74
[2020-05-18 09:00:08.771244] INFO: pipeline_live.data.alpaca.pricing_loader: chart_range=221
[2020-05-18 09:00:26.039294] INFO: pipeline_live.data.alpaca.pricing_loader: chart_range=18
[2020-05-18 09:00:47.496312] DEBUG: reversion: Number of candidates to prepare: 87
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/alpaca_trade_api/rest.py", line 136, in _one_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: https://data.alpaca.markets/v1/bars/minute?symbols=AAWW&limit=1001&start=2020-05-16&end=2020-05-18
reversion_1  |
During handling of the above exception, another exception occurred:
reversion_1  |
Traceback (most recent call last):
  File "/usr/local/bin/pylivetrader", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/__main__.py", line 222, in run
    algorithm.run(retry=ctx.retry)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/algorithm.py", line 275, in run
    return self.executor.run(retry=retry)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/executor/executor.py", line 119, in run
    algo.before_trading_start(self.current_data)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/algorithm.py", line 248, in before_trading_start
    self._before_trading_start(self, data)
  File "reversion.py", line 291, in before_trading_start
    prepare_candidates(context, data)
  File "reversion.py", line 325, in prepare_candidates
    indicators = Indicators(security, data)
  File "reversion.py", line 94, in __init__
    super().__init__(security, data)
  File "/opt/algo/algo/indicator.py", line 32, in __init__
    self.get_data()
  File "/opt/algo/algo/indicator.py", line 43, in get_data
    '1d') \
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/data/bardata.py", line 163, in history
    )[assets] for field in fields
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/data/bardata.py", line 163, in <dictcomp>
    )[assets] for field in fields
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/data/data_portal.py", line 86, in get_history_window
    end_dt=end_dt).swaplevel(
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/data/data_portal.py", line 62, in _get_realtime_bars
    assets, frequency, bar_count=bar_count)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/backend/alpaca.py", line 505, in get_bars
    symbols, 'minute', limit=1000)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/backend/alpaca.py", line 631, in _symbol_bars
    return parallelize(fetch)(symbols)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/misc/parallel_utils.py", line 39, in wrapper
    task_result = task.result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 425, in result
    return self.__get_result()
  File "/usr/local/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/backend/alpaca.py", line 82, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/pylivetrader/backend/alpaca.py", line 595, in fetch
    limit=limit+1).df[symbol]
  File "/usr/local/lib/python3.6/site-packages/alpaca_trade_api/rest.py", line 359, in get_barset
    resp = self.data_get('/bars/{}'.format(timeframe), params)
  File "/usr/local/lib/python3.6/site-packages/alpaca_trade_api/rest.py", line 166, in data_get
    'GET', path, data, base_url=base_url, api_version='v1'
  File "/usr/local/lib/python3.6/site-packages/alpaca_trade_api/rest.py", line 115, in _request
    return self._one_request(method, url, opts, retry)
  File "/usr/local/lib/python3.6/site-packages/alpaca_trade_api/rest.py", line 144, in _one_request
    raise APIError(error, http_error)
alpaca_trade_api.rest.APIError: maximum 1000 bars per symbol per request

Library versions:

"alpaca-trade-api": {
    "hashes": [	
        "sha256:60e42308bbfce7f7cd227b5e0dc5c371c783faa3dd58173ea4800d6031201570",
        "sha256:9f3f8a1f678b19754ae70ba61be98e9226e7c72b5a9e6645480555c78228189a"
        ],
    "version": "==0.48"
},

"pylivetrader": {
    "hashes": [
        "sha256:8d6039132818d01728ca3696935410e9218f8f0fdce1106ffa29e6efef733471",
        "sha256:96a128528d34763acbc30f142919c0f60f8491514e74c5773f748f43cb80486e"
    ],
    "version": "==0.3.0"
},

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

@jmaslek install it like this: pip install -U git+https://github.com/alpacahq/pylivetrader/