How to Import Stock Information for All Tickers in the US and TW Market into SQLite via Python Colab? Part 1.b
Previously on How to Import Stock Information for All Tickers in the US and TW Market into SQLite via Python Colab? Part 1, we talked about how to pull all tickers of US and TW markets. We would like to share another way to get the stock symbol list.
The FinanceDatabase serves the role of providing anyone with any type of financial product categorisation entirely for free. Unlike stocksymbol, financedatabase does not include TW market information but it does contain ETFs that stocksymbol does not include.
Step 0: install financedatabase
!pip install financedatabase
Step 1: Grab all equities including international exchanges
import financedatabase as fd
import pandas as pd
equities = fd.Equities()
df = equities.select()
df['symbol'] = df.index
df.head()
Step 2: Grab all ETFs
etfs = fd.ETFs()
df_etf = etfs.select()
df_etf ['symbol'] = df_etf.index
Step 3: Import these two data frames into SQLite
from google.colab import drive
drive.mount('/content/drive')
df = df.reset_index(drop=True)
df_etf = df_etf.reset_index(drop=True)
import sqlite3
con = sqlite3.connect('/content/drive/MyDrive/data/Stock.db')
df.to_sql('financedatabase_eq', con, if_exists='replace')
df_etf.to_sql('financedatabase_etf', con, if_exists='replace')
con.close()
Thank you! enjoy it!