diff --git a/.circleci/config.yml b/.circleci/config.yml index aee006e..a1474c5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -21,7 +21,9 @@ jobs: - run: command: | . venv/bin/activate - python3 setup.py flake8 test + pip install -r requirements/requirements_test.txt + flake8 ./pylivetrader && echo "Flake8 passed" + pytest build-python37: docker: @@ -43,10 +45,12 @@ jobs: - run: command: | . venv/bin/activate - python3 setup.py flake8 test + pip install -r requirements/requirements_test.txt + flake8 ./pylivetrader && echo "Flake8 passed" + pytest workflows: version: 2 build: jobs: - - build-python36 \ No newline at end of file + - build-python36 diff --git a/pylivetrader/_version.py b/pylivetrader/_version.py index 1f345e7..09b25bb 100644 --- a/pylivetrader/_version.py +++ b/pylivetrader/_version.py @@ -13,4 +13,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -VERSION = '0.6.0' +VERSION = '0.7.0' diff --git a/pylivetrader/backend/alpaca.py b/pylivetrader/backend/alpaca.py index 1fb1b96..b63698f 100644 --- a/pylivetrader/backend/alpaca.py +++ b/pylivetrader/backend/alpaca.py @@ -446,7 +446,7 @@ def cancel_order(self, zp_order_id): return def get_last_traded_dt(self, asset): - trade = self._api.get_last_trade(asset.symbol) + trade = self._api.get_latest_trade(asset.symbol) return trade.timestamp def get_spot_value( @@ -496,7 +496,7 @@ def _get_symbols_last_trade_value(self, symbols): @skip_http_error((404, 504)) def fetch(symbol): - return self._api.get_last_trade(symbol) + return self._api.get_latest_trade(symbol) return parallelize(fetch)(symbols) @@ -645,25 +645,25 @@ def wrapper(): _from = params['_from'] to = params['to'] size = params['size'] - df = self._api.get_barset(symbols, - size, - limit=params['limit'], - start=_from.isoformat(), - end=to.isoformat()).df[symbols] - - if df.empty: - # we got an empty response. We will try to use the updated - # V2 api to get the data. we cannot do 1 api call for all - # symbols so we will iterate them - r = {} - for sym in symbols: - r[sym] = self._api.get_bars(sym, TimeFrame.Minute, - _from.isoformat(), - to.isoformat(), - adjustment='raw').df - df = pd.concat(r, axis=1) - # data is received in UTC tz but without tz (naive) - df.index = df.index.tz_localize("UTC") + + timeframe = TimeFrame.Minute if size == "minute" else TimeFrame.Day + + # Using V2 api to get the data. we cannot do 1 api call for all + # symbols because the v1 `limit` was per symbol, where v2 it's for + # overall response size; so we will iterate over each symbol with + # the limit for each to replicate that behaviour + r = {} + for sym in symbols: + r[sym] = self._api.get_bars(sym, + limit=params['limit'], + timeframe=timeframe, + start=_from.isoformat(), + end=to.isoformat(), + adjustment='raw').df + df = pd.concat(r, axis=1) + # data is received in UTC tz but without tz (naive) + df.index = df.index.tz_localize("UTC") + if size == 'minute': df.index += pd.Timedelta('1min') diff --git a/requirements/requirements.txt b/requirements/requirements.txt index f165e8c..1f16d85 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -10,6 +10,6 @@ trading_calendars>=1.11 click==8.0.1 PyYAML>=5, <6 ipython>=7 -alpaca-trade-api>=1.2.2 +alpaca-trade-api==1.5.0 pandas>=0.18.1, <=0.22.0 # pyup: ignore # limit to work properly with zipline 1.3.0 pandas-datareader<=0.8.1 # pyup: ignore # higher requires pandas>=0.23, zipline limits to 0.22 diff --git a/requirements/requirements_test.txt b/requirements/requirements_test.txt index adc14e3..2872acf 100644 --- a/requirements/requirements_test.txt +++ b/requirements/requirements_test.txt @@ -1,2 +1,3 @@ pytest>=5.0.0 -pytest-cov \ No newline at end of file +pytest-cov +flake8