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
23 changes: 23 additions & 0 deletions polygon/modelclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import inspect
from dataclasses import dataclass


def modelclass(cls):
cls = dataclass(cls)
attributes = [
a
for a in cls.__dict__["__annotations__"].keys()
if not a.startswith("__") and not inspect.isroutine(a)
]

def init(self, *args, **kwargs):
for (i, a) in enumerate(args):
if i < len(attributes):
self.__dict__[attributes[i]] = a
for (k, v) in kwargs.items():
if k in attributes:
self.__dict__[k] = v

cls.__init__ = init

return cls
10 changes: 5 additions & 5 deletions polygon/rest/models/aggs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from typing import Optional
from ...modelclass import modelclass


@dataclass
@modelclass
class Agg:
"Contains aggregate data for a given ticker symbol over a given date range in a custom time window size."
open: Optional[float] = None
Expand All @@ -28,7 +28,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class GroupedDailyAgg:
"Contains daily open, high, low, and close (OHLC) data for a given date."
ticker: Optional[str] = None
Expand Down Expand Up @@ -56,7 +56,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class DailyOpenCloseAgg:
"Contains data for open, close and afterhours prices of a ticker symbol on a specified date."
after_hours: Optional[float] = None
Expand Down Expand Up @@ -86,7 +86,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class PreviousCloseAgg:
"Contains data for the previous day's open, high, low, and close (OHLC) of the specified stock ticker."
ticker: Optional[str] = None
Expand Down
12 changes: 6 additions & 6 deletions polygon/rest/models/conditions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, List
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class SipMapping:
"Contains data for a mapping to a symbol for each SIP that has a given condition."
CTA: Optional[str] = None
Expand All @@ -14,7 +14,7 @@ def from_dict(d):
return SipMapping(**d)


@dataclass
@modelclass
class Consolidated:
"Contains data for aggregation rules on a consolidated (all exchanges) basis."
updates_high_low: Optional[bool] = None
Expand All @@ -26,7 +26,7 @@ def from_dict(d):
return Consolidated(**d)


@dataclass
@modelclass
class MarketCenter:
"Contains data for aggregation rules on a per-market-center basis."
updates_high_low: Optional[bool] = None
Expand All @@ -38,7 +38,7 @@ def from_dict(d):
return MarketCenter(**d)


@dataclass
@modelclass
class UpdateRules:
"Contains data for a list of aggregation rules."
consolidated: Optional[Consolidated] = None
Expand All @@ -56,7 +56,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class Condition:
"Condition contains data for a condition that Polygon.io uses."
abbreviation: Optional[str] = None
Expand Down
4 changes: 2 additions & 2 deletions polygon/rest/models/dividends.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class Dividend:
"Dividend contains data for a historical cash dividend, including the ticker symbol, declaration date, ex-dividend date, record date, pay date, frequency, and amount."
cash_amount: Optional[float] = None
Expand Down
4 changes: 2 additions & 2 deletions polygon/rest/models/exchanges.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class Exchange:
"Exchange contains data for a condition that Polygon.io uses."
acronym: Optional[str] = None
Expand Down
36 changes: 18 additions & 18 deletions polygon/rest/models/financials.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, Dict
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class DataPoint:
"An individual financial data point."
formula: Optional[str] = None
Expand All @@ -17,7 +17,7 @@ def from_dict(d):
return DataPoint(**d)


@dataclass
@modelclass
class ExchangeGainsLosses:
"Contains exchange gains losses data for a cash flow statement."
formula: Optional[str] = None
Expand All @@ -32,7 +32,7 @@ def from_dict(d):
return ExchangeGainsLosses(**d)


@dataclass
@modelclass
class NetCashFlow:
"Contains net cash flow data for a cash flow statement."
formula: Optional[str] = None
Expand All @@ -47,7 +47,7 @@ def from_dict(d):
return NetCashFlow(**d)


@dataclass
@modelclass
class NetCashFlowFromFinancingActivities:
"Contains net cash flow from financing activities data for a cash flow statement."
formula: Optional[str] = None
Expand All @@ -62,7 +62,7 @@ def from_dict(d):
return NetCashFlowFromFinancingActivities(**d)


@dataclass
@modelclass
class CashFlowStatement:
"Contains cash flow statement data."
exchange_gains_losses: Optional[ExchangeGainsLosses] = None
Expand All @@ -88,7 +88,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class ComprehensiveIncomeLoss:
"Contains comprehensive income loss data for comprehensive income."
formula: Optional[str] = None
Expand All @@ -103,7 +103,7 @@ def from_dict(d):
return ComprehensiveIncomeLoss(**d)


