Skip to content

Commit

Permalink
Delete code associated with popularity endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
omikader committed Aug 17, 2020
1 parent 7d2a384 commit f3d4455
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 114 deletions.
2 changes: 1 addition & 1 deletion aiorobinhood/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.0.0"
__version__ = "2.0.0"
__all__ = [
"RobinhoodClient",
# exceptions
Expand Down
47 changes: 0 additions & 47 deletions aiorobinhood/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,53 +640,6 @@ async def get_instruments(

return results

@check_tokens
@check_session
async def get_popularity(
self, ids: Iterable[str], pages: Optional[int] = None
) -> List[Dict[str, Any]]:
"""Fetch the popularity information pertaining to a list of securities.
Args:
ids: A sequence of instrument IDs.
pages: The number of pages to fetch (default is unlimited).
Returns:
Popularity data for each security, including number of open positions
held on Robinhood.
Raises:
ClientAPIError: Robinhood server responded with an error.
ClientRequestError: The HTTP request timed out or failed.
ClientUnauthenticatedError: The :class:`~.RobinhoodClient` is not logged in.
ClientUninitializedError: The :class:`~.RobinhoodClient` is not initialized.
"""
assert self._session is not None

results = []
url = urls.POPULARITY.with_query({"ids": ",".join(ids)})

while url is not None and (pages is None or pages > 0):
try:
async with self._session.get(
url,
timeout=self._timeout,
headers={"Authorization": self._access_token},
) as resp:
response = await resp.json()
if resp.status != 200:
raise ClientAPIError(
resp.method, resp.url, resp.status, response
)

results += response["results"]
url = response["next"]
pages = pages and pages - 1
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
raise ClientRequestError("GET", url) from e

return results

@mutually_exclusive("symbols", "instruments")
@check_tokens
@check_session
Expand Down
1 change: 0 additions & 1 deletion aiorobinhood/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# Stocks
FUNDAMENTALS = BASE / "fundamentals/"
INSTRUMENTS = BASE / "instruments/"
POPULARITY = INSTRUMENTS / "popularity/"
QUOTES = BASE / "quotes/"
HISTORICALS = QUOTES / "historicals/"
MIDLANDS = BASE / "midlands/"
Expand Down
1 change: 0 additions & 1 deletion docs/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ Stocks

.. automethod:: RobinhoodClient.get_fundamentals
.. automethod:: RobinhoodClient.get_instruments
.. automethod:: RobinhoodClient.get_popularity
.. automethod:: RobinhoodClient.get_quotes
.. automethod:: RobinhoodClient.get_historical_quotes
.. automethod:: RobinhoodClient.get_tags
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def get_long_description() -> str:
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
license="MIT",
keywords=["robinhood", "asyncio", "python3", "stocks"],
Expand Down
64 changes: 0 additions & 64 deletions tests/test_stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
FUNDAMENTALS,
HISTORICALS,
INSTRUMENTS,
POPULARITY,
QUOTES,
RATINGS,
TAGS,
Expand Down Expand Up @@ -152,69 +151,6 @@ async def test_get_instruments_value_error(logged_in_client):
await client.get_instruments(symbol="ABCD", ids=["12345"])


@pytest.mark.asyncio
async def test_get_popularity(logged_in_client):
client, server = logged_in_client
task = asyncio.create_task(client.get_popularity(ids=["12345", "67890"]))

request = await server.receive_request(timeout=pytest.TIMEOUT)
assert request.method == "GET"
assert request.headers["Authorization"] == f"Bearer {pytest.ACCESS_TOKEN}"
assert request.path == POPULARITY.path
assert request.query["ids"] == "12345,67890"
server.send_response(
request,
content_type="application/json",
text=json.dumps({"next": str(pytest.NEXT), "results": [{"foo": "bar"}]}),
)

request = await server.receive_request(timeout=pytest.TIMEOUT)
assert request.method == "GET"
assert request.headers["Authorization"] == f"Bearer {pytest.ACCESS_TOKEN}"
assert request.path == pytest.NEXT.path
server.send_response(
request,
content_type="application/json",
text=json.dumps({"next": None, "results": [{"baz": "quux"}]}),
)

result = await asyncio.wait_for(task, pytest.TIMEOUT)
assert result == [{"foo": "bar"}, {"baz": "quux"}]


@pytest.mark.asyncio
async def test_get_popularity_api_error(logged_in_client):
client, server = logged_in_client
task = asyncio.create_task(client.get_popularity(ids=["12345"]))

request = await server.receive_request(timeout=pytest.TIMEOUT)
assert request.method == "GET"
assert request.headers["Authorization"] == f"Bearer {pytest.ACCESS_TOKEN}"
assert request.path == POPULARITY.path
assert request.query["ids"] == "12345"
server.send_response(request, status=400, content_type="application/json")

with pytest.raises(ClientAPIError):
await task


@pytest.mark.asyncio
async def test_get_popularity_timeout_error(logged_in_client):
client, server = logged_in_client
task = asyncio.create_task(client.get_popularity(ids=["12345"]))

request = await server.receive_request(timeout=pytest.TIMEOUT)
assert request.method == "GET"
assert request.headers["Authorization"] == f"Bearer {pytest.ACCESS_TOKEN}"
assert request.path == POPULARITY.path
assert request.query["ids"] == "12345"

with pytest.raises(ClientRequestError) as exc_info:
await asyncio.sleep(pytest.TIMEOUT + 1)
await task
assert isinstance(exc_info.value.__cause__, asyncio.TimeoutError)


@pytest.mark.asyncio
async def test_get_quotes(logged_in_client):
client, server = logged_in_client
Expand Down

0 comments on commit f3d4455

Please sign in to comment.