Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion massive/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ def _get_params(
# using ., and not _ (removesuffix would work)
# but that is python 3.9+
argname = argname[: -len(f"_{ext}")] + f".{ext}"
if argname.endswith("any_of"):
# any_of accepts a comma-separated str (per the spec) or a
# list of values; only join the latter, since joining a str
# would split it into single characters
if argname.endswith("any_of") and not isinstance(val, str):
Comment thread
justinpolygon marked this conversation as resolved.
val = ",".join(val)
params[argname] = val

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"results": [
{
"id": "E1e778b36bcedb4d1589a970be52c16294ad4bc89c8627d56a3b970f6cf2a6e10",
"ticker": "AAPL",
"record_date": "2026-08-10",
"pay_date": "2026-08-13",
"declaration_date": "2026-07-30",
"ex_dividend_date": "2026-08-10",
"frequency": 4,
"cash_amount": 0.27,
"currency": "USD",
"distribution_type": "recurring",
"historical_adjustment_factor": 0.999138,
"split_adjusted_cash_amount": 0.27
},
{
"id": "Ebff20941049b81e8d1cc80d5ef0cf7b9e44318993597f922292327578e468954",
"ticker": "VZ",
"record_date": "2026-10-09",
"pay_date": "2026-11-02",
"declaration_date": "2026-09-09",
"ex_dividend_date": "2026-10-09",
"frequency": 4,
"cash_amount": 0.7075,
"currency": "USD",
"distribution_type": "recurring",
"historical_adjustment_factor": 0.984736,
"split_adjusted_cash_amount": 0.7075
}
],
"status": "OK",
"request_id": "6a7e466379af0a71039d60cc78e72282"
}
42 changes: 41 additions & 1 deletion test_rest/test_dividends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from massive.rest.models import Dividend
from massive.rest.models import Dividend, StockDividend
from base import BaseTest


Expand Down Expand Up @@ -108,3 +108,43 @@ def test_list_dividends(self):
),
]
self.assertEqual(dividends, expected)

def test_list_stocks_dividends_ticker_any_of(self):
expected = [
StockDividend(
cash_amount=0.27,
currency="USD",
declaration_date="2026-07-30",
distribution_type="recurring",
ex_dividend_date="2026-08-10",
frequency=4,
historical_adjustment_factor=0.999138,
id="E1e778b36bcedb4d1589a970be52c16294ad4bc89c8627d56a3b970f6cf2a6e10",
pay_date="2026-08-13",
record_date="2026-08-10",
split_adjusted_cash_amount=0.27,
ticker="AAPL",
),
StockDividend(
cash_amount=0.7075,
currency="USD",
declaration_date="2026-09-09",
distribution_type="recurring",
ex_dividend_date="2026-10-09",
frequency=4,
historical_adjustment_factor=0.984736,
id="Ebff20941049b81e8d1cc80d5ef0cf7b9e44318993597f922292327578e468954",
pay_date="2026-11-02",
record_date="2026-10-09",
split_adjusted_cash_amount=0.7075,
ticker="VZ",
),
]
# a comma-separated str must be sent as-is, not split into characters
dividends = [d for d in self.c.list_stocks_dividends(ticker_any_of="AAPL,VZ")]
self.assertEqual(dividends, expected)
# a list of values is still joined with commas
dividends = [
d for d in self.c.list_stocks_dividends(ticker_any_of=["AAPL", "VZ"]) # type: ignore
]
self.assertEqual(dividends, expected)
2 changes: 2 additions & 0 deletions test_rest/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ def test_list_snapshot_indices(self):
def test_get_snapshot_indices(self):
ticker_any_of = ["SPX", "APx", "APy"]
summary_results = self.c.get_snapshot_indices(ticker_any_of)
# the comma-separated str form must build the same request
self.assertEqual(self.c.get_snapshot_indices("SPX,APx,APy"), summary_results)
expected = [
IndicesSnapshot(
value=3822.39,
Expand Down
Loading