Skip to content
Draft
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
9 changes: 8 additions & 1 deletion docs/source/Aggs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ Get daily open close agg

- `Stocks daily open/close agg`_
- `Options daily open/close agg`_
- `Crypto daily open/close agg`_

.. automethod:: massive.RESTClient.get_daily_open_close_agg

============================
Get daily open close crypto
============================

- `Crypto daily open/close agg`_

.. automethod:: massive.RESTClient.get_daily_open_close_crypto

============================
Get previous close agg
============================
Expand Down
7 changes: 4 additions & 3 deletions examples/rest/crypto-daily_open_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

# docs
# https://massive.com/docs/crypto/get_v1_open-close_crypto__from___to___date
# https://massive-api-client.readthedocs.io/en/latest/Aggs.html#get-daily-open-close-agg
# https://massive-api-client.readthedocs.io/en/latest/Aggs.html#get-daily-open-close-crypto

# client = RESTClient("XXXXXX") # hardcoded api_key is used
client = RESTClient() # MASSIVE_API_KEY environment variable is used

# make request
request = client.get_daily_open_close_agg(
"X:BTCUSD",
request = client.get_daily_open_close_crypto(
"BTC",
"USD",
"2023-01-09",
)

Expand Down
13 changes: 13 additions & 0 deletions examples/rest/economy-funding_conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from massive import RESTClient

# docs
# https://massive.com/docs/rest/economy/funding-conditions

# client = RESTClient("XXXXXX") # hardcoded api_key is used
client = RESTClient() # MASSIVE_API_KEY environment variable is used

conditions = []
for day in client.list_funding_conditions(date_gte="2025-06-01", sort="date.asc"):
conditions.append(day)

print(conditions)
41 changes: 40 additions & 1 deletion massive/rest/aggs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from .base import BaseClient
from typing import Optional, Any, Dict, List, Union, Iterator
from .models import Agg, GroupedDailyAgg, DailyOpenCloseAgg, PreviousCloseAgg, Sort
from .models import (
Agg,
GroupedDailyAgg,
DailyOpenCloseAgg,
DailyOpenCloseCrypto,
PreviousCloseAgg,
Sort,
)
from urllib3 import HTTPResponse
from datetime import datetime, date

Expand Down Expand Up @@ -161,6 +168,38 @@ def get_daily_open_close_agg(
options=options,
)

def get_daily_open_close_crypto(
self,
# "from" is a keyword in python https://www.w3schools.com/python/python_ref_keywords.asp
from_: str,
to: str,
date: Union[str, date],
adjusted: Optional[bool] = None,
params: Optional[Dict[str, Any]] = None,
raw: bool = False,
options: Optional[RequestOptionBuilder] = None,
) -> Union[DailyOpenCloseCrypto, HTTPResponse]:
"""
Get the open and close prices of a cryptocurrency pair on a certain day, along with the opening and closing trades.

:param from_: The "from" symbol of the pair (e.g. "BTC").
:param to: The "to" symbol of the pair (e.g. "USD").
:param date: The date of the requested open/close in the format YYYY-MM-DD.
:param adjusted: Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits.
:param params: Any additional query params
:param raw: Return raw object instead of results object
:return: Daily open close for the crypto pair
"""
url = f"/v1/open-close/crypto/{from_}/{to}/{date}"

return self._get(
path=url,
params=self._get_params(self.get_daily_open_close_crypto, locals()),
deserializer=DailyOpenCloseCrypto.from_dict,
raw=raw,
options=options,
)

def get_previous_close_agg(
self,
ticker: str,
Expand Down
40 changes: 40 additions & 0 deletions massive/rest/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
TreasuryYield,
FedInflationExpectations,
FedLaborMarket,
FedFundingConditions,
EUMerchantAggregate,
EUMerchantHierarchy,
)
Expand Down Expand Up @@ -171,6 +172,45 @@ def list_labor_market_indicators(
options=options,
)

def list_funding_conditions(
self,
date: Optional[Union[str, date]] = None,
date_gt: Optional[Union[str, date]] = None,
date_gte: Optional[Union[str, date]] = None,
date_lt: Optional[Union[str, date]] = None,
date_lte: Optional[Union[str, date]] = None,
limit: Optional[int] = None,
sort: Optional[str] = None,
params: Optional[Dict[str, Any]] = None,
raw: bool = False,
options: Optional[RequestOptionBuilder] = None,
) -> Union[Iterator[FedFundingConditions], HTTPResponse]:
"""
Daily U.S. money-market funding conditions from the Federal Reserve and the Federal Reserve Bank of New York, including the Federal Funds Effective Rate, SOFR, OBFR, tri-party general collateral repo rates, Treasury-collateralized overnight reverse repo and repo operation amounts, and commercial paper rates.

:param date: Calendar date of the observation (YYYY-MM-DD).
:param date_gt: Filter greater than the value.
:param date_gte: Filter greater than or equal to the value.
:param date_lt: Filter less than the value.
:param date_lte: Filter less than or equal to the value.
:param limit: Limit the maximum number of results returned. Defaults to '100' if not specified. The maximum allowed limit is '50000'.
:param sort: A comma separated list of sort columns. For each column, append '.asc' or '.desc' to specify the sort direction, e.g. "date.desc". The sort column defaults to 'date' if not specified. The sort order defaults to 'asc' if not specified. The value is sent as given.
:param params: Additional query parameters.
:param raw: Return raw HTTPResponse object if True, else return Iterator[FedFundingConditions].
:param options: RequestOptionBuilder for additional headers or params.
:return: An iterator of FedFundingConditions objects or HTTPResponse if raw=True.
"""
url = "/fed/v1/funding-conditions"

return self._paginate(
path=url,
params=self._get_params(self.list_funding_conditions, locals()),
deserializer=FedFundingConditions.from_dict,
raw=raw,
result_key="results",
options=options,
)

def list_eu_merchant_aggregates(
self,
transaction_date: Optional[Union[str, date]] = None,
Expand Down
60 changes: 59 additions & 1 deletion massive/rest/models/aggs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import List, Optional
from ...modelclass import modelclass


Expand Down Expand Up @@ -95,6 +95,64 @@ def from_dict(d):
)


@modelclass
class DailyOpenCloseCryptoTrade:
"Contains data for one of the opening or closing trades of a crypto pair on a specified date."

conditions: Optional[List[int]] = None
id: Optional[str] = None
price: Optional[float] = None
size: Optional[float] = None
timestamp: Optional[int] = None
exchange: Optional[int] = None

@staticmethod
def from_dict(d):
return DailyOpenCloseCryptoTrade(
conditions=d.get("c", None),
id=d.get("i", None),
price=d.get("p", None),
size=d.get("s", None),
timestamp=d.get("t", None),
exchange=d.get("x", None),
)


@modelclass
class DailyOpenCloseCrypto:
"Contains data for open and close prices, and the opening and closing trades, of a crypto pair on a specified date."

symbol: Optional[str] = None
is_utc: Optional[bool] = None
day: Optional[str] = None
open: Optional[float] = None
close: Optional[float] = None
open_trades: Optional[List[DailyOpenCloseCryptoTrade]] = None
closing_trades: Optional[List[DailyOpenCloseCryptoTrade]] = None

@staticmethod
def from_dict(d):
return DailyOpenCloseCrypto(
symbol=d.get("symbol", None),
is_utc=d.get("isUTC", None),
day=d.get("day", None),
open=d.get("open", None),
close=d.get("close", None),
open_trades=(
None
if "openTrades" not in d
else [DailyOpenCloseCryptoTrade.from_dict(t) for t in d["openTrades"]]
),
closing_trades=(
None
if "closingTrades" not in d
else [
DailyOpenCloseCryptoTrade.from_dict(t) for t in d["closingTrades"]
]
),
)


@modelclass
class PreviousCloseAgg:
"Contains data for the previous day's open, high, low, and close (OHLC) of the specified stock ticker."
Expand Down
70 changes: 70 additions & 0 deletions massive/rest/models/economy.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,76 @@ def from_dict(d):
)


