Skip to content

Commit

Permalink
Merge pull request #102 from alpacahq/handle-empty-data
Browse files Browse the repository at this point in the history
Handle empty bardata and update pipeline-live version
  • Loading branch information
ttt733 authored May 15, 2019
2 parents c73cbd0 + ce43613 commit d07da83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dockerfiles/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pypi"
numpy = ">1.16"
alpaca-trade-api = "==0.28"
pylivetrader = "==0.0.29"
pipeline-live = "==0.1.4"
pipeline-live = "==0.1.5"
ta-lib = "==0.4.17"

[dev-packages]
Expand Down
11 changes: 6 additions & 5 deletions pylivetrader/backend/alpaca.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,12 @@ def fetch(symbol):
if size == 'minute':
df.index += pd.Timedelta('1min')

# mask out bars outside market hours
mask = self._cal.minutes_in_range(
df.index[0], df.index[-1],
).tz_convert(NY)
df = df.reindex(mask)
if not df.empty:
# mask out bars outside market hours
mask = self._cal.minutes_in_range(
df.index[0], df.index[-1],
).tz_convert(NY)
df = df.reindex(mask)

if limit is not None:
df = df.iloc[-limit:]
Expand Down
3 changes: 3 additions & 0 deletions pylivetrader/data/bardata.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def fetch(asset, field):

def history(self, assets, fields, bar_count, frequency):

if not (assets and fields):
return None

if isinstance(fields, str):
single_asset = isinstance(assets, Asset)

Expand Down

0 comments on commit d07da83

Please sign in to comment.