Welcome to cad_tickers’s documentation!

https://badge.fury.io/py/cad-tickers.svg https://codecov.io/gh/FriendlyUser/cad_tickers/branch/master/graph/badge.svg

Exchanges Classes

These classes are primary data objects for the json returned from the exchanges.

Canadian Securities Exchange

Functions to download tickers from the cse

Toronto Stock Exchange

Set of functions to scrap ticker data from the toronto stock exchange.

Will definitely split into smaller files once the graphql api becomes the main api.

Stock News

Extract news from stocks on yahoo

Finds news link from news_content.
Assumes comments are deleted from the yahoo finance news items
Parameters:
news_content - html based data for the news article
Returns:
link_href - link in html markup link_text - link text in html markup
cad_tickers.news.stock_news.find_news_source(news_content: bs4.element.Tag) → Union[None, str]

Utility function to verify news format from yahoo has not changed

when grabbing data from yahoo with requests, it seems date is not returned.

Parameters:
news_content: html based data for the news article
Returns:
source - publisher of article

wrapper div around content - such as - CNW Group 2 days ago

cad_tickers.news.stock_news.get_ynews_for_ticker(ticker: str, yahoo_base_url='https://finance.yahoo.com') → List[bs4.element.Tag]

Returns initial news items fetched from yahoo when loading quote page. Since yahoo has lazy loading, not all items are returned. Seems like ads are not loaded because of lazy loading.

Parameters:
ticker - yahoo formatted ticker str yahoo_base_url - optional parameter that is the base of the request
Returns:
news_items - list of key html content for the news item
cad_tickers.news.stock_news.scrap_news_for_ticker(ticker: str) → List[dict]

Extracts webpage data from a ticker

TODO add a delay

Parameters:
ticker - yahoo finance ticker
Returns:
news_data - list of dicts extracted from webpage
  • source - str
  • link_href - link from post (can be relative or absolute)
  • link_text - description for link
  • ticker - reference to original ticker

CEO

To use this functionality, we require dataclasses which is natively available in python 3.7, for python 3.6 please install dataclasses from pip.

cad_tickers.news.ceo.main.extract_urls(spiels: List[dict]) → Tuple[list, str]

Valid List Items from ceo

cad_tickers.news.ceo.main.get_new_items(ticker: str, channel='@newswire', max_iterations=60, until=0)

Gets news items from ceo using ticker

Parameters:
ticker - stock ticker, for example APHA channel - can be @newswire, @thenewswire max_iterations - max number of requests to ceo.ca
cad_tickers.news.ceo.main.get_spiels(params: dict) → dict

Simple function to get ceo.ca spiels

class cad_tickers.news.ceo.spiel_class.SearchParams(channel: str = '@newswire', filter_terms: str = 'APHA', filter_top: int = 100, load_more: str = 'top', original_scroll_height: str = 0, until: int = 1656725739253)

Search Params for Ceo.ca intended to get spiels.

channel = '@newswire'
filter_terms = 'APHA'
filter_top = 100
load_more = 'top'
original_scroll_height = 0
until = 1656725739253
cad_tickers.news.ceo.utils.earlier_timestamp(timestamp: int, days: int = 90) → int

Update timestamp and return timestamp in millseconds

cad_tickers.news.ceo.utils.params_to_dict(sp: Type[cad_tickers.news.ceo.spiel_class.SearchParams]) → dict

utility function to get query parameters

IIROC Halts

Find out what latest stocks have been halted from iiroc (only canada)

cad_tickers.news.iiroc_halts.get_halts_resumption() → pandas.core.frame.DataFrame

Gets the latest 25 halts from the iiroc

Returns:
halt_df

Dataframe with bad data removed

Halts Details of halts
Listing Extracted ticker from halt

Sedar Documents

Utilities for downloading documents from sedar. Directly downloading files from sedar is difficult, so I am piggybacking the various exchanges, for the cse you can get links directly and download files.

As for the tsx and tsxv, it is a link that redirects to another website. This is fine as I do not intend to scrap data and only read the pdfs.

Stock Utilities

Contains various utility classes

Examples

Grab Descriptions for all tsx tickers

from cad_tickers.exchanges.tsx import dl_tsx_xlsx, add_descriptions_to_df_pp
from datetime import datetime
start_time = datetime.now()
df = dl_tsx_xlsx()
# df = add_descriptions_to_df(df)
df = add_descriptions_to_df_pp(df)
end_time = datetime.now()
df.to_csv('tsx_all_descriptions.csv')
print(end_time - start_time)

Indices and tables