-
Notifications
You must be signed in to change notification settings - Fork 347
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
AttributeError: 'REST' object has no attribute 'get_news' #4
Comments
Not sure if OP is active here: if anyone faces this issue, use this method to get news from Alpaca (include it in the MLTrader class defined in this project:
|
THe problem with is is that it will not return data from the right date but jsut the latest news |
I'm doing a variation on this (
Example: import datetime
from alpaca.data import requests
from alpaca.data.historical import news
news_client = news.NewsClient(api_key=API_KEY, secret_key=API_SECRET)
end = datetime.datetime.now().date()
start = end - datetime.timedelta(days=3)
req = requests.NewsRequest(
symbols='AAPL',
start=str(start),
end=str(end),
)
while True:
news_set = news_client.get_news(req)
for news in news_set.news:
headline = news.headline
...
else:
# Pagination
if news_set.next_page_token:
req.page_token = news_set.next_page_token
continue
break |
I have the same issue. Sorry, I didn't understand in what place exactly I need to paste it (I stupidly pasted it in a class and it did nothing) Can you please explain how to use this function? |
@S0ft1c This is the function for get_alpaca_news() I use in the class as a member function: def get_alpaca_news(self,today, three_days_prior):
newsRequest = NewsRequest(
symbols=self.symbol,
start=three_days_prior,
end=today,
limit=20
)
news = self.newsClient.get_news(newsRequest)
headlines = []
summaries = []
for news_item in news.news:
headlines.append(news_item.headline)
summaries.append(news_item.summary)
return headlines You also need to change the function call in the get_sentiment() function def get_sentiment(self):
today, three_days_prior = self.get_dates()
news = self.get_alpaca_news(today, three_days_prior)
probability, sentiment = estimate_sentiment(news)
return probability, sentiment And in the initialise function you need to add the news client as a class variable def initialize(self, symbol: str = "SPY", cash_at_risk: float = .5):
self.symbol = symbol
self.sleeptime = "24H"
self.last_trade = None
self.cash_at_risk = cash_at_risk
self.newsClient = NewsClient(ALPACA_CREDS["API_KEY"],ALPACA_CREDS["API_SECRET"]) If you need more help let me know |
Thanks a lot! It works! |
I don't see a
get_news
method exposed under REST even in the Alpaca Trade API documentation. I'm appalled it worked in this project. Anyone else facing this?The text was updated successfully, but these errors were encountered: