Skip to content

Commit 19926a9

Browse files
author
clickingbuttons
authored
add better types (#118)
1 parent 406549d commit 19926a9

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

polygon/rest/aggs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .base import BaseClient
22
from typing import Optional, Any, Dict, List, Union
33
from .models import Agg, Sort
4+
from urllib3 import HTTPResponse
45

56
# https://polygon.io/docs/stocks
67
class AggsClient(BaseClient):
@@ -17,7 +18,7 @@ def get_aggs(
1718
limit: Optional[int] = None,
1819
params: Optional[Dict[str, Any]] = None,
1920
raw: bool = False,
20-
) -> List[Agg]:
21+
) -> Union[List[Agg], HTTPResponse]:
2122
"""
2223
Get aggregate bars for a ticker over a given date range in custom time window sizes.
2324

polygon/rest/models/aggs.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
from dataclasses import dataclass
2-
2+
from typing import Optional
33

44
@dataclass
55
class Agg:
6+
timestamp: int
67
open: float
78
high: float
89
low: float
910
close: float
1011
volume: float
11-
vwap: float
12-
timestamp: int
13-
transactions: int
12+
vwap: Optional[float]
13+
transactions: Optional[int]
1414

1515
@staticmethod
1616
def from_dict(d):
17-
return Agg(d["o"], d["h"], d["l"], d["c"], d["v"], d["vw"], d["t"], d["n"])
17+
return Agg(
18+
timestamp=d["t"],
19+
open=d["o"],
20+
high=d["h"],
21+
low=d["l"],
22+
close=d["c"],
23+
volume=d["v"],
24+
vwap=d.get("vw", None),
25+
transactions=d.get("n", None)
26+
)

polygon/rest/trades.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .base import BaseClient
2-
from typing import Optional, Any, Dict, Union
2+
from typing import Optional, Any, Dict, Union, Iterator
33
from .models import Trade, Sort, Order
4+
from urllib3 import HTTPResponse
45

56
# https://polygon.io/docs/stocks
67
class TradesClient(BaseClient):
@@ -17,7 +18,7 @@ def list_trades(
1718
order: Optional[Union[str, Order]] = None,
1819
params: Optional[Dict[str, Any]] = None,
1920
raw: bool = False,
20-
):
21+
) -> Union[Iterator[Trade], HTTPResponse]:
2122
"""
2223
Get trades for a ticker symbol in a given time range.
2324

0 commit comments

Comments
 (0)