@modelclass
class FedFundingConditions:
"""
Daily U.S. money-market funding conditions for a specific date. Rates are
percentages; volumes and operation amounts are in billions of U.S. dollars.
"""

date: Optional[str] = None
effective_fed_funds_rate: Optional[float] = None
effective_fed_funds_volume: Optional[float] = None
fed_funds_target_lower: Optional[float] = None
fed_funds_target_upper: Optional[float] = None
fed_overnight_repo_treasury_amount: Optional[float] = None
fed_overnight_reverse_repo_treasury_amount: Optional[float] = None
financial_commercial_paper_90d_rate: Optional[float] = None
interest_on_reserve_balances: Optional[float] = None
nonfinancial_commercial_paper_90d_rate: Optional[float] = None
obfr_25th_percentile: Optional[float] = None
obfr_75th_percentile: Optional[float] = None
obfr_volume: Optional[float] = None
overnight_bank_funding_rate: Optional[float] = None
secured_overnight_financing_rate: Optional[float] = None
sofr_25th_percentile: Optional[float] = None
sofr_75th_percentile: Optional[float] = None
sofr_volume: Optional[float] = None
tgcr_25th_percentile: Optional[float] = None
tgcr_75th_percentile: Optional[float] = None
tri_party_general_collateral_rate: Optional[float] = None
tri_party_general_collateral_volume: Optional[float] = None

