Skip to content

Commit 848b1b8

Browse files
authored
V2.1.8 (#59)
* update pypi * tweaked news
1 parent 0ce0cd2 commit 848b1b8

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/py_alpaca_api/stock/predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def get_losers_to_gainers(
111111
)
112112
if is_gainer:
113113
future_gainers.append(gainer)
114-
print(f"Predicted [bold]{len(future_gainers)}[/bold] future gainers.")
114+
print(f"Predicted {len(future_gainers)} future gainers.")
115115
return future_gainers
116116

117117
@staticmethod

src/py_alpaca_api/trading/news.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import textwrap
44
import time
5+
import math
56
from typing import Dict, List
67
import pendulum
78
from bs4 import BeautifulSoup as bs
@@ -120,18 +121,10 @@ def get_news(self, symbol: str, limit: int = 6) -> List[Dict[str, str]]:
120121
"""
121122
benzinga_news = self._get_benzinga_news(symbol=symbol, limit=limit)
122123
yahoo_news = self._get_yahoo_news(
123-
symbol=symbol, limit=(limit - len(benzinga_news[:3]))
124+
symbol=symbol, limit=(limit - len(benzinga_news[: (math.floor(limit / 2))]))
124125
)
125126

126-
news = benzinga_news[:3] + yahoo_news[: (limit - len(benzinga_news[:3]))]
127-
128-
# if len(benzinga_news) == 0:
129-
# news = yahoo_news
130-
# else:
131-
# news = benzinga_news[:3]
132-
# news.append(yahoo_news[:(limit - len(benzinga_news))])
133-
134-
# news = yahoo_news + benzinga_news
127+
news = benzinga_news[: (math.floor(limit / 2))] + yahoo_news
135128

136129
sorted_news = sorted(
137130
news, key=lambda x: pendulum.parse(x["publish_date"]), reverse=True
@@ -155,10 +148,13 @@ def _get_yahoo_news(self, symbol: str, limit: int = 6) -> List[Dict[str, str]]:
155148
news_response = ticker.news
156149

157150
yahoo_news = []
158-
for news in news_response[:limit]:
151+
news_count = 0
152+
for news in news_response:
159153
try:
160154
content = self.strip_html(self.scrape_article(news["link"]))
161-
155+
if not content:
156+
continue
157+
news_count += 1
162158
yahoo_news.append(
163159
{
164160
"title": news["title"],
@@ -174,6 +170,10 @@ def _get_yahoo_news(self, symbol: str, limit: int = 6) -> List[Dict[str, str]]:
174170
except Exception as e:
175171
logging.error(f"Error scraping article: {e}")
176172
continue
173+
else:
174+
if news_count == limit:
175+
news_count = 0
176+
break
177177

178178
return yahoo_news
179179

tests/test_trading/test_account2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def test_get_portfolio_history(alpaca):
8989
assert history.profit_loss.dtype == float
9090
assert history.profit_loss_pct.dtype == float
9191
assert history.base_value.dtype == float
92-
assert history.equity.iloc[-1] == alpaca.trading.account.get().equity
9392

9493

9594
def test_portfolio_history(alpaca):

0 commit comments

Comments
 (0)