Skip to content

Commit 5820020

Browse files
Darcy-LindeDarcy Linde
andauthored
Fix broken from_dict methods (#206)
* from_dict should use camelCase in these instances * update tests to reflect from_dict change Co-authored-by: Darcy Linde <{[email protected]}>
1 parent db3deed commit 5820020

File tree

4 files changed

+105
-27
lines changed

4 files changed

+105
-27
lines changed

polygon/rest/models/markets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class MarketStatus:
5353
@staticmethod
5454
def from_dict(d):
5555
return MarketStatus(
56-
after_hours=d.get("after_hours", None),
56+
after_hours=d.get("afterHours", None),
5757
currencies=None
5858
if "currencies" not in d
5959
else MarketCurrencies.from_dict(d["currencies"]),
60-
early_hours=d.get("early_hours", None),
60+
early_hours=d.get("earlyHours", None),
6161
exchanges=None
6262
if "exchanges" not in d
6363
else MarketExchanges.from_dict(d["exchanges"]),
6464
market=d.get("market", None),
65-
server_time=d.get("server_time", None),
65+
server_time=d.get("serverTime", None),
6666
)

polygon/rest/models/snapshot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ def from_dict(d):
4747
return TickerSnapshot(
4848
day=None if "day" not in d else Agg.from_dict(d["day"]),
4949
last_quote=None
50-
if "last_quote" not in d
51-
else LastQuote.from_dict(d["last_quote"]),
50+
if "lastQuote" not in d
51+
else LastQuote.from_dict(d["lastQuote"]),
5252
last_trade=None
53-
if "last_trade" not in d
54-
else LastTrade.from_dict(d["last_trade"]),
53+
if "lastTrade" not in d
54+
else LastTrade.from_dict(d["lastTrade"]),
5555
min=None if "min" not in d else MinuteSnapshot.from_dict(d["min"]),
56-
prev_day=None if "prev_day" not in d else Agg.from_dict(d["prev_day"]),
56+
prev_day=None if "prevDay" not in d else Agg.from_dict(d["prevDay"]),
5757
ticker=d.get("ticker", None),
58-
todays_change=d.get("todays_change", None),
59-
todays_change_percent=d.get("todays_change_percent", None),
58+
todays_change=d.get("todaysChange", None),
59+
todays_change_percent=d.get("todaysChangePerc", None),
6060
updated=d.get("updated", None),
6161
)
6262

@@ -207,8 +207,8 @@ def from_dict(d):
207207
asks=None
208208
if "asks" not in d
209209
else [OrderBookQuote.from_dict(o) for o in d["asks"]],
210-
bid_count=d.get("bid_count", None),
211-
ask_count=d.get("ask_count", None),
210+
bid_count=d.get("bidCount", None),
211+
ask_count=d.get("askCount", None),
212212
spread=d.get("spread", None),
213213
updated=d.get("updated", None),
214214
)

test_rest/test_markets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ def test_get_market_holidays(self):
129129
def test_get_market_status(self):
130130
status = self.c.get_market_status()
131131
expected = MarketStatus(
132-
after_hours=None,
132+
after_hours=True,
133133
currencies=MarketCurrencies(crypto="open", fx="open"),
134-
early_hours=None,
134+
early_hours=False,
135135
exchanges=MarketExchanges(
136136
nasdaq="extended-hours", nyse="extended-hours", otc="extended-hours"
137137
),
138138
market="extended-hours",
139-
server_time=None,
139+
server_time="2022-04-28T16:48:08-04:00",
140140
)
141141
self.assertEqual(status, expected)

