Howdy, first time using the forum, lack of documentation brought me here. I’ve been trying to use the get_barset method, it ends up in giving me an error that reads
404 Client Error: Not Found for url: https://data.alpaca.markets/v2/bars/1Min?symbols=AAPL&limit=1
For some reason it is adding my request to the end of my link? I genuinely do not understand how. Here’s my code below.
import alpaca_trade_api_fixed as tradeapi
api_key = ‘I put my key here’
api_secret = ‘I put my private key’
base_url = ‘https://paper-api.alpaca.markets’
api = tradeapi.REST(api_key, api_secret, base_url, api_version=‘v2’)
account = api.get_account()
print(account)
barset = api.get_barset(‘AAPL’, ‘1Min’, limit=1)
bars = barset[‘AAPL’]
print(bars)
Any help would be greatly appreciated, thank you.
@Lord_Ingram Try this
`import alpaca_trade_api as tradeapi`
Then, don’t use get_barset (that is old) do this instead
`barset = api.get_bars('AAPL', '1Min', limit=1)`
That should work for you.
I swapped out
import alpaca_trade_api_fixed as tradeapi
with
import alpaca_trade_api as tradeapi
It’s red in the code, when running it gives ModuleNotFoundError: No module named 'alpaca_trade_api'
Secondly, I swapped out the get_barset with get_bars, it ended up giving a AttributeError: 'REST' object has no attribute 'get_bars'. Did you mean: 'get_barset'?
I am utterly stumped on this.
@Lord_Ingram You will need to install the package alpaca_trade_api
. Don’t install alpaca_trade_api_fixed
(which you may have done), The alpaca_trade_api_fixed
package is an old version. Then it should work.
!pip install -q alpaca_trade_api
import alpaca_trade_api as tradeapi
ALPACA_API_KEY_ID_PAPER = 'xxxxxxx'
ALPACA_API_SECRET_KEY_PAPER = 'xxxxxxx'
ALPACA_API_BASE_URL_PAPER = 'https://paper-api.alpaca.markets'
api_paper = alpacaapi.REST(ALPACA_API_KEY_ID_PAPER,
ALPACA_API_SECRET_KEY_PAPER,
ALPACA_API_ENDPOINT_PAPER)
barset = api.get_bars('AAPL', '1Min', limit=1)
The github repository for the alpaca_trade_api
SDK is here and has a bit of examples and documentation.
Is there a place to find better documentation? I’ve been scouring online sources and no dice. I uninstalled alpaca_trade_api_fixed and installed alpaca_trade_api. I’m still receiving the error “AttributeError: module ‘alpaca_trade_api’ has no attribute 'get_bars”
Here’s the code I tried
import alpaca_trade_api as tradeapi
ALPACA_API_KEY_ID_PAPER = ‘xxxxx’
ALPACA_API_SECRET_KEY_ID_PAPER = ‘xxxxx’
ALPACA_API_ENDPOINT_PAPER = ‘https://paper-api.alpaca.markets’
api_paper = tradeapi.REST(ALPACA_API_KEY_ID_PAPER,
ALPACA_API_SECRET_KEY_ID_PAPER,
ALPACA_API_ENDPOINT_PAPER)
barset = tradeapi.get_bars(‘AAPL’, ‘1Min’, limit=1)
I just want to view AAPL’s performance over the last minute. Will issues such as these be prevalent if I continue using this API?
@Lord_Ingram I believe the problem is this line of code
barset = tradeapi.get_bars(‘AAPL’, ‘1Min’, limit=1)
That should be
barset = api_paper.get_bars(‘AAPL’, ‘1Min’, limit=1)
Try that.
That worked! Thank you so very much. If I may ask, where can I find documentation if need be?