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

Alpaca-trade-api 1.x #171

Open
jrhone opened this issue Jun 21, 2021 · 14 comments
Open

Alpaca-trade-api 1.x #171

jrhone opened this issue Jun 21, 2021 · 14 comments

Comments

@jrhone
Copy link

jrhone commented Jun 21, 2021

Is upgrading to alpaca-trade-api >= 1.0 planned in the near future?

Lots of recent updates there around websockets and V2 data that would be great to use.

@camelpac
Copy link
Contributor

camelpac commented Jun 22, 2021

Hi,
an updated version was released last week: 0.14.0

@ohheytherewow
Copy link

@camelpac unfortunately the update doesn't replace v1.0, as it doesn't permit subscription to multiple symbols. is there a workaround for that?

@camelpac
Copy link
Contributor

camelpac commented Jun 23, 2021

not yet. follow the alpaca-proxy-agent project for updates.

@ohheytherewow
Copy link

not yet. follow the alpaca-proxy-agent project for updates.

@camelpac great, thanks for the reply!

@ohheytherewow
Copy link

@camelpac any chance this will be updated soon? I'd happily subscribe to the data API if this were supported, but it doesn't make sense if i can only subscribe to one ticker symbol.

@camelpac
Copy link
Contributor

not yet. it's in the backlog

@jrhone
Copy link
Author

jrhone commented Aug 6, 2021

This update was not done properly by the way, alpaca-trade-api 1.x is not integrated well and even the basic examples provided in the repo are not working.

Given all these issues it seems you decided to make another release with only the alpaca-trade-api version bumped but none of the issues fixed!

Can we get an ETA on when this will be resolved?
Shouldn't it be high priority when your examples are broken for almost two months?

@camelpac
Copy link
Contributor

Hi @jrhone
The alpaca-proxy-agent was just updated to the data v2 stream. You can now use it to subscribe to multiple symbols.

What other issue to you face? please point me to specific examples.

@mkaicher
Copy link

I am having issues testing minute granularity on >= 0.14.0. For example, when testing the README.md example modified for minute granularity:

data0 = DataFactory(dataname='AAPL', historical=True, fromdate=datetime(
2021, 7, 21, 13, 30), todate=datetime(2021, 7, 21, 20, 0), timeframe=bt.TimeFrame.Minutes)

I'm only getting results between UTC 13:30 and 16:00. This occurs when testing one or multiple sessions. I've also tried substituting NYC and my local timezones without success. There's clearly something amiss with timezones in >=0.14.0. The above works perfectly on <=0.13.1.

NOTE: Regardless of version, I've had to apply the trading_calendars fix mentioned in issue #176. Modifying calendar_helpers in trading-calendars works but throws a FutureWarning. Substituting exchange_calendars works with no warning.

@jrhone
Copy link
Author

jrhone commented Aug 12, 2021

Hi @camelpac , there are errors when trying to run the examples in the sample folder and the README.

Please see the two issues below which specify the sample code, error stacktraces and library versions used.

#172
#173

I think it would make sense to go through all the examples in the samples folder and verify they work.
They should be tested with all the variations of the config args because some combos work while others do not.

You have 3 options:
 - backtest (IS_BACKTEST=True, IS_LIVE=False)
 - paper trade (IS_BACKTEST=False, IS_LIVE=False)
 - live trade (IS_BACKTEST=False, IS_LIVE=True)

@ohheytherewow
Copy link

Hi @camelpac,

i am still unable to run my backtrader code with the updated proxy / backtrader-api code using the latest trading api. i see log of attempted connections in the proxy, but all data subscriptions fail.

these are strategies that worked fine using the earlier backtrader-api and v1 data. any hope this code might be updated sometime soon?

@brianhumphreys
Copy link

@camelpac thanks for this work you've done thus far. I am excited to see where it will go in the future.

To add to the other commenters' requests, I am having issues with the sample code when running strategy_sma_crossover.py. I get the following error:

Traceback (most recent call last):
  File "strategy_sma_crossover.py", line 118, in <module>
    cerebro.run()
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1127, in run
    runstrat = self.runstrategies(iterstrat)
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/backtrader/cerebro.py", line 1187, in runstrategies
    self._broker.start()
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/alpaca_backtrader_api/alpacabroker.py", line 103, in start
    self.positions = self.update_positions()
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/alpaca_backtrader_api/alpacabroker.py", line 83, in update_positions
    broker_positions_symbols = [p.symbol for p in broker_positions]
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/alpaca_backtrader_api/alpacabroker.py", line 83, in <listcomp>
    broker_positions_symbols = [p.symbol for p in broker_positions]
  File "/Users/brianhumphreys/.pyenv/versions/3.7.3/lib/python3.7/site-packages/alpaca_trade_api/entity.py", line 29, in __getattr__
    return super().__getattribute__(key)
AttributeError: 'Position' object has no attribute 'symbol'

With the following dependencies:

alpaca-backtrader-api==0.14.1
alpaca-trade-api==1.2.3
backtrader==1.9.76.123
trading-calendars==2.1.1

I'll see if I can do some investigative work on this to help out

@mitchweaver
Copy link

can confirm the above is still an issue

@brianhumphreys
Copy link

Quick update: I solved this issue by realizing that my key and secret set in my env file were not registering because the sample code was explicitly passing in the key and secret into the AlpacaStore constructor. The issue was that I had not set the variables with my key and secret.

# Your credentials here
ALPACA_API_KEY = "<key_id>"
ALPACA_SECRET_KEY = "<secret_key>"

Once setting these it worked. I believe this was happening because the endpoint was sending back a 401 status and the backtrader was not catching properly and trying to cast the 40 response into a Position object.... hints AttributeError: 'Position' object has no attribute 'symbol'

I think there might have been another issue that I worked through but it's been too long.

A potential improvement here would be handling 401s from the authentication endpoint better. The error message is not clear.

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

6 participants