test_rest/test_snapshots.py

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
SnapshotTickerFullBook,
55
Agg,
66
MinuteSnapshot,
7+
LastQuote,
8+
LastTrade,
79
OrderBookQuote,
810
UnderlyingAsset,
911
LastQuoteOptionContractSnapshot,
@@ -29,8 +31,37 @@ def test_get_snapshot_all(self):
2931
timestamp=None,
3032
transactions=None,
3133
),
32-
last_quote=None,
33-
last_trade=None,
34+
last_quote=LastQuote(
35+
ticker=None,
36+
trf_timestamp=None,
37+
sequence_number=None,
38+
sip_timestamp=1605192959994246100,
39+
participant_timestamp=None,
40+
ask_price=20.6,
41+
ask_size=22,
42+
ask_exchange=None,
43+
conditions=None,
44+
indicators=None,
45+
bid_price=20.5,
46+
bid_size=13,
47+
bid_exchange=None,
48+
tape=None,
49+
),
50+
last_trade=LastTrade(
51+
ticker=None,
52+
trf_timestamp=None,
53+
sequence_number=None,
54+
sip_timestamp=1605192894630916600,
55+
participant_timestamp=None,
56+
conditions=[14, 41],
57+
correction=None,
58+
id="71675577320245",
59+
price=20.506,
60+
trf_id=None,
61+
size=2416,
62+
exchange=4,
63+
tape=None,
64+
),
3465
min=MinuteSnapshot(
3566
accumulated_volume=37216,
3667
open=20.506,
@@ -40,10 +71,19 @@ def test_get_snapshot_all(self):
4071
volume=5000,
4172
vwap=20.5105,
4273
),
43-
prev_day=None,
74+
prev_day=Agg(
75+
open=20.79,
76+
high=21,
77+
low=20.5,
78+
close=20.63,
79+
volume=292738,
80+
vwap=20.6939,
81+
timestamp=None,
82+
transactions=None,
83+
),
4484
ticker="BCAT",
45-
todays_change=None,
46-
todays_change_percent=None,
85+
todays_change=-0.124,
86+
todays_change_percent=-0.601,
4787
updated=1605192894630916600,
4888
)
4989
]
@@ -62,8 +102,37 @@ def test_get_snapshot_ticker(self):
62102
timestamp=None,
63103
transactions=None,
64104
),
65-
last_quote=None,
66-
last_trade=None,
105+
last_quote=LastQuote(
106+
ticker=None,
107+
trf_timestamp=None,
108+
sequence_number=None,
109+
sip_timestamp=1651251948407646487,
110+
participant_timestamp=None,
111+
ask_price=159.99,
112+
ask_size=5,
113+
ask_exchange=None,
114+
conditions=None,
115+
indicators=None,
116+
bid_price=159.98,
117+
bid_size=3,
118+
bid_exchange=None,
119+
tape=None,
120+
),
121+
last_trade=LastTrade(
122+
ticker=None,
123+
trf_timestamp=None,
124+
sequence_number=None,
125+
sip_timestamp=1651251948294080343,
126+
participant_timestamp=None,
127+
conditions=None,
128+
correction=None,
129+
id="121351",
130+
price=159.99,
131+
trf_id=None,
132+
size=200,
133+
exchange=12,
134+
tape=None,
135+
),
67136
min=MinuteSnapshot(
68137
accumulated_volume=68834255,
69138
open=160.71,
@@ -73,10 +142,19 @@ def test_get_snapshot_ticker(self):
73142
volume=197226,
74143
vwap=160.5259,
75144
),
76-
prev_day=None,
145+
prev_day=Agg(
146+
open=159.25,
147+
high=164.515,
148+
low=158.93,
149+
close=163.64,
150+
volume=130149192,
151+
vwap=161.8622,
152+
timestamp=None,
153+
transactions=None,
154+
),
77155
ticker="AAPL",
78-
todays_change=None,
79-
todays_change_percent=None,
156+
todays_change=-3.65,
157+
todays_change_percent=-2.231,
80158
updated=1651251948294080343,
81159
)
82160
self.assertEqual(snapshots, expected)
@@ -146,8 +224,8 @@ def test_get_snapshot_crypto_book(self):
146224
OrderBookQuote(price=11454, exchange_shares={"2": 1}),
147225
OrderBookQuote(price=11455, exchange_shares={"2": 1}),
148226
],
149-
bid_count=None,
150-
ask_count=None,
227+
bid_count=694.951789670001,
228+
ask_count=593.1412981600005,
151229
spread=-4849.17,
152230
updated=1605295074162,
153231
)

0 commit comments

Comments
 (0)