|
1 | 1 | from .base import BaseClient
|
2 |
| -from typing import Optional, Any, Dict, List, Union |
| 2 | +from typing import Optional, Any, Dict, List, Union, Iterator |
3 | 3 | from .models import Agg, GroupedDailyAgg, DailyOpenCloseAgg, PreviousCloseAgg, Sort
|
4 | 4 | from urllib3 import HTTPResponse
|
5 | 5 | from datetime import datetime, date
|
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class AggsClient(BaseClient):
|
| 11 | + def list_aggs( |
| 12 | + self, |
| 13 | + ticker: str, |
| 14 | + multiplier: int, |
| 15 | + timespan: str, |
| 16 | + # "from" is a keyword in python https://www.w3schools.com/python/python_ref_keywords.asp |
| 17 | + from_: Union[str, int, datetime, date], |
| 18 | + to: Union[str, int, datetime, date], |
| 19 | + adjusted: Optional[bool] = None, |
| 20 | + sort: Optional[Union[str, Sort]] = None, |
| 21 | + limit: Optional[int] = None, |
| 22 | + params: Optional[Dict[str, Any]] = None, |
| 23 | + raw: bool = False, |
| 24 | + options: Optional[RequestOptionBuilder] = None, |
| 25 | + ) -> Union[Iterator[Agg], HTTPResponse]: |
| 26 | + """ |
| 27 | + List aggregate bars for a ticker over a given date range in custom time window sizes. |
| 28 | +
|
| 29 | + :param ticker: The ticker symbol. |
| 30 | + :param multiplier: The size of the timespan multiplier. |
| 31 | + :param timespan: The size of the time window. |
| 32 | + :param from_: The start of the aggregate time window as YYYY-MM-DD, a date, Unix MS Timestamp, or a datetime. |
| 33 | + :param to: The end of the aggregate time window as YYYY-MM-DD, a date, Unix MS Timestamp, or a datetime. |
| 34 | + :param adjusted: Whether or not the results are adjusted for splits. By default, results are adjusted. Set this to false to get results that are NOT adjusted for splits. |
| 35 | + :param sort: Sort the results by timestamp. asc will return results in ascending order (oldest at the top), desc will return results in descending order (newest at the top).The end of the aggregate time window. |
| 36 | + :param limit: Limits the number of base aggregates queried to create the aggregate results. Max 50000 and Default 5000. Read more about how limit is used to calculate aggregate results in our article on Aggregate Data API Improvements. |
| 37 | + :param params: Any additional query params |
| 38 | + :param raw: Return raw object instead of results object |
| 39 | + :return: Iterator of aggregates |
| 40 | + """ |
| 41 | + if isinstance(from_, datetime): |
| 42 | + from_ = int(from_.timestamp() * self.time_mult("millis")) |
| 43 | + |
| 44 | + if isinstance(to, datetime): |
| 45 | + to = int(to.timestamp() * self.time_mult("millis")) |
| 46 | + url = f"/v2/aggs/ticker/{ticker}/range/{multiplier}/{timespan}/{from_}/{to}" |
| 47 | + |
| 48 | + return self._paginate( |
| 49 | + path=url, |
| 50 | + params=self._get_params(self.list_aggs, locals()), |
| 51 | + raw=raw, |
| 52 | + deserializer=Agg.from_dict, |
| 53 | + options=options, |
| 54 | + ) |
| 55 | + |
11 | 56 | def get_aggs(
|
12 | 57 | self,
|
13 | 58 | ticker: str,
|
|
0 commit comments