btgsolutions_dataservices.rest package¶
Submodules¶
btgsolutions_dataservices.rest.authenticator module¶
btgsolutions_dataservices.rest.bulk_data module¶
- class btgsolutions_dataservices.rest.bulk_data.BulkData(api_key: Optional[str])[source]¶
Bases:
object
This class provides market data by ticker and date, in .csv format
Main use case:
>>> from btgsolutions_dataservices import BulkData >>> bulk_data = BulkData( >>> api_key='YOUR_API_KEY', >>> ) >>> bulk_data.get_data( >>> ticker = 'DI1F18', >>> date = '2017-01-02', >>> data_type = 'trades', >>> raw_data = False >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_available_tickers(date: str, data_type: str, prefix: str = '')[source]¶
This method provides all tickers available for query, for the provided market data type.
- Parameters
date (str) – Date period. Field is required. Format: ‘YYYY-MM-DD’. Example: ‘2023-07-03’.
data_type (str) – Market data type. Field is required. Example: ‘trades’, ‘books’ or ‘trades-and-book-events’.
prefix (str) – Filters tickers starting with the prefix. Field is optional. Example: ‘DOL’.
- get_compressed_data(channel: str, date: str, data_type: str = 'instruments', binary: bool = False)[source]¶
This method provides market data via compressed files (instruments, snapshot, incremental) for a given market data channel and date. Function get_market_data_channels provides all the available channels for a given date.
- Parameters
channel (str) – Market Data channel. Field is required. Example: ‘001’.
date (str) – Date period. Field is required. Format: ‘YYYY-MM-DD’. Example: ‘2023-07-03’, ‘2023-07-28’.
data_type (str) – Market data type. Field is required. Example: ‘instruments’, ‘snapshot’, ‘incremental’.
binary (bool) – If true, returns binary data. If false, returns FIX/FAST data. Field is not required. Default: false.
- get_data(ticker: str, date: str, data_type: str = 'trades', raw_data: bool = False)[source]¶
This method provides tick-by-tick market data (trades, book events, book snapshots) for a given ticker and date.
- Parameters
ticker (str) – Ticker that needs to be returned. Field is required. Example: ‘DI1F18’.
date (str) – Date period. Field is required. Format: ‘YYYY-MM-DD’. Example: ‘2023-07-03’, ‘2023-07-28’.
data_type (str) – Market data type. Field is required. Available types: ‘trades’, ‘books’, ‘trades-and-book-events’
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
- get_market_data_channels(date: str)[source]¶
This method provides all the available market data channels for a given date. For more detailed information about market data channels, please consult our documentation, at https://dataservicesdocs.btgpactualsolutions.com/home > Data Specs > Market Data channel definition.
- Parameters
date (str) – Date period. Field is required. Format: ‘YYYY-MM-DD’. Example: ‘2023-07-03’, ‘2023-07-28’.
btgsolutions_dataservices.rest.company_data module¶
- class btgsolutions_dataservices.rest.company_data.CompanyData(api_key: Optional[str])[source]¶
Bases:
object
This class provides company general information and fundamentalist data.
Main use case:
>>> from btgsolutions_dataservices import CompanyData >>> company_data = CompanyData( >>> api_key='YOUR_API_KEY', >>> ) >>> company_data.general_info( >>> ticker = 'PETR4' >>> ) >>> company_data.income_statement( >>> ticker = 'PETR4' >>> ) >>> company_data.balance_sheet( >>> ticker = 'PETR4' >>> ) >>> company_data.cash_flow( >>> ticker = 'PETR4' >>> ) >>> company_data.valuation( >>> ticker = 'PETR4' >>> ) >>> company_data.ratios( >>> ticker = 'PETR4' >>> ) >>> company_data.growth( >>> ticker = 'PETR4' >>> ) >>> company_data.interims( >>> ticker = 'PETR4' >>> ) >>> company_data.all_financial_tables( >>> ticker = 'PETR4' >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- all_financial_tables(ticker: str, raw_data: bool = False)[source]¶
This method returns all available financial tables (such as Valuation, Income Statement, Cash Flow) for the requested company ticker.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
raw_data (bool) – If false, returns financial tables in dataframes. If true, returns raw data. Field is not required. Default: False.
- balance_sheet(ticker: str)[source]¶
This method returns the company Balance Sheet.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
- cash_flow(ticker: str)[source]¶
This method returns the company Cash Flow.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
- general_info(ticker: str, raw_data: bool = False)[source]¶
This method returns company general information such as name, ticker, sector, description.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: ‘PETR4’.
raw_data (bool) – If false, returns financial tables in dataframes. If true, returns raw data. Field is not required. Default: False.
- growth(ticker: str)[source]¶
This method returns the company Growth.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
- income_statement(ticker: str)[source]¶
This method returns the company Income Statement.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
- interims(ticker: str)[source]¶
This method returns the company Interims.
- Parameters
ticker (str) – Company ticker symbol. Field is required. Example: “PETR4”. The ticker radical is also allowed. Example: “PETR”.
btgsolutions_dataservices.rest.corporate_events module¶
- class btgsolutions_dataservices.rest.corporate_events.CorporateEvents(api_key: Optional[str])[source]¶
Bases:
object
This class provides the market data corporate events
Main use case:
>>> from btgsolutions_dataservices import CorporateEvents >>> corporate_events = CorporateEvents( >>> api_key='YOUR_API_KEY', >>> ) >>> corporate_events.get( >>> start_date = '2024-05-10', >>> end_date = '2024-05-31', >>> tickers = ['PETR4'] >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get(start_date: str, end_date: str, tickers: List[str] = [], raw_data: bool = False)[source]¶
This method uses corporate events filtered by a range of dates (ex_date) and a list of tickers
- Parameters
start_date (string<date>) – Lower bound for corporate events. Filtering by ex_date. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-10-06’.
end_date (string<date>) – Upper bound for corporate events. Filtering by ex_date. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-10-06’.
ticker (List[str]) – List of tickers. Field is not required. Example: [‘PETR4’, ‘VALE3’]. Default: [].
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
btgsolutions_dataservices.rest.hfn module¶
- class btgsolutions_dataservices.rest.hfn.HighFrequencyNews(api_key: Optional[str])[source]¶
Bases:
object
This class provides realtime and historical news of several news .
Main use case:
>>> from btgsolutions_dataservices import HighFrequencyNews
>>> hfn = HighFrequencyNews( >>> api_key='YOUR_API_KEY', >>> ) >>> latest_news = hfn.latest_news( >>> n = 15, >>> )
>>> petro_news = hfn.filter_news( >>> ticker = 'PETR4', >>> )
>>> ibov_news = hfn.filter_news( >>> tag = 'IBOV', >>> )
>>> news_21_08 = hfn.historical_news( >>> start_date = '2023-08-21', >>> end_date = '2023-08-22', >>> )
>>> available_feeds = hfn.get_available_feeds() >>> available_sources = hfn.get_available_sources() >>> available_tickers = hfn.get_available_tickers() >>> available_tags = hfn.get_available_tags()
- Parameters
api_key (str) – User identification key. Field is required.
- filter_news(ticker: Optional[str] = None, tag: Optional[str] = None, force: bool = True, country: str = 'brazil', raw_data: bool = False)[source]¶
Filter news by ticker or tag. If both ticker and tag are provided, the filter will be by ticker only
- Parameters
ticker (str) – Ticker symbol. Will be used to filter news. Example: ‘VALE3’, ‘PETR4’. Field is not required.
tag (str) – Tag name. Will be used to filter news. Example: ‘IBOV’, ‘TESOURO’, ‘RENDA_FIXA’. Field is not required.
force (bool) – Force to return news even if it does not match the requested parameters. Default: True Example: True, False. Field is required.
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
raw_data (bool) – If True, returns raw data from API, if False, returns a Pandas DataFrame. Default: False. Field is not required.
- get_available_feeds(country: str = 'brazil')[source]¶
This method provides all feeds available for query.
- Parameters
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
- get_available_sources(country: str = 'brazil')[source]¶
This method provides all sources available for query.
- Parameters
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
- get_available_tags(country: str = 'brazil')[source]¶
This method provides all tags available for query.
- Parameters
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
- get_available_tickers(country: str = 'brazil')[source]¶
This method provides all tickers available for query.
- Parameters
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
- historical_news(start_date: str, end_date: str, feed: str = 'raw', country: str = 'brazil', raw_data: bool = False)[source]¶
Provide a datetime interval and get all the news registered on that interval. The interval between start_date and end_date must be 24 hours maximum.
- Parameters
start_date (str) – Upper bound for news publishing time. Supported formats: ISO Date (YYYY-MM-DD), Long Date (MMM DD YYYY), Short Date (MM/DD/YYYY). Example: ‘2023-08-21’. Field is required.
end_date (str) – Lower bound for news publishing time. Supported formats: ISO Date (YYYY-MM-DD), Long Date (MMM DD YYYY), Short Date (MM/DD/YYYY). Example: ‘2023-08-22’. Field is required.
feed (str) – Feed name. Default: ‘raw’ Example: ‘raw’, ‘economy’, ‘politics’, ‘crypto’, ‘cvm’. Field is required.
country (str) – Country name. Default: ‘brazil’ Example: ‘brazil’, ‘chile’. Field is required.
raw_data (bool) – If True, returns raw data from API, if False, returns a Pandas DataFrame. Default: False. Field is not required.
- latest_news(feed: str = 'raw', country: str = 'brazil', n: int = 10, raw_data: bool = False)[source]¶
Latest news by feed.
- Parameters
feed (str) – News feed. Example: ‘raw’, ‘economy’, ‘politics’, ‘crypto’, ‘cvm’. Default: ‘raw’. Field is not required.
country (str) – Country name. Example: ‘brazil’, ‘chile’. Default: ‘brazil’. Field is not required.
n (int) – Number of news to be returned. Default: 10. Field is not required.
raw_data (bool) – If True, returns raw data from API, if False, returns a Pandas DataFrame. Default: False. Field is not required.
btgsolutions_dataservices.rest.historical_candles module¶
- class btgsolutions_dataservices.rest.historical_candles.HistoricalCandles(api_key: Optional[str])[source]¶
Bases:
object
This class provides historical candles for a given ticker or all tickers available for query.
Main use case - Interday:
>>> from btgsolutions_dataservices import HistoricalCandles >>> hist_candles = HistoricalCandles( >>> api_key='YOUR_API_KEY', >>> ) >>> hist_candles.get_interday_history_candles( >>> ticker = 'PETR4', >>> market_type = 'stocks', >>> corporate_events_adj = True, >>> start_date = '2023-10-11', >>> end_date = '2023-10-20', >>> rmv_after_market = True, >>> timezone = 'UTC', >>> raw_data = False >>> )
Main use case - Intraday:
>>> hist_candles.get_intraday_history_candles( >>> ticker = 'PETR4', >>> market_type = 'stocks', >>> corporate_events_adj = True, >>> date = '2023-10-20', >>> rmv_after_market = True, >>> timezone = 'UTC', >>> candle='1m', >>> raw_data = False >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_interday_history_candles(market_type: str, ticker: str, start_date: str, end_date: str, corporate_events_adj: bool, rmv_after_market: bool, timezone: str, raw_data: bool = False)[source]¶
This method provides historical candles for a given ticket in determined period.
- Parameters
market_type (str) – Field is required. Allowed values: ‘stocks’ or ‘derivatives’.
ticker (str) – Ticker that needs to be returned. Field is required. Example: ‘PETR4’.
start_date (string<date>) – Start date of analysis. Format: “YYYY-MM-DD”. Field is required. Example: ‘2022-10-06’.
end_date (string<date>) – End date of analysis. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-01-22’.
corporate_events_adj (bool) – Corporate events adjustment. Field is required. Allowed values: ‘true’ or ‘false’.
rmv_after_market (bool) – Remove trades after market close. Field is required. Allowed values: ‘true’ or ‘false’.
timezone (str) – Timezone of the datetime. Field is required. Allowed values: ‘America/Sao_Paulo’ or ‘UTC’.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
- get_intraday_history_candles(market_type: str, ticker: str, date: str, candle: str, corporate_events_adj: bool, rmv_after_market: bool, timezone: str, raw_data: bool = False)[source]¶
This method provides historical candles for a given ticket in determined period.
- Parameters
market_type (str) – Field is required. Allowed values: ‘stocks’ or ‘derivatives’.
ticker (str) – Ticker that needs to be returned. Field is required. Example: ‘PETR4’.
date (string<date>) – Date of requested data. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-10-06’.
candle (str) – Candle period. Field is required. Allowed values: ‘1s’, ‘1m’, ‘5m’, ‘15m’, ‘30m’ or ‘1h’.
corporate_events_adj (bool) – Corporate events adjustment. Field is required. Allowed values: ‘true’ or ‘false’.
rmv_after_market (bool) – Remove trades after market close. Field is required. Allowed values: ‘true’ or ‘false’.
timezone (str) – Timezone of the datetime. Field is required. Allowed values: ‘America/Sao_Paulo’ or ‘UTC’.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
btgsolutions_dataservices.rest.intraday_candles module¶
- class btgsolutions_dataservices.rest.intraday_candles.IntradayCandles(api_key: Optional[str])[source]¶
Bases:
object
This class provides realtime intraday candles for a given ticker or all tickers available for query.
Main use case:
>>> from btgsolutions_dataservices import IntradayCandles >>> intraday_candles = IntradayCandles( >>> api_key='YOUR_API_KEY', >>> ) >>> candles = intraday_candles.get_intraday_candles( >>> market_type = 'stocks', >>> tickers = ['PETR4', 'ABEV3'], >>> candle_period = '1m', >>> delay='delayed', >>> mode='absolute', >>> timezone='UTC', >>> raw_data=False >>> ) >>> PETR4 = candles.get('PETR4') >>> ABEV3 = candles.get('ABEV3')
>>> intraday_candles.get_available_tickers( >>> market_type='stocks', >>> delay='delayed' >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_available_tickers(market_type: str, delay: str)[source]¶
This method provides all tickers available for query.
- Parameters
market_type (str) – Market type. Options: ‘stocks’, ‘derivatives’ or ‘options’. Field is required.
delay (str) – Data delay. Options: ‘delayed’ or ‘realtime’. Field is required.
- get_intraday_candles(market_type: str, tickers: list, delay: str, timezone: str, candle_period: str, start: int = 0, end: int = 0, mode: str = 'absolute', raw_data: bool = False)[source]¶
This method provides realtime intraday candles for a given ticker.
- Parameters
market_type (str) – Market type. Options: ‘stocks’, ‘derivatives’, ‘options’ or ‘indices’. Field is required.
tickers (list of str) – Tickers that needs to be returned. Example: [‘PETR4’, ‘ABEV3’] Field is required.
delay (str) – Data delay. Options: ‘delayed’ or ‘realtime’. Field is required.
timezone (str) – Timezone of the datetime. Options: ‘America/Sao_Paulo’ or ‘UTC’. Field is required.
candle_period (str) – Grouping interval. Example: ‘1m’, ‘5m’, ‘30m’, ‘1h’ or ‘1d’. Field is required.
start (int) – Start date (in Unix timestamp format).
end (int) – End date (in Unix timestamp format)
mode (str) – Candle mode. Example: ‘absolute’, ‘relative’ or ‘spark’. Default: absolute.
raw_data (bool) – If false, returns data in a dict of dataframes. If true, returns raw data. Default: False.
btgsolutions_dataservices.rest.intraday_tick_data module¶
- class btgsolutions_dataservices.rest.intraday_tick_data.IntradayTickData(api_key: Optional[str])[source]¶
Bases:
object
This class provides tick-by-tick market data from the current day, for the provided ticker
Main use case:
>>> from btgsolutions_dataservices import IntradayTickData >>> tick_data = IntradayTickData( >>> api_key='YOUR_API_KEY', >>> )
>>> tick_data.get_trades( >>> ticker = 'PETR4', >>> raw_data = False >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_trades(ticker: str, raw_data: bool = False)[source]¶
This method provides tick-by-tick trade data from the current day, for the provided ticker.
- Parameters
ticker (str) – Ticker symbol. Field is required. Example: ‘PETR4’.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
btgsolutions_dataservices.rest.public_sources module¶
- class btgsolutions_dataservices.rest.public_sources.PublicSources(api_key: str)[source]¶
Bases:
object
This class provides data from public sources
Main use case:
>>> from btgsolutions_dataservices import PublicSources >>> public_sources = PublicSources( >>> api_key='YOUR_API_KEY', >>> ) >>> public_sources.get_opas( >>> start_date = '2024-05-10', >>> end_date = '2024-05-31' >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_opas(start_date: str, end_date: str, asset: Optional[str] = None, type: Optional[str] = None, raw_data: bool = False)[source]¶
This method uses OPAs filtered by a range of dates (registration_date), asset or type.
- Parameters
start_date (string<date>) – Lower bound for OPAS. Filtering by registration_date. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-10-06’.
end_date (string<date>) – Upper bound for OPAS. Filtering by registration_date. Format: “YYYY-MM-DD”. Field is required. Example: ‘2023-10-06’.
asset (str) – Ticker asset. Field is not required. Example: VALE. Default: None.
type (str) – Filtering by OPA type Field is not required. Example: VOLUNTARIO. Default: None.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
btgsolutions_dataservices.rest.quotes module¶
- class btgsolutions_dataservices.rest.quotes.Quotes(api_key: Optional[str])[source]¶
Bases:
object
This class provides ticker quote information and quotes sorted by top-bottom quote variation, filtered by ticker market type.
Main use case:
>>> from btgsolutions_dataservices import Quotes >>> quotes = Quotes( >>> api_key='YOUR_API_KEY', >>> )
>>> quotes.get_quote( >>> market_type = 'stocks', >>> tickers = ['PETR4', 'VALE3'], >>> )
>>> quotes.get_top_bottom( >>> market_type = 'stocks', >>> ticker_type = 'IBOV', >>> )
>>> quotes.get_available_tickers(market_type="stocks")
- Parameters
api_key (str) – User identification key. Field is required.
- get_available_tickers(market_type: str, mode: str = 'realtime')[source]¶
This method provides all tickers available for query, for the provided market type.
- Parameters
market_type (str) – Market type. Field is required. Example: ‘stocks’, ‘options’, ‘derivatives’.
mode (str) – Realtime or 15-minutes delayed. Field is not required. Example: ‘realtime’ or ‘delayed’. Default: ‘realtime’.
- get_quote(tickers: list, market_type: str, mode: str = 'realtime', raw_data: bool = False)[source]¶
This method provides realtime and delayed quote information for a given ticker.
- Parameters
tickers (list) – List of tickers that needs to be returned. Field is required. Example: [‘VALE3’], [‘PETR4’, ‘PRIO3’].
market_type (str) – Market type. Field is required. Example: ‘stocks’, ‘options’, ‘derivatives’.
mode (str) – Realtime or 15-minutes delayed. Field is required. Example: ‘realtime’ or ‘delayed’. Default: ‘realtime’.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
- get_top_bottom(market_type: str, mode: str = 'realtime', ticker_type: str = 'IBOV', variation: str = 'interday', n: int = 5, raw_data: bool = False)[source]¶
This method provides realtime and delayed quotes sorted by top-bottom quote variation, filtered by ticker market type.
- Parameters
market_type (str) – Market type. Field is required. Example: ‘stocks’, ‘options’, ‘derivatives’.
mode (str) – Realtime or 15-minutes delayed. Field is not required. Example: ‘realtime’ or ‘delayed’. Default: ‘realtime’.
ticker_type (str) – Type of tickers to be returned. Field is not required. Example: ‘SHARE’, ‘BDR’, ‘FII’, ‘ETF’, ‘UNIT’, ‘IBOV’. Default: ‘IBOV’.
variation (str) – Choose between intraday or interday quotes. Field is not required. Example: ‘interday’ or ‘intraday’. Default: ‘interday’.
n (int) – Top-N tickers to be returned. Field is not required. Default: 5.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.
btgsolutions_dataservices.rest.ticker_last_event module¶
- class btgsolutions_dataservices.rest.ticker_last_event.TickerLastEvent(api_key: Optional[str])[source]¶
Bases:
object
This class provides the last market data event available, for the provided ticker
Main use case:
>>> from btgsolutions_dataservices import TickerLastEvent >>> last_event = TickerLastEvent( >>> api_key='YOUR_API_KEY', >>> )
>>> last_event.get_trades( >>> ticker = 'PETR4', >>> raw_data = False >>> )
- Parameters
api_key (str) – User identification key. Field is required.
- get_available_tickers(data_type: str)[source]¶
This method provides all the available tickers for the specific data type.
- Parameters
data_type (str) – Market Data Type. Field is required. Example: ‘equities’, ‘derivatives’.
- get_trades(data_type: str, ticker: str, raw_data: bool = False)[source]¶
This method provides the last market data event available, for the provided ticker.
- Parameters
data_type (str) – Market Data Type. Field is required. Example: ‘equities’, ‘derivatives’.
ticker (str) – Ticker symbol. Field is required. Example: ‘PETR4’.
raw_data (bool) – If false, returns data in a dataframe. If true, returns raw data. Field is not required. Default: False.