How to Import Stock Information for All Tickers in the US and TW Market into SQLite via Python Colab? Part 1

Informula
IMU Framework Design
2 min readJul 7, 2023

--

In this series of article, we will discuss how to pull stock detailed information including PE, moving average, etc for all stock tickers of US & Taiwan market and to store it into SQLite DB in Google Drive.

In this part, we will cover how to get all tickers and continue to discuss on collecting the stock details in the next session.

Step 0

  • Sign up in stocksymbol to get the API key.
  • Install stocksymbol in Colab Notebook
!pip install stocksymbol

Step 1

In SQLite Stock.db stored in Google Drive, create a table called “Tickers”

import sqlite3

con = sqlite3.connect('/content/drive/MyDrive/data/Stock.db')

cursor = con.cursor()

query = """
CREATE TABLE "Tickers"
(
[symbol] varchar(50) NOT NULL,
[longName] varchar(255) ,
[exchange] varchar(255) ,
[market] varchar(255),
PRIMARY KEY(symbol)
)
"""

cursor.execute(query)

con.commit()

cursor.close()

Step 3

  • Pull tickers from stocksymbol.
  • Convert them into DataFrame.
from stocksymbol import StockSymbol

api_key = 'Your API…

--

--