Skip to content

Commit c65cfe3

Browse files
author
clickingbuttons
authored
Fix locale for crypto snapshot (#268)
* Fix locale for crypto snapshot * Fix enum
1 parent 59b307d commit c65cfe3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

polygon/rest/snapshot.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010
from urllib3 import HTTPResponse
1111

1212

13+
def get_locale(market_type: Union[SnapshotMarketType, str]):
14+
if market_type == SnapshotMarketType.STOCKS.value:
15+
return "us"
16+
17+
return "global"
18+
19+
1320
class SnapshotClient(BaseClient):
1421
def get_snapshot_all(
1522
self,
16-
market_type: Optional[Union[str, SnapshotMarketType]],
23+
market_type: Union[str, SnapshotMarketType],
1724
tickers: Optional[Union[str, List[str]]] = None,
1825
params: Optional[Dict[str, Any]] = None,
1926
raw: bool = False,
@@ -29,7 +36,8 @@ def get_snapshot_all(
2936
:param include_otc: Include OTC securities in the response. Default is false (don't include OTC securities).
3037
:return: List of Snapshots
3138
"""
32-
url = f"/v2/snapshot/locale/us/markets/{market_type}/tickers"
39+
locale = get_locale(market_type)
40+
url = f"/v2/snapshot/locale/{locale}/markets/{market_type}/tickers"
3341
if type(tickers) is list:
3442
tickers = ",".join(tickers)
3543
return self._get(
@@ -42,7 +50,7 @@ def get_snapshot_all(
4250

4351
def get_snapshot_direction(
4452
self,
45-
market_type: Optional[Union[str, SnapshotMarketType]],
53+
market_type: Union[str, SnapshotMarketType],
4654
direction: Union[str, Direction],
4755
params: Optional[Dict[str, Any]] = None,
4856
include_otc: Optional[bool] = False,
@@ -60,7 +68,8 @@ def get_snapshot_direction(
6068
:param include_otc: Include OTC securities in the response. Default is false (don't include OTC securities).
6169
:return: List of Snapshots
6270
"""
63-
url = f"/v2/snapshot/locale/us/markets/{market_type}/{direction}"
71+
locale = get_locale(market_type)
72+
url = f"/v2/snapshot/locale/{locale}/markets/{market_type}/{direction}"
6473
return self._get(
6574
path=url,
6675
params=self._get_params(self.get_snapshot_direction, locals()),
@@ -71,7 +80,7 @@ def get_snapshot_direction(
7180

7281
def get_snapshot_ticker(
7382
self,
74-
market_type: Optional[Union[str, SnapshotMarketType]],
83+
market_type: Union[str, SnapshotMarketType],
7584
ticker: str,
7685
params: Optional[Dict[str, Any]] = None,
7786
raw: bool = False,
@@ -85,7 +94,8 @@ def get_snapshot_ticker(
8594
:param ticker: The ticker symbol.
8695
:return: List of Snapshots
8796
"""
88-
url = f"/v2/snapshot/locale/us/markets/{market_type}/tickers/{ticker}"
97+
locale = get_locale(market_type)
98+
url = f"/v2/snapshot/locale/{locale}/markets/{market_type}/tickers/{ticker}"
8999
return self._get(
90100
path=url,
91101
params=self._get_params(self.get_snapshot_ticker, locals()),

0 commit comments

Comments
 (0)