@dataclass
@modelclass
class ComprehensiveIncomeLossAttributableToParent:
"Contains comprehensive income loss attributable to parent data for comprehensive income."
formula: Optional[str] = None
Expand All @@ -118,7 +118,7 @@ def from_dict(d):
return ComprehensiveIncomeLossAttributableToParent(**d)


@dataclass
@modelclass
class OtherComprehensiveIncomeLoss:
"Contains other comprehensive income loss data for comprehensive income."
formula: Optional[str] = None
Expand All @@ -133,7 +133,7 @@ def from_dict(d):
return OtherComprehensiveIncomeLoss(**d)


@dataclass
@modelclass
class ComprehensiveIncome:
"Contains comprehensive income data."
comprehensive_income_loss: Optional[ComprehensiveIncomeLoss] = None
Expand Down Expand Up @@ -161,7 +161,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class BasicEarningsPerShare:
"Contains basic earning per share data for an income statement."
formula: Optional[str] = None
Expand All @@ -176,7 +176,7 @@ def from_dict(d):
return BasicEarningsPerShare(**d)


@dataclass
@modelclass
class CostOfRevenue:
"Contains cost of revenue data for an income statement."
formula: Optional[str] = None
Expand All @@ -191,7 +191,7 @@ def from_dict(d):
return CostOfRevenue(**d)


@dataclass
@modelclass
class GrossProfit:
"Contains gross profit data for an income statement."
formula: Optional[str] = None
Expand All @@ -206,7 +206,7 @@ def from_dict(d):
return GrossProfit(**d)


@dataclass
@modelclass
class OperatingExpenses:
"Contains operating expenses data for an income statement."
formula: Optional[str] = None
Expand All @@ -221,7 +221,7 @@ def from_dict(d):
return OperatingExpenses(**d)


@dataclass
@modelclass
class Revenues:
"Contains revenues data for an income statement."
formula: Optional[str] = None
Expand All @@ -236,7 +236,7 @@ def from_dict(d):
return Revenues(**d)


@dataclass
@modelclass
class IncomeStatement:
"Contains income statement data."
basic_earnings_per_share: Optional[BasicEarningsPerShare] = None
Expand Down Expand Up @@ -264,7 +264,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class Financials:
"Contains financial data."
balance_sheet: Optional[Dict[str, DataPoint]] = None
Expand All @@ -290,7 +290,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class StockFinancial:
"StockFinancial contains historical financial data for a stock ticker."
cik: Optional[str] = None
Expand Down
10 changes: 5 additions & 5 deletions polygon/rest/models/markets.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class MarketCurrencies:
"Contains currency market status data."
crypto: Optional[str] = None
Expand All @@ -13,7 +13,7 @@ def from_dict(d):
return MarketCurrencies(**d)


@dataclass
@modelclass
class MarketExchanges:
"Contains exchange market status data."
nasdaq: Optional[str] = None
Expand All @@ -25,7 +25,7 @@ def from_dict(d):
return MarketExchanges(**d)


@dataclass
@modelclass
class MarketHoliday:
"MarketHoliday contains data for upcoming market holidays and their open/close times."
close: Optional[str] = None
Expand All @@ -40,7 +40,7 @@ def from_dict(d):
return MarketHoliday(**d)


@dataclass
@modelclass
class MarketStatus:
"MarketStatus contains data for the current trading status of the exchanges and overall financial markets."
after_hours: Optional[bool] = None
Expand Down
12 changes: 6 additions & 6 deletions polygon/rest/models/quotes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Optional, List
from dataclasses import dataclass
from ...modelclass import modelclass


@dataclass
@modelclass
class Quote:
"Quote contains quote data for a specified ticker symbol."
ask_exchange: Optional[int] = None
Expand All @@ -24,7 +24,7 @@ def from_dict(d):
return Quote(**d)


@dataclass
@modelclass
class LastQuote:
"LastQuote contains data for the most recent NBBO (Quote) tick for a given stock."
ticker: Optional[str] = None
Expand Down Expand Up @@ -62,7 +62,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class ForexQuote:
"Contains data for a forex quote."
ask: Optional[float] = None
Expand All @@ -75,7 +75,7 @@ def from_dict(d):
return ForexQuote(**d)


@dataclass
@modelclass
class LastForexQuote:
"ForexLastQuote contains data for the last quote tick for a forex currency pair."
last: Optional[ForexQuote] = None
Expand All @@ -89,7 +89,7 @@ def from_dict(d):
)


@dataclass
@modelclass
class RealTimeCurrencyConversion:
"RealTimeCurrencyConversion contains data for currency conversions using the latest market conversion rates."
converted: Optional[float] = None
Expand Down
Loading