Skip to content

Commit 72366ef

Browse files
Darcy-Lindeclickingbuttons
authored andcommitted
Markets (#121)
1 parent 02c6cf4 commit 72366ef

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

polygon/rest/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from .aggs import AggsClient
22
from .trades import TradesClient
33
from .quotes import QuotesClient
4+
from .reference import MarketsClient
45

56

6-
class RESTClient(AggsClient, TradesClient, QuotesClient):
7+
class RESTClient(AggsClient, TradesClient, QuotesClient, MarketsClient):
78
pass

polygon/rest/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from .aggs import *
22
from .trades import *
33
from .quotes import *
4+
from .markets import *
5+
46
from enum import Enum
57

68

polygon/rest/models/markets.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Optional, Dict
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class MarketHoliday:
7+
"MarketHoliday contains data for upcoming market holidays and their open/close times."
8+
close: Optional[str] = None
9+
date: Optional[str] = None
10+
exchange: Optional[str] = None
11+
name: Optional[str] = None
12+
open: Optional[str] = None
13+
status: Optional[str] = None
14+
15+
@staticmethod
16+
def from_dict(d):
17+
return MarketHoliday(**d)
18+
19+
@dataclass
20+
class MarketStatus:
21+
"MarketStatus contains data for the current trading status of the exchanges and overall financial markets."
22+
after_hours: Optional[bool] = None
23+
currencies: Optional[Dict[str, str]] = None
24+
early_hours: Optional[bool] = None
25+
exchanges: Optional[Dict[str, str]] = None
26+
market: Optional[str] = None
27+
server_time: Optional[str] = None
28+
29+
@staticmethod
30+
def from_dict(d):
31+
return MarketStatus(**d)

polygon/rest/reference.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from .base import BaseClient
2+
from typing import Optional, Any, Dict, List, Union
3+
from .models import MarketHoliday, MarketStatus
4+
from urllib3 import HTTPResponse
5+
6+
# https://polygon.io/docs/stocks
7+
class MarketsClient(BaseClient):
8+
def list_market_holidays(
9+
self,
10+
params: Optional[Dict[str, Any]] = None,
11+
raw: bool = False
12+
) -> Union[List[MarketHoliday], HTTPResponse]:
13+
"""
14+
Get upcoming market holidays and their open/close times.
15+
16+
:param params: Any additional query params
17+
:param raw: Return HTTPResponse object instead of results object
18+
:return: List of quotes
19+
:rtype: List[Quote]
20+
"""
21+
url = "/v1/marketstatus/upcoming"
22+
23+
return self._get(path=url, params=params, deserializer=MarketHoliday.from_dict, raw=raw)
24+
25+
def get_market_status(
26+
self,
27+
params: Optional[Dict[str, Any]] = None,
28+
raw: bool = False
29+
) -> Union[MarketStatus, HTTPResponse]:
30+
"""
31+
Get the current trading status of the exchanges and overall financial markets.
32+
33+
:param params: Any additional query params
34+
:param raw: Return HTTPResponse object instead of results object
35+
:return: List of quotes
36+
:rtype: List[Quote]
37+
"""
38+
url = "/v1/marketstatus/now"
39+
40+
return self._get(path=url, params=params, deserializer=MarketStatus.from_dict, raw=raw)

0 commit comments

Comments
 (0)