Skip to content

tv module

Module with TVData.


FIELD_LIST list

List of fields supported by the market scanner (list may be incomplete).


MARKET_LIST list

List of markets supported by the market scanner (list may be incomplete).


ORIGIN_URL str

Origin URL.


PRO_WS_URL str

Websocket URL (Pro).


REFERER_URL str

Referer URL.


SCAN_URL str

Market scanner URL.


SEARCH_URL str

Symbol search URL.


SIGNIN_URL str

Sign-in URL.


USER_AGENT str

User agent.


WS_TIMEOUT int

Websocket timeout.


WS_URL str

Websocket URL.


TVClient class

TVClient(
    username=None,
    password=None,
    auth_token=None,
    **kwargs
)

Client for TradingView.

Client for TradingView.

Superclasses

Inherited members


auth class method

TVClient.auth(
    username=None,
    password=None
)

Authenticate.


auth_token property

Authentication token.


chart_session property

Chart session.


construct_message class method

TVClient.construct_message(
    func,
    param_list
)

Construct a message.


convert_raw_data class method

TVClient.convert_raw_data(
    raw_data,
    symbol
)

Process raw data into a DataFrame.


create_connection method

TVClient.create_connection(
    pro_data=True
)

Create a websocket connection.


create_message method

TVClient.create_message(
    func,
    param_list
)

Create a message.


filter_raw_message class method

TVClient.filter_raw_message(
    text
)

Filter raw message.


format_symbol class method

TVClient.format_symbol(
    symbol,
    exchange,
    fut_contract=None
)

Format a symbol.


generate_chart_session class method

TVClient.generate_chart_session()

Generate chart session.


generate_session class method

TVClient.generate_session()

Generate session.


get_hist method

TVClient.get_hist(
    symbol,
    exchange='NSE',
    interval='1D',
    fut_contract=None,
    adjustment='splits',
    extended_session=False,
    pro_data=True,
    limit=20000,
    return_raw=False
)

Get historical data.


prepend_header class method

TVClient.prepend_header(
    st
)

Prepend a header.


scan_symbols class method

TVClient.scan_symbols(
    market=None,
    **kwargs
)

Scan symbols in a region/market.


search_symbol class method

TVClient.search_symbol(
    text=None,
    exchange=None,
    pages=None,
    delay=None,
    retries=3,
    show_progress=True,
    pbar_kwargs=None
)

Search for a symbol.


send_message method

TVClient.send_message(
    func,
    param_list
)

Send a message.


session property

Session.


ws property

Instance of websocket.Websocket.


TVData class

TVData(
    wrapper,
    data,
    single_key=True,
    classes=None,
    level_name=None,
    fetch_kwargs=None,
    returned_kwargs=None,
    last_index=None,
    delisted=None,
    tz_localize=None,
    tz_convert=None,
    missing_index=None,
    missing_columns=None,
    **kwargs
)

Data class for fetching from TradingView.

See TVData.fetch_symbol() for arguments.

Note

If you're getting the error "Please confirm that you are not a robot by clicking the captcha box." when attempting to authenticate, use auth_token instead of username and password. To get the authentication token, go to TradingView, log in, visit any chart, open your console's developer tools, and search for "auth_token".

Usage

  • Set up the credentials globally (optional):
>>> from vectorbtpro import *

>>> vbt.TVData.set_custom_settings(
...     client_config=dict(
...         username="YOUR_USERNAME",
...         password="YOUR_PASSWORD",
...         auth_token="YOUR_AUTH_TOKEN",  # optional, instead of username and password
...     )
... )
  • Pull data:
>>> data = vbt.TVData.pull(
...     "NASDAQ:AAPL",
...     timeframe="1 hour"
... )

Superclasses

Inherited members


fetch_symbol class method

TVData.fetch_symbol(
    symbol,
    client=None,
    client_config=None,
    exchange=None,
    timeframe=None,
    tz=None,
    fut_contract=None,
    adjustment=None,
    extended_session=None,
    pro_data=None,
    limit=None,
    delay=None,
    retries=None
)

