Skip to content

Commit

Permalink
Entities: change nasdaq api cols to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
tsugumi-sys committed May 5, 2024
1 parent 2409cca commit 4aeffaf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
18 changes: 14 additions & 4 deletions stocklake/nasdaqapi/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,27 @@ class RawNasdaqApiSymbolData(TypedDict):
lastsale: str
netchange: str
pctchange: str
volume: str
marketCap: str
country: str
ipo_year: str
industry: str
sector: str
url: str


class NasdaqApiSymbolData(TypedDict):
symbol: str
name: str
lastsale: float
netchange: float
pctchange: float
marketCap: float
last_sale: float
net_change: float
pct_change: float
marketcap: float
volume: float
country: str
ipo_year: int
industry: str
sector: str
url: str


Expand Down
19 changes: 15 additions & 4 deletions stocklake/nasdaqapi/preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ def process(self, data: List[RawNasdaqApiSymbolData]) -> List[NasdaqApiSymbolDat
_data: NasdaqApiSymbolData = {
"symbol": data_dic["symbol"],
"name": data_dic["name"],
"lastsale": float(
"last_sale": float(
data_dic["lastsale"].replace("$", "").replace(",", "")
),
"netchange": float(data_dic["netchange"]),
"pctchange": float(data_dic["pctchange"].replace("%", "")),
"marketCap": float(data_dic["marketCap"].replace(",", "")),
"pct_change": float(data_dic["pctchange"].replace("%", "")),
"net_change": float(data_dic["netchange"]),
"volume": float(data_dic["volume"]),
"marketcap": float(data_dic["marketCap"].replace(",", "")),
"country": data_dic["country"],
"ipo_year": self._ipo_year(data_dic),
"industry": data_dic["industry"],
"sector": data_dic["sector"],
"url": data_dic["url"],
}
processed_data.append(_data)
return processed_data

def _ipo_year(self, data_dic: RawNasdaqApiSymbolData) -> int:
ipo_year = data_dic["ipoyear"]
if ipo_year == "":
return 0
return int(ipo_year)
4 changes: 3 additions & 1 deletion tests/nasdaqapi/test_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def test_process():
data = preprocessor.process(mock_raw_data)
for data_dic in data:
for key, val in data_dic.items():
if key in ["lastsale", "netchange", "pctchange", "marketCap"]:
if key in ["last_sale", "net_change", "pct_change", "marketcap", "volume"]:
assert isinstance(val, float)
elif key in ["ipo_year"]:
assert isinstance(val, int)
else:
assert isinstance(val, str)

0 comments on commit 4aeffaf

Please sign in to comment.