File tree 2 files changed +18
-4
lines changed
2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -249,7 +249,7 @@ def get_backfill_ohlcv(
249
249
return ohlcv
250
250
251
251
252
- def get_polygon_websocket_client (tickers : list [str ], api_key : str | None = None ) -> PolygonWebSocketClient :
252
+ def get_polygon_websocket_client (tickers : list [str ], api_key : str | None = None ) -> PolygonWebSocketClient : # TODO: check for usage; but probably delete
253
253
"""
254
254
Get Polygon WebSocket client. Subscribes to 1-minute aggs for the provided tickers.
255
255
@@ -286,6 +286,22 @@ def get_last_price_cached(ticker: str) -> float:
286
286
287
287
288
288
def convert_pg_agg (pg_agg : EquityAgg ) -> OHLCVAgg :
289
+ """
290
+ Convert a Polygon EquityAgg object to a phantom OHLCVAgg object.
291
+
292
+ This function transforms the data model from Polygon's format to phantom's internal
293
+ representation. The main use case is when receiving realtime data streamed from
294
+ Polygon via websocket.
295
+
296
+ Args:
297
+ pg_agg (EquityAgg): The Polygon equity aggregate object to convert.
298
+
299
+ Returns:
300
+ OHLCVAgg: A phantom OHLCVAgg object containing the same data.
301
+
302
+ Raises:
303
+ ValueError: If the event type is not supported.
304
+ """
289
305
data = pg_agg .__dict__
290
306
291
307
ticker = Ticker (data ['symbol' ].upper ())
@@ -298,12 +314,10 @@ def convert_pg_agg(pg_agg: EquityAgg) -> OHLCVAgg:
298
314
start_ts = pd .to_datetime (data ['start_timestamp' ], unit = 'ms' )\
299
315
.tz_localize ('UTC' )\
300
316
.tz_convert ('US/Eastern' )\
301
- .tz_localize (None )\
302
317
.to_pydatetime ()
303
318
end_ts = pd .to_datetime (data ['end_timestamp' ], unit = 'ms' )\
304
319
.tz_localize ('UTC' )\
305
320
.tz_convert ('US/Eastern' )\
306
- .tz_localize (None )\
307
321
.to_pydatetime ()
308
322
309
323
volume = data ['volume' ] / 10 # TODO: needs verification
Original file line number Diff line number Diff line change 1
1
[tool .poetry ]
2
2
name = " phantom-core"
3
- version = " 0.0.17 "
3
+ version = " 0.0.18 "
4
4
description = " Phantom Core"
5
5
authors = [" Adam Lineberry <ablineberry@gmail.com>" ]
6
6
license = " MIT"
You can’t perform that action at this time.
0 commit comments