@staticmethod
def from_dict(d):
return FedFundingConditions(
date=d.get("date"),
effective_fed_funds_rate=d.get("effective_fed_funds_rate"),
effective_fed_funds_volume=d.get("effective_fed_funds_volume"),
fed_funds_target_lower=d.get("fed_funds_target_lower"),
fed_funds_target_upper=d.get("fed_funds_target_upper"),
fed_overnight_repo_treasury_amount=d.get(
"fed_overnight_repo_treasury_amount"
),
fed_overnight_reverse_repo_treasury_amount=d.get(
"fed_overnight_reverse_repo_treasury_amount"
),
financial_commercial_paper_90d_rate=d.get(
"financial_commercial_paper_90d_rate"
),
interest_on_reserve_balances=d.get("interest_on_reserve_balances"),
nonfinancial_commercial_paper_90d_rate=d.get(
"nonfinancial_commercial_paper_90d_rate"
),
obfr_25th_percentile=d.get("obfr_25th_percentile"),
obfr_75th_percentile=d.get("obfr_75th_percentile"),
obfr_volume=d.get("obfr_volume"),
overnight_bank_funding_rate=d.get("overnight_bank_funding_rate"),
secured_overnight_financing_rate=d.get("secured_overnight_financing_rate"),
sofr_25th_percentile=d.get("sofr_25th_percentile"),
sofr_75th_percentile=d.get("sofr_75th_percentile"),
sofr_volume=d.get("sofr_volume"),
tgcr_25th_percentile=d.get("tgcr_25th_percentile"),
tgcr_75th_percentile=d.get("tgcr_75th_percentile"),
tri_party_general_collateral_rate=d.get(
"tri_party_general_collateral_rate"
),
tri_party_general_collateral_volume=d.get(
"tri_party_general_collateral_volume"
),
)


@modelclass
class EUMerchantAggregate:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"status": "OK",
"request_id": "b2170df985474b6d21a6eeccfb6bee67",
"count": 1,
"results": [
{
"date": "2025-06-02",
"effective_fed_funds_rate": 4.33,
"effective_fed_funds_volume": 98,
"fed_funds_target_lower": 4.25,
"fed_funds_target_upper": 4.5,
"fed_overnight_repo_treasury_amount": 0,
"fed_overnight_reverse_repo_treasury_amount": 214.5,
"financial_commercial_paper_90d_rate": 4.35,
"interest_on_reserve_balances": 4.4,
"nonfinancial_commercial_paper_90d_rate": 4.34,
"obfr_25th_percentile": 4.3,
"obfr_75th_percentile": 4.33,
"obfr_volume": 305,
"overnight_bank_funding_rate": 4.32,
"secured_overnight_financing_rate": 4.31,
"sofr_25th_percentile": 4.28,
"sofr_75th_percentile": 4.32,
"sofr_volume": 2214,
"tgcr_25th_percentile": 4.27,
"tgcr_75th_percentile": 4.31,
"tri_party_general_collateral_rate": 4.3,
"tri_party_general_collateral_volume": 1876
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"status": "OK",
"request_id": "6a7e466379af0a71039d60cc78e72282",
"count": 1,
"next_url": "https://api.massive.com/fed/v1/funding-conditions?cursor=ZGF0ZS5ndGU9MjAyNS0wNi0wMSZsaW1pdD0x",
"results": [
{
"date": "2025-06-01",
"effective_fed_funds_rate": 4.33,
"effective_fed_funds_volume": null,
"fed_funds_target_lower": 4.25,
"fed_funds_target_upper": 4.5,
"fed_overnight_repo_treasury_amount": null,
"fed_overnight_reverse_repo_treasury_amount": null,
"financial_commercial_paper_90d_rate": null,
"interest_on_reserve_balances": 4.4,
"nonfinancial_commercial_paper_90d_rate": null,
"obfr_25th_percentile": null,
"obfr_75th_percentile": null,
"obfr_volume": null,
"overnight_bank_funding_rate": null,
"secured_overnight_financing_rate": null,
"sofr_25th_percentile": null,
"sofr_75th_percentile": null,
"sofr_volume": null,
"tgcr_25th_percentile": null,
"tgcr_75th_percentile": null,
"tri_party_general_collateral_rate": null,
"tri_party_general_collateral_volume": null
}
]
}
Loading
Loading