Override Data.fetch_symbol() to fetch a symbol from TradingView.

Args

symbol : str

Symbol.

Symbol must be in the EXCHANGE:SYMBOL format if exchange is None.

client : TVClient

Client.

See TVData.resolve_client().

client_config : dict

Client config.

See TVData.resolve_client().

exchange : str

Exchange.

Can be omitted if already provided via symbol.

timeframe : str

Timeframe.

Allows human-readable strings such as "15 minutes".

tz : any

Timezone.

See to_timezone().

fut_contract : int
None for cash, 1 for continuous current contract in front, 2 for continuous next contract in front.
adjustment : str

Adjustment.

Either "splits" (default) or "dividends".

extended_session : bool
Regular session if False, extended session if True.
pro_data : bool
Whether to use pro data.
limit : int
The maximum number of returned items.
delay : float
Time to sleep after each request (in seconds).
retries : int
The number of retries on failure to fetch data.

For defaults, see custom.tv in data.


list_symbols class method

TVData.list_symbols(
    *,
    exchange_pattern=None,
    symbol_pattern=None,
    use_regex=False,
    sort=True,
    client=None,
    client_config=None,
    text=None,
    exchange=None,
    pages=None,
    delay=None,
    retries=None,
    show_progress=None,
    pbar_kwargs=None,
    market=None,
    markets=None,
    fields=None,
    filter_by=None,
    groups=None,
    template_context=None,
    return_field_data=False,
    **scanner_kwargs
)

List all symbols.

Uses symbol search when either text or exchange is provided (returns a subset of symbols). Otherwise, uses the market scanner (returns all symbols, big payload).

When using the market scanner, use market to filter by one or multiple markets. For the list of available markets, see MARKET_LIST.

Use fields to make the market scanner return additional information that can be used for filtering with filter_by. Such information is passed to the function as a dictionary where fields are keys. The function can also be a template that can use the same information provided as a context, or a list of values that should be matched against the values corresponding to their fields. For the list of available fields, see FIELD_LIST. Argument fields can also be "all". Set return_field_data to True to return a list with (filtered) field data.

Use groups to provide a single dictionary or a list of dictionaries with groups. Each dictionary can be provided either in a compressed format, such as dict(index=index), or in a full format, such as dict(type="index", values=[index]).

Keyword arguments scanner_kwargs are encoded and passed directly to the market scanner.

Uses CustomData.key_match() to check each exchange against exchange_pattern and each symbol against symbol_pattern.

Usage

  • List all symbols (market scanner):
>>> from vectorbtpro import *

>>> vbt.TVData.list_symbols()
  • Search for symbols matching a pattern (market scanner, client-side):
>>> vbt.TVData.list_symbols(symbol_pattern="BTC*")
  • Search for exchanges matching a pattern (market scanner, client-side):
>>> vbt.TVData.list_symbols(exchange_pattern="NASDAQ")
  • Search for symbols containing a text (symbol search, server-side):
>>> vbt.TVData.list_symbols(text="BTC")
  • List symbols from an exchange (symbol search):
>>> vbt.TVData.list_symbols(exchange="NASDAQ")
  • List symbols from a market (market scanner):
>>> vbt.TVData.list_symbols(market="poland")
  • List index constituents (market scanner):
>>> vbt.TVData.list_symbols(groups=dict(index="NASDAQ:NDX"))
  • Filter symbols by fields using a function (market scanner):
>>> vbt.TVData.list_symbols(
...     market="america",
...     fields=["sector"],
...     filter_by=lambda context: context["sector"] == "Technology Services"
... )
  • Filter symbols by fields using a template (market scanner):
>>> vbt.TVData.list_symbols(
...     market="america",
...     fields=["sector"],
...     filter_by=vbt.RepEval("sector == 'Technology Services'")
... )

resolve_client class method

TVData.resolve_client(
    client=None,
    **client_config
)

Resolve the client.

If provided, must be of the type TVClient. Otherwise, will be created using client_config.