tradingview_screener.models

 1from __future__ import annotations
 2
 3from typing import TypedDict, TYPE_CHECKING
 4
 5if TYPE_CHECKING:
 6    from typing_extensions import Any, Literal, NotRequired
 7
 8
 9class FilterOperationDict(TypedDict):
10    left: str
11    operation: Literal[
12        'greater',
13        'egreater',
14        'less',
15        'eless',
16        'equal',
17        'nequal',
18        'in_range',  # equivalent to SQL `BETWEEN` or `IN (...)`
19        'not_in_range',
20        'empty',
21        'nempty',
22        'crosses',
23        'crosses_above',
24        'crosses_below',
25        'match',  # the same as: `LOWER(col) LIKE '%pattern%'`
26        'nmatch',  # not match
27        # simple match, there is no method for this operation as of right now, because it does
28        # the same thing as `match`
29        'smatch',
30        'has',  # set must contain one of the values
31        'has_none_of',  # set must NOT contain ANY of the values
32        'above%',
33        'below%',
34        'in_range%',
35        'not_in_range%',
36        'in_day_range',
37        'in_week_range',
38        'in_month_range',
39    ]
40    right: Any  # its optional when the operation is `empty` or `nempty`
41
42
43class SortByDict(TypedDict):
44    sortBy: str
45    sortOrder: Literal['asc', 'desc']
46    nullsFirst: NotRequired[bool]
47
48
49class SymbolsDict(TypedDict, total=False):
50    query: dict[Literal['types'], list[str]]
51    tickers: list[str]
52    symbolset: list[str]
53    watchlist: dict[Literal['id'], int]
54    groups: list[dict[Literal['type', 'values'], str]]
55    # for example [{'type': 'index', 'values': ['DJ:DJU']}]
56
57
58class ExpressionDict(TypedDict):
59    expression: FilterOperationDict
60
61
62class OperationComparisonDict(TypedDict):
63    operator: Literal['and', 'or']
64    operands: list[OperationDict | ExpressionDict]
65
66
67class OperationDict(TypedDict):
68    operation: OperationComparisonDict
69
70
71class QueryDict(TypedDict, total=False):
72    """
73    The fields that can be passed to the tradingview scan API
74    """
75
76    markets: list[str]
77    symbols: SymbolsDict
78    options: dict[str, Any]  # example: `{"options": {"lang": "en"}}`
79    columns: list[str]
80    filter: list[FilterOperationDict]
81    filter2: OperationComparisonDict
82    sort: SortByDict
83    range: list[int]  # list with two integers, i.e. `[0, 100]`
84    ignore_unknown_fields: bool  # default false
85    preset: Literal['index_components_market_pages', 'pre-market-gainers']  # there are many
86    # other presets (these are just some a examples)
87    price_conversion: dict[Literal['to_symbol'], bool] | dict[
88        Literal['to_currency'], str  # this string should be the currency in lower-case
89    ]
90
91
92class ScreenerRowDict(TypedDict):
93    s: str  # symbol (NASDAQ:AAPL)
94    d: list  # data, list of values
95
96
97class ScreenerDict(TypedDict):
98    totalCount: int
99    data: list[ScreenerRowDict]
class FilterOperationDict(typing.TypedDict):
10class FilterOperationDict(TypedDict):
11    left: str
12    operation: Literal[
13        'greater',
14        'egreater',
15        'less',
16        'eless',
17        'equal',
18        'nequal',
19        'in_range',  # equivalent to SQL `BETWEEN` or `IN (...)`
20        'not_in_range',
21        'empty',
22        'nempty',
23        'crosses',
24        'crosses_above',
25        'crosses_below',
26        'match',  # the same as: `LOWER(col) LIKE '%pattern%'`
27        'nmatch',  # not match
28        # simple match, there is no method for this operation as of right now, because it does
29        # the same thing as `match`
30        'smatch',
31        'has',  # set must contain one of the values
32        'has_none_of',  # set must NOT contain ANY of the values
33        'above%',
34        'below%',
35        'in_range%',
36        'not_in_range%',
37        'in_day_range',
38        'in_week_range',
39        'in_month_range',
40    ]
41    right: Any  # its optional when the operation is `empty` or `nempty`
left: str
operation: Literal['greater', 'egreater', 'less', 'eless', 'equal', 'nequal', 'in_range', 'not_in_range', 'empty', 'nempty', 'crosses', 'crosses_above', 'crosses_below', 'match', 'nmatch', 'smatch', 'has', 'has_none_of', 'above%', 'below%', 'in_range%', 'not_in_range%', 'in_day_range', 'in_week_range', 'in_month_range']
right: Any
class SortByDict(typing.TypedDict):
44class SortByDict(TypedDict):
45    sortBy: str
46    sortOrder: Literal['asc', 'desc']
47    nullsFirst: NotRequired[bool]
sortBy: str
sortOrder: Literal['asc', 'desc']
nullsFirst: NotRequired[bool]
class SymbolsDict(typing.TypedDict):
50class SymbolsDict(TypedDict, total=False):
51    query: dict[Literal['types'], list[str]]
52    tickers: list[str]
53    symbolset: list[str]
54    watchlist: dict[Literal['id'], int]
55    groups: list[dict[Literal['type', 'values'], str]]
56    # for example [{'type': 'index', 'values': ['DJ:DJU']}]
query: dict[typing.Literal['types'], list[str]]
tickers: list[str]
symbolset: list[str]
watchlist: dict[typing.Literal['id'], int]
groups: list[dict[typing.Literal['type', 'values'], str]]
class ExpressionDict(typing.TypedDict):
59class ExpressionDict(TypedDict):
60    expression: FilterOperationDict
expression: FilterOperationDict
class OperationComparisonDict(typing.TypedDict):
63class OperationComparisonDict(TypedDict):
64    operator: Literal['and', 'or']
65    operands: list[OperationDict | ExpressionDict]
operator: Literal['and', 'or']
operands: list[OperationDict | ExpressionDict]
class OperationDict(typing.TypedDict):
68class OperationDict(TypedDict):
69    operation: OperationComparisonDict
class QueryDict(typing.TypedDict):
72class QueryDict(TypedDict, total=False):
73    """
74    The fields that can be passed to the tradingview scan API
75    """
76
77    markets: list[str]
78    symbols: SymbolsDict
79    options: dict[str, Any]  # example: `{"options": {"lang": "en"}}`
80    columns: list[str]
81    filter: list[FilterOperationDict]
82    filter2: OperationComparisonDict
83    sort: SortByDict
84    range: list[int]  # list with two integers, i.e. `[0, 100]`
85    ignore_unknown_fields: bool  # default false
86    preset: Literal['index_components_market_pages', 'pre-market-gainers']  # there are many
87    # other presets (these are just some a examples)
88    price_conversion: dict[Literal['to_symbol'], bool] | dict[
89        Literal['to_currency'], str  # this string should be the currency in lower-case
90    ]

The fields that can be passed to the tradingview scan API

markets: list[str]
symbols: SymbolsDict
options: dict[str, typing.Any]
columns: list[str]
filter: list[FilterOperationDict]
sort: SortByDict
range: list[int]
ignore_unknown_fields: bool
preset: Literal['index_components_market_pages', 'pre-market-gainers']
price_conversion: dict[typing.Literal['to_symbol'], bool] | dict[typing.Literal['to_currency'], str]
class ScreenerRowDict(typing.TypedDict):
93class ScreenerRowDict(TypedDict):
94    s: str  # symbol (NASDAQ:AAPL)
95    d: list  # data, list of values
s: str
d: list
class ScreenerDict(typing.TypedDict):
 98class ScreenerDict(TypedDict):
 99    totalCount: int
100    data: list[ScreenerRowDict]
totalCount: int
data: list[ScreenerRowDict]