Skip to content

Commit

Permalink
add fmv to snapshot and ws models and add new feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
morningvera committed Oct 19, 2023
1 parent d93ab7e commit 29cc799
Show file tree
Hide file tree
Showing 9 changed files with 1,735 additions and 791 deletions.
2,479 changes: 1,692 additions & 787 deletions .polygon/rest.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions polygon/rest/models/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class TickerSnapshot:
todays_change: Optional[float] = None
todays_change_percent: Optional[float] = None
updated: Optional[int] = None
fair_market_value: Optional[float] = None

@staticmethod
def from_dict(d):
Expand All @@ -107,6 +108,7 @@ def from_dict(d):
todays_change=d.get("todaysChange", None),
todays_change_percent=d.get("todaysChangePerc", None),
updated=d.get("updated", None),
fair_market_value=d.get("fmv", None),
)


Expand Down Expand Up @@ -215,6 +217,7 @@ class OptionContractSnapshot:
last_trade: Optional[LastTradeOptionContractSnapshot] = None
open_interest: Optional[float] = None
underlying_asset: Optional[UnderlyingAsset] = None
fair_market_value: Optional[float] = None

@staticmethod
def from_dict(d):
Expand All @@ -238,6 +241,7 @@ def from_dict(d):
underlying_asset=None
if "underlying_asset" not in d
else UnderlyingAsset.from_dict(d["underlying_asset"]),
fair_market_value=d.get("fmv", None),
)


Expand Down Expand Up @@ -391,6 +395,7 @@ class UniversalSnapshot:
open_interest: Optional[float] = None
market_status: Optional[str] = None
name: Optional[str] = None
fair_market_value: Optional[float] = None
error: Optional[str] = None
message: Optional[str] = None

Expand Down Expand Up @@ -420,6 +425,7 @@ def from_dict(d):
open_interest=d.get("open_interest", None),
market_status=d.get("market_status", None),
name=d.get("name", None),
fair_market_value=d.get("fmv", None),
error=d.get("error", None),
message=d.get("message", None),
)
10 changes: 10 additions & 0 deletions polygon/websocket/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class Feed(Enum):
PolyFeedPlus = "polyfeedplus.polygon.io"
StarterFeed = "starterfeed.polygon.io"
Launchpad = "launchpad.polygon.io"
BusinessFeed = "business.polygon.io"
EdgxBusinessFeed = "edgx-business.polygon.io"
DelayedBusinessFeed = "delayed-business.polygon.io"
FullMarketBusinessFeed = "fullmarket-business.polygon.io"
NasdaqfeedLastSaleBusinessFeed = "nasdaqfeed-last-sale-business.polygon.io"
NasdaqfeedBasicBusinessFeed = "nasdaqfeed-basic-business.polygon.io"


class Market(Enum):
Expand Down Expand Up @@ -40,3 +46,7 @@ class EventType(Enum):
"""
LaunchpadValue = "LV"
LaunchpadAggMin = "AM"
"""Business* EventTypes are only available to Business users. These values are the same across all asset classes (
stocks, options, forex, crypto).
"""
BusinessFairMarketValue = "FMV"
15 changes: 15 additions & 0 deletions polygon/websocket/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,21 @@ def from_dict(d):
timestamp=d.get("t", None),
)

@modelclass
class FairMarketValue:
event_type: Optional[Union[str, EventType]] = None
fmv: Optional[float] = None
ticker: Optional[str] = None
timestamp: Optional[int] = None

@staticmethod
def from_dict(d):
return LaunchpadValue(
event_type=d.get("ev", None),
fmv=d.get("fmv", None),
ticker=d.get("sym", None),
timestamp=d.get("t", None),
)

WebSocketMessage = NewType(
"WebSocketMessage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"ticker": "AAPL",
"todaysChange": -3.65,
"todaysChangePerc": -2.231,
"updated": 1651251948294080343
"updated": 1651251948294080343,
"fair_market_value": 160.315
}
}
3 changes: 2 additions & 1 deletion test_rest/mocks/v3/snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"volume": 37
},
"ticker": "AAPL",
"type": "stocks"
"type": "stocks",
"fair_market_value": 20.5
},
{
"error": "NOT_FOUND",
Expand Down
3 changes: 2 additions & 1 deletion test_rest/mocks/v3/snapshot/options/AAPL.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"price": 159.9606,
"ticker": "AAPL",
"timeframe": "REAL-TIME"
}
},
"fair_market_value": 20.5
}],
"status": "OK"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"price": 159.9606,
"ticker": "AAPL",
"timeframe": "REAL-TIME"
}
},
"fair_market_value": 29.2
},
"status": "OK"
}
4 changes: 4 additions & 0 deletions test_rest/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def test_get_snapshot_all(self):
todays_change=-0.124,
todays_change_percent=-0.601,
updated=1605192894630916600,
fair_market_value=20.5,
)
]
self.assertEqual(snapshots, expected)
Expand Down Expand Up @@ -276,6 +277,7 @@ def test_get_snapshot_ticker(self):
todays_change=-3.65,
todays_change_percent=-2.231,
updated=1651251948294080343,
fair_market_value=20.5,
)
self.assertEqual(snapshots, expected)

Expand Down Expand Up @@ -335,6 +337,7 @@ def test_get_snapshot_option(self):
ticker="AAPL",
timeframe="REAL-TIME",
),
fair_market_value=160.315,
)
self.assertEqual(snapshots, expected)

Expand Down Expand Up @@ -395,6 +398,7 @@ def test_list_snapshot_options_chain(self):
ticker="AAPL",
timeframe="REAL-TIME",
),
fair_market_value=29.2,
)
]
self.assertEqual(snapshots, expected)
Expand Down

0 comments on commit 29cc799

Please sign in to comment.