tradingview_screener.screener

  1from __future__ import annotations
  2
  3import requests
  4
  5from tradingview_screener.query import Query
  6from tradingview_screener.constants import URL
  7
  8
  9DEFAULT_COLUMNS = ['name', 'close', 'volume', 'market_cap_basic']  # for the scanners
 10
 11
 12class Scanner:
 13    """
 14    This class contains some of the most common stock-screeners, to use them you just need to call
 15    `get_scanner_data()` on any given stock-screener.
 16
 17    Examples:
 18
 19    Get the full list of scanners:
 20    >>> from tradingview_screener import Scanner
 21    >>> Scanner.names()
 22    ['premarket_gainers',
 23     'premarket_losers',
 24     'premarket_most_active',
 25     'premarket_gappers',
 26     'postmarket_gainers',
 27     'postmarket_losers',
 28     'postmarket_most_active']
 29
 30    Get the Pre-Market gainers
 31    >>> Scanner.premarket_gainers.get_scanner_data()
 32    (18060,
 33              ticker  name  ...  premarket_change_abs  premarket_volume
 34     0   NASDAQ:APLM  APLM  ...               0.72200          30551043
 35     1      OTC:RNVA  RNVA  ...               0.00005            200000
 36     2      OTC:OCLN  OCLN  ...               0.00690            220000
 37     3   NASDAQ:BKYI  BKYI  ...               0.09740           8826676
 38     4    NASDAQ:ICU   ICU  ...               0.28790           7527703
 39     ..          ...   ...  ...                   ...               ...
 40     45     OTC:BSEM  BSEM  ...               0.25000               200
 41     46     NYSE:SWI   SWI  ...               0.76000              5425
 42     47     NYSE:BPT   BPT  ...               0.45000               380
 43     48    NYSE:HOUS  HOUS  ...               0.39000               200
 44     49   NASDAQ:HCM   HCM  ...               1.40000              1950
 45     [50 rows x 8 columns])
 46
 47    Get the most active tickers during the Post-Market session (highest volume)
 48    >>> Scanner.postmarket_most_active.get_scanner_data()
 49    (18060,
 50              ticker  name  ...  postmarket_change_abs  postmarket_volume
 51     0   NASDAQ:MCOM  MCOM  ...                -0.0001           12432509
 52     1   NASDAQ:AAPL  AAPL  ...                -0.2000           10364140
 53     2      AMEX:XLF   XLF  ...                -0.0100            8813170
 54     3      NYSE:BAC   BAC  ...                -0.0100            8741713
 55     4   NASDAQ:INTC  INTC  ...                -0.0600            8493758
 56     ..          ...   ...  ...                    ...                ...
 57     45      NYSE:PG    PG  ...                 0.2200            1895116
 58     46     NYSE:BMY   BMY  ...                -0.0700            1875806
 59     47  NASDAQ:TQQQ  TQQQ  ...                -0.0200            1870908
 60     48   NASDAQ:WBD   WBD  ...                -0.0003            1865705
 61     49    NYSE:SNAP  SNAP  ...                -0.0100            1852715
 62     [50 rows x 8 columns])
 63
 64    """
 65
 66    premarket_gainers = (
 67        Query()
 68        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 69        .order_by('premarket_change', ascending=False)
 70    )
 71    premarket_losers = (
 72        Query()
 73        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 74        .order_by('premarket_change', ascending=True)
 75    )
 76    premarket_most_active = (
 77        Query()
 78        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 79        .order_by('premarket_volume', ascending=False)
 80    )
 81    premarket_gappers = (
 82        Query()
 83        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 84        .order_by('premarket_gap', ascending=False)
 85    )
 86
 87    postmarket_gainers = (
 88        Query()
 89        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
 90        .order_by('postmarket_change', ascending=False)
 91    )
 92    postmarket_losers = (
 93        Query()
 94        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
 95        .order_by('postmarket_change', ascending=True)
 96    )
 97    postmarket_most_active = (
 98        Query()
 99        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
100        .order_by('postmarket_volume', ascending=False)
101    )
102
103    @classmethod
104    def names(cls) -> list[str]:
105        return [x for x in cls.__dict__.keys() if not x.startswith('_') and x != 'names']
106
107
108def get_all_symbols(market: str = 'america') -> list[str]:
109    """
110    Get all the symbols of a given market.
111
112    Examples:
113
114    >>> from tradingview_screener import get_all_symbols
115    >>> get_all_symbols()
116    ['OTC:BMVVF',
117     'OTC:BRQL',
118     'NYSE:EFC/PA',
119     'NASDAQ:NVCR',
120     'NASDAQ:OMIC',
121     ...
122
123    >>> len(get_all_symbols())
124    18060
125
126    The default market is `america`, but you can change it with any market from
127    `tradingview_screener.constants.MARKETS`:
128    >>> get_all_symbols(market='switzerland')
129    ['BX:UN01',
130     'BX:XFNT',
131     'BX:ZPDE',
132     'BX:0QF',
133     'BX:BSN',
134     ...
135
136    For instance, to get all the crypto tickers:
137    >>> get_all_symbols(market='crypto')
138    ['KRAKEN:KNCEUR',
139     'TRADERJOE:WETHEWAVAX_FE15C2',
140     'UNISWAP:DBIWETH_DEDF7B',
141     'KUCOIN:DIABTC',
142     'QUICKSWAP:WIXSWMATIC_F87B83.USD',
143     ...
144
145    >>> len(get_all_symbols(market='futures'))
146    75205
147
148    >>> len(get_all_symbols(market='bonds'))
149    1090
150
151    >>> len(get_all_symbols(market='germany'))
152    13251
153
154    >>> len(get_all_symbols(market='israel'))
155    1034
156
157    :param market: any market from `tradingview_screener.constants.MARKETS`, default 'america'
158    :return: list of tickers
159    """
160    r = requests.get(URL.format(market=market))
161    r.raise_for_status()
162    data = r.json()['data']  # [{'s': 'NYSE:HKD', 'd': []}, {'s': 'NASDAQ:ALTY', 'd': []}...]
163
164    return [dct['s'] for dct in data]
DEFAULT_COLUMNS = ['name', 'close', 'volume', 'market_cap_basic']
class Scanner:
 13class Scanner:
 14    """
 15    This class contains some of the most common stock-screeners, to use them you just need to call
 16    `get_scanner_data()` on any given stock-screener.
 17
 18    Examples:
 19
 20    Get the full list of scanners:
 21    >>> from tradingview_screener import Scanner
 22    >>> Scanner.names()
 23    ['premarket_gainers',
 24     'premarket_losers',
 25     'premarket_most_active',
 26     'premarket_gappers',
 27     'postmarket_gainers',
 28     'postmarket_losers',
 29     'postmarket_most_active']
 30
 31    Get the Pre-Market gainers
 32    >>> Scanner.premarket_gainers.get_scanner_data()
 33    (18060,
 34              ticker  name  ...  premarket_change_abs  premarket_volume
 35     0   NASDAQ:APLM  APLM  ...               0.72200          30551043
 36     1      OTC:RNVA  RNVA  ...               0.00005            200000
 37     2      OTC:OCLN  OCLN  ...               0.00690            220000
 38     3   NASDAQ:BKYI  BKYI  ...               0.09740           8826676
 39     4    NASDAQ:ICU   ICU  ...               0.28790           7527703
 40     ..          ...   ...  ...                   ...               ...
 41     45     OTC:BSEM  BSEM  ...               0.25000               200
 42     46     NYSE:SWI   SWI  ...               0.76000              5425
 43     47     NYSE:BPT   BPT  ...               0.45000               380
 44     48    NYSE:HOUS  HOUS  ...               0.39000               200
 45     49   NASDAQ:HCM   HCM  ...               1.40000              1950
 46     [50 rows x 8 columns])
 47
 48    Get the most active tickers during the Post-Market session (highest volume)
 49    >>> Scanner.postmarket_most_active.get_scanner_data()
 50    (18060,
 51              ticker  name  ...  postmarket_change_abs  postmarket_volume
 52     0   NASDAQ:MCOM  MCOM  ...                -0.0001           12432509
 53     1   NASDAQ:AAPL  AAPL  ...                -0.2000           10364140
 54     2      AMEX:XLF   XLF  ...                -0.0100            8813170
 55     3      NYSE:BAC   BAC  ...                -0.0100            8741713
 56     4   NASDAQ:INTC  INTC  ...                -0.0600            8493758
 57     ..          ...   ...  ...                    ...                ...
 58     45      NYSE:PG    PG  ...                 0.2200            1895116
 59     46     NYSE:BMY   BMY  ...                -0.0700            1875806
 60     47  NASDAQ:TQQQ  TQQQ  ...                -0.0200            1870908
 61     48   NASDAQ:WBD   WBD  ...                -0.0003            1865705
 62     49    NYSE:SNAP  SNAP  ...                -0.0100            1852715
 63     [50 rows x 8 columns])
 64
 65    """
 66
 67    premarket_gainers = (
 68        Query()
 69        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 70        .order_by('premarket_change', ascending=False)
 71    )
 72    premarket_losers = (
 73        Query()
 74        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 75        .order_by('premarket_change', ascending=True)
 76    )
 77    premarket_most_active = (
 78        Query()
 79        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 80        .order_by('premarket_volume', ascending=False)
 81    )
 82    premarket_gappers = (
 83        Query()
 84        .select(*DEFAULT_COLUMNS, 'premarket_change', 'premarket_change_abs', 'premarket_volume')
 85        .order_by('premarket_gap', ascending=False)
 86    )
 87
 88    postmarket_gainers = (
 89        Query()
 90        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
 91        .order_by('postmarket_change', ascending=False)
 92    )
 93    postmarket_losers = (
 94        Query()
 95        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
 96        .order_by('postmarket_change', ascending=True)
 97    )
 98    postmarket_most_active = (
 99        Query()
100        .select(*DEFAULT_COLUMNS, 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume')
101        .order_by('postmarket_volume', ascending=False)
102    )
103
104    @classmethod
105    def names(cls) -> list[str]:
106        return [x for x in cls.__dict__.keys() if not x.startswith('_') and x != 'names']

This class contains some of the most common stock-screeners, to use them you just need to call get_scanner_data() on any given stock-screener.

Examples:

Get the full list of scanners:

>>> from tradingview_screener import Scanner
>>> Scanner.names()
['premarket_gainers',
 'premarket_losers',
 'premarket_most_active',
 'premarket_gappers',
 'postmarket_gainers',
 'postmarket_losers',
 'postmarket_most_active']

Get the Pre-Market gainers

>>> Scanner.premarket_gainers.get_scanner_data()
(18060,
          ticker  name  ...  premarket_change_abs  premarket_volume
 0   NASDAQ:APLM  APLM  ...               0.72200          30551043
 1      OTC:RNVA  RNVA  ...               0.00005            200000
 2      OTC:OCLN  OCLN  ...               0.00690            220000
 3   NASDAQ:BKYI  BKYI  ...               0.09740           8826676
 4    NASDAQ:ICU   ICU  ...               0.28790           7527703
 ..          ...   ...  ...                   ...               ...
 45     OTC:BSEM  BSEM  ...               0.25000               200
 46     NYSE:SWI   SWI  ...               0.76000              5425
 47     NYSE:BPT   BPT  ...               0.45000               380
 48    NYSE:HOUS  HOUS  ...               0.39000               200
 49   NASDAQ:HCM   HCM  ...               1.40000              1950
 [50 rows x 8 columns])

Get the most active tickers during the Post-Market session (highest volume)

>>> Scanner.postmarket_most_active.get_scanner_data()
(18060,
          ticker  name  ...  postmarket_change_abs  postmarket_volume
 0   NASDAQ:MCOM  MCOM  ...                -0.0001           12432509
 1   NASDAQ:AAPL  AAPL  ...                -0.2000           10364140
 2      AMEX:XLF   XLF  ...                -0.0100            8813170
 3      NYSE:BAC   BAC  ...                -0.0100            8741713
 4   NASDAQ:INTC  INTC  ...                -0.0600            8493758
 ..          ...   ...  ...                    ...                ...
 45      NYSE:PG    PG  ...                 0.2200            1895116
 46     NYSE:BMY   BMY  ...                -0.0700            1875806
 47  NASDAQ:TQQQ  TQQQ  ...                -0.0200            1870908
 48   NASDAQ:WBD   WBD  ...                -0.0003            1865705
 49    NYSE:SNAP  SNAP  ...                -0.0100            1852715
 [50 rows x 8 columns])
premarket_gainers = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'premarket_change', 'premarket_change_abs', 'premarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'premarket_change', 'sortOrder': 'desc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
premarket_losers = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'premarket_change', 'premarket_change_abs', 'premarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'premarket_change', 'sortOrder': 'asc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
premarket_most_active = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'premarket_change', 'premarket_change_abs', 'premarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'premarket_volume', 'sortOrder': 'desc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
premarket_gappers = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'premarket_change', 'premarket_change_abs', 'premarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'premarket_gap', 'sortOrder': 'desc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
postmarket_gainers = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'postmarket_change', 'sortOrder': 'desc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
postmarket_losers = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'postmarket_change', 'sortOrder': 'asc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
postmarket_most_active = < {'columns': ['name', 'close', 'volume', 'market_cap_basic', 'postmarket_change', 'postmarket_change_abs', 'postmarket_volume'], 'markets': ['america'], 'options': {'lang': 'en'}, 'range': [0, 50], 'sort': {'sortBy': 'postmarket_volume', 'sortOrder': 'desc'}, 'symbols': {'query': {'types': []}, 'tickers': []}} >
@classmethod
def names(cls) -> list[str]:
104    @classmethod
105    def names(cls) -> list[str]:
106        return [x for x in cls.__dict__.keys() if not x.startswith('_') and x != 'names']
def get_all_symbols(market: str = 'america') -> list[str]:
109def get_all_symbols(market: str = 'america') -> list[str]:
110    """
111    Get all the symbols of a given market.
112
113    Examples:
114
115    >>> from tradingview_screener import get_all_symbols
116    >>> get_all_symbols()
117    ['OTC:BMVVF',
118     'OTC:BRQL',
119     'NYSE:EFC/PA',
120     'NASDAQ:NVCR',
121     'NASDAQ:OMIC',
122     ...
123
124    >>> len(get_all_symbols())
125    18060
126
127    The default market is `america`, but you can change it with any market from
128    `tradingview_screener.constants.MARKETS`:
129    >>> get_all_symbols(market='switzerland')
130    ['BX:UN01',
131     'BX:XFNT',
132     'BX:ZPDE',
133     'BX:0QF',
134     'BX:BSN',
135     ...
136
137    For instance, to get all the crypto tickers:
138    >>> get_all_symbols(market='crypto')
139    ['KRAKEN:KNCEUR',
140     'TRADERJOE:WETHEWAVAX_FE15C2',
141     'UNISWAP:DBIWETH_DEDF7B',
142     'KUCOIN:DIABTC',
143     'QUICKSWAP:WIXSWMATIC_F87B83.USD',
144     ...
145
146    >>> len(get_all_symbols(market='futures'))
147    75205
148
149    >>> len(get_all_symbols(market='bonds'))
150    1090
151
152    >>> len(get_all_symbols(market='germany'))
153    13251
154
155    >>> len(get_all_symbols(market='israel'))
156    1034
157
158    :param market: any market from `tradingview_screener.constants.MARKETS`, default 'america'
159    :return: list of tickers
160    """
161    r = requests.get(URL.format(market=market))
162    r.raise_for_status()
163    data = r.json()['data']  # [{'s': 'NYSE:HKD', 'd': []}, {'s': 'NASDAQ:ALTY', 'd': []}...]
164
165    return [dct['s'] for dct in data]

Get all the symbols of a given market.

Examples:

>>> from tradingview_screener import get_all_symbols
>>> get_all_symbols()
['OTC:BMVVF',
 'OTC:BRQL',
 'NYSE:EFC/PA',
 'NASDAQ:NVCR',
 'NASDAQ:OMIC',
 ...
>>> len(get_all_symbols())
18060

The default market is america, but you can change it with any market from tradingview_screener.constants.MARKETS:

>>> get_all_symbols(market='switzerland')
['BX:UN01',
 'BX:XFNT',
 'BX:ZPDE',
 'BX:0QF',
 'BX:BSN',
 ...

For instance, to get all the crypto tickers:

>>> get_all_symbols(market='crypto')
['KRAKEN:KNCEUR',
 'TRADERJOE:WETHEWAVAX_FE15C2',
 'UNISWAP:DBIWETH_DEDF7B',
 'KUCOIN:DIABTC',
 'QUICKSWAP:WIXSWMATIC_F87B83.USD',
 ...
>>> len(get_all_symbols(market='futures'))
75205
>>> len(get_all_symbols(market='bonds'))
1090
>>> len(get_all_symbols(market='germany'))
13251
>>> len(get_all_symbols(market='israel'))
1034
Parameters
Returns

list of tickers