pylivetrader: Issue during live trading. Cannot order XXXX on as there is no last price for the security

I’m doing a live trading using pylivetrader 0.5.1 (same issue with 0.5.2) and having these issues happen every day:

[2020-10-05 13:31:01.912238] ERROR: builtins: failed closing position with: Cannot order AAPL on 2020-10-05 13:31:00+00:00 as there is no last price for the security.
[2020-10-05 13:31:01.933311] INFO: pipeline_live.data.alpaca.pricing_loader: chart_range=5
/home/ubuntu/.zipline/data/dailycache/alpaca_chart_5: digest mismatch 38d1c082545877db0a880a8c723ec797 != c4a2fe5faf4363334722824e558a6016, reloading
[2020-10-05 13:31:13.953458] DEBUG: pipeline_live.data.sources.util: fetch: 11.18% completed
[2020-10-05 13:31:14.043624] DEBUG: pipeline_live.data.sources.util: fetch: 20.13% completed
[2020-10-05 13:31:19.523271] DEBUG: pipeline_live.data.sources.util: fetch: 31.32% completed
[2020-10-05 13:31:19.733984] DEBUG: pipeline_live.data.sources.util: fetch: 40.27% completed
[2020-10-05 13:31:24.657859] DEBUG: pipeline_live.data.sources.util: fetch: 51.45% completed
[2020-10-05 13:31:28.247525] DEBUG: pipeline_live.data.sources.util: fetch: 60.40% completed
[2020-10-05 13:31:31.176971] DEBUG: pipeline_live.data.sources.util: fetch: 71.58% completed
[2020-10-05 13:31:32.786441] DEBUG: pipeline_live.data.sources.util: fetch: 80.53% completed
[2020-10-05 13:31:36.671318] DEBUG: pipeline_live.data.sources.util: fetch: 91.05% completed
[2020-10-05 13:31:36.959422] DEBUG: pipeline_live.data.sources.util: fetch: 100.00% completed

I don’t see this issue during paper trading. Issue happens every day with different stocks.

My code:

def initialize(context):
    schedule_function(
        my_rebalance,
        date_rules.every_day(),
        time_rules.market_open()
    )
    my_pipe = make_pipeline()
    attach_pipeline(my_pipe, 'my_pipeline')

def make_pipeline():
   return <some_pipeline>

def my_rebalance(context, data):
    for s in context.portfolio.positions:
        try:
            order_target_percent(s, 0)  // HERE issue happen and I think here we detect the difference and loading the data
        except Exception as e:
            log.error(f"failed closing position with: {e}")

    df = pipeline_output('my_pipeline')
    // buy and sell logic works after data download completes

My understanding that the issue happens here: https://github.com/alpacahq/pylivetrader/blob/779e23f8622376f3685e8de2f387446093402add/pylivetrader/algorithm.py#L833

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 34 (27 by maintainers)

Most upvoted comments

Guys, I have merged #204 (from issue #192) onto the master branch. please do test it and let me know if you still have issues with it.