### FinMind DataLoader Example Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Example of using the FinMind DataLoader class in Python to fetch option data, including asynchronous fetching. ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='YOUR_API_TOKEN') # Replace with your actual API token start = datetime.datetime.now() df = api.taiwan_option_open_interest_large_traders( option_id_list=['TXO', 'TEO'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Python Request Example Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Example of how to fetch Taiwan Option Open Interest Large Traders data using Python's requests library. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "YOUR_API_TOKEN" # Replace with your actual API token headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanOptionOpenInterestLargeTraders", "data_id":"CA", "start_date": "2024-09-01", "end_date": "2024-09-02", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` -------------------------------- ### Python Request Example Source: https://finmind.github.io/tutor/TaiwanMarket/ConvertibleBond Example of how to fetch Taiwan Stock Convertible Bond Daily Overview data using Python's requests library. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # Refer to login to get the token headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockConvertibleBondDailyOverview", "data_id":"15131", "start_date": "2020-04-01", "end_date": "2020-04-10", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` -------------------------------- ### R httr Example Source: https://finmind.github.io/tutor/TaiwanMarket/ConvertibleBond Example of how to fetch Taiwan Stock Convertible Bond Daily Overview data using R's httr library. ```r library(httr) library(data.table) library(dplyr) token = "" # Refer to login to get the token url = 'https://api.finmindtrade.com/api/v4/data' response = httr::GET( url = url, query = list( dataset="TaiwanStockConvertibleBondDailyOverview", data_id="15131", start_date= "2020-04-01", end_date='2020-04-10' ), add_headers(Authorization = paste("Bearer", token)) ) data = response %>% content df = do.call('cbind',data$data) %>%data.table head(df) ``` -------------------------------- ### Get Taiwan Stock Month Revenue by Stock ID (Python Requests) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental This example shows how to fetch Taiwan stock month revenue data using the requests library in Python. It requires an API token for authentication. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockMonthRevenue", "data_id": "2330", "start_date": "2019-01-01", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` -------------------------------- ### R httr Example Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Example of how to fetch Taiwan Option Open Interest Large Traders data using R's httr library. ```r library(httr) library(data.table) library(dplyr) token = "YOUR_API_TOKEN" # Replace with your actual API token url = 'https://api.finmindtrade.com/api/v4/data' response = httr::GET( url = url, query = list( dataset="TaiwanOptionOpenInterestLargeTraders", data_id="CA", start_date= "2024-09-01", end_date= "2024-09-02" ), add_headers(Authorization = paste("Bearer", token)) ) data = response %>% content df = do.call('cbind',data$data) %>%data.table head(df) ``` -------------------------------- ### Retrieve Taiwan Stock PER and PBR Data Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Examples for fetching Price-to-Earnings and Price-to-Book ratios for specific stocks. ```python df = api.taiwan_stock_per_pbr( stock_id='2330', start_date='2020-01-02', end_date='2020-04-12', ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockPER", "data_id": "2330", "start_date": "2020-04-01", "end_date": "2020-04-12", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockPER", data_id= "2330", start_date= "2020-01-02", end_date= "2020-04-12" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_stock_per_pbr( stock_id_list=['2330', '2317', '2454', '3008'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Retrieve Stock Shareholding Data Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Examples for fetching foreign shareholding data for specific stocks. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_stock_shareholding( stock_id="2330", start_date='2020-04-01', end_date='2020-04-12' ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockShareholding", "data_id": "2330", "start_date": "2020-04-01", "end_date": "2020-04-12", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockShareholding", data_id= "2330", start_date= "2020-01-02", end_date="2020-04-12" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_stock_shareholding( stock_id_list=['2330', '2317', '2454', '3008'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Retrieve Institutional Investors Total Data Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Examples for fetching total institutional investor data for a specific date range. ```python df = api.taiwan_stock_institutional_investors_total( start_date='2020-04-01', end_date='2020-04-12', ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockTotalInstitutionalInvestors", "start_date": "2020-04-01", "end_date": "2020-04-12", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockTotalInstitutionalInvestors", start_date= "2020-01-02", end_date='2020-04-12' ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### Retrieve Taiwan Stock Margin Purchase and Short Sale Data Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Examples for fetching margin purchase and short sale data for specific stocks. ```python df = api.taiwan_stock_margin_purchase_short_sale( start_date='2020-04-01', ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockMarginPurchaseShortSale", "start_date": "2020-04-01", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockMarginPurchaseShortSale", start_date= "2020-01-02" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### GET /data Source: https://finmind.github.io/llms.txt Fetches specific financial datasets based on provided parameters. ```APIDOC ## GET /data ### Description Retrieves financial data for a specific dataset and identifier. ### Method GET ### Endpoint /data ### Parameters #### Query Parameters - **dataset** (string) - Required - The name of the dataset - **data_id** (string) - Required - The specific identifier for the data - **start_date** (string) - Optional - Start date for the data range - **end_date** (string) - Optional - End date for the data range - **token** (string) - Optional - Authorization token ``` -------------------------------- ### Retrieve Taiwan Stock Holding Shares Per Data Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Examples for fetching stock holding shares per data, including async support for multiple stocks. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_stock_holding_shares_per( stock_id="2330", start_date='2020-04-01', end_date='2020-04-12' ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockHoldingSharesPer", "data_id": "2330", "start_date": "2020-04-01", "end_date": "2020-04-12", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockHoldingSharesPer", data_id= "2330", start_date= "2020-01-02", end_date='2020-04-12' ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_stock_holding_shares_per( stock_id_list=['2330', '2317', '2454', '3008'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Retrieve Daily Adjusted Stock Data Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Examples for fetching daily adjusted stock price data for a specific stock ID and date range. ```python df = api.taiwan_stock_daily_adj( stock_id='2330', start_date='2020-04-02', end_date='2020-04-12' ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockPriceAdj", "data_id": "2330", "start_date": "2020-04-02", "end_date": "2020-04-12", } resp = requests.get(url, headers=headers, params=parameter) data = resp.json() data = pd.DataFrame(data["data"]) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockPriceAdj", data_id= "2330", start_date= "2020-04-02", end_date= "2020-04-08" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### FinMind DataLoader - Python Library Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Example usage of the FinMind Python DataLoader library for fetching financial data, including asynchronous requests for multiple futures contracts. ```APIDOC ## Python DataLoader Library ### Description This section demonstrates how to use the FinMind Python DataLoader library to fetch financial data, including futures open interest. It shows how to log in with an API token and make asynchronous requests for multiple futures contracts. ### Method `DataLoader.taiwan_futures_open_interest_large_traders()` ### Parameters - **api_token** (string) - Required - Your API token for authentication. - **futures_id_list** (list of strings) - Required - A list of futures contract IDs (e.g., ['TXF', 'MXF', 'EXF']). - **start_date** (string) - Required - The start date for the data in YYYY-MM-DD format. - **end_date** (string) - Required - The end date for the data in YYYY-MM-DD format. - **use_async** (boolean) - Optional - Set to `True` to enable asynchronous data fetching. ### Request Example (Python) ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='YOUR_API_TOKEN') start = datetime.datetime.now() df = api.taiwan_futures_open_interest_large_traders( futures_id_list=['TXF', 'MXF', 'EXF'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` ### Response - The function returns a pandas DataFrame containing the requested financial data. The structure of the DataFrame is as follows: #### DataFrame Schema | name | contract_type | buy_top5_trader_open_interest | buy_top5_trader_open_interest_per | buy_top10_trader_open_interest | buy_top10_trader_open_interest_per | sell_top5_trader_open_interest | sell_top5_trader_open_interest_per | sell_top10_trader_open_interest | sell_top10_trader_open_interest_per | market_open_interest | buy_top5_specific_open_interest | buy_top5_specific_open_interest_per | buy_top10_specific_open_interest | buy_top10_specific_open_interest_per | sell_top5_specific_open_interest | sell_top5_specific_open_interest_per | sell_top10_specific_open_interest | sell_top10_specific_open_interest_per | date | futures_id ---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|--- 0 | 東證期貨 | 202409 | 93 | 74.4 | 113 | 90.4 | 102 | 81.6 | 118 | 94.4 | 125 | 16 | 12.8 | 16 | 12.8 | 14 | 11.2 | 14 | 11.2 | 2024-09-02 | TJF 1 | 東證期貨 | 202409 | 133 | 62.7 | 170 | 80.2 | 172 | 81.1 | 194 | 91.5 | 212 | 16 | 7.5 | 16 | 7.5 | 42 | 19.8 | 42 | 19.5 | 2024-09-02 | TJF #### Field Descriptions - **name** (str): 商品名稱 (Product name) - **contract_type** (str): 到期月份 (Expiration month) - **buy_top5_trader_open_interest** (int32): 買方前五大交易人合計部位數 (Total open interest for top 5 buying traders) - **buy_top5_trader_open_interest_per** (float32): 買方前五大交易人合計百分比 (Percentage of open interest for top 5 buying traders) - **buy_top10_trader_open_interest** (int32): 買方前十大交易人合計部位數 (Total open interest for top 10 buying traders) - **buy_top10_trader_open_interest_per** (float32): 買方前十大交易人合計百分比 (Percentage of open interest for top 10 buying traders) - **sell_top5_trader_open_interest** (int32): 賣方前五大交易人合計部位數 (Total open interest for top 5 selling traders) - **sell_top5_trader_open_interest_per** (float32): 賣方前五大交易人合計百分比 (Percentage of open interest for top 5 selling traders) - **sell_top10_trader_open_interest** (int32): 賣方前十大交易人合計部位數 (Total open interest for top 10 selling traders) - **sell_top10_trader_open_interest_per** (float32): 賣方前十大交易人合計百分比 (Percentage of open interest for top 10 selling traders) - **market_open_interest** (int32): 全市場未沖銷部位數 (Total open interest for the entire market) - **buy_top5_specific_open_interest** (int32): 買方前五大特定法人合計部位數 (Total open interest for top 5 specific buying institutions) - **buy_top5_specific_open_interest_per** (float32): 買方前五大特定法人合計百分比 (Percentage of open interest for top 5 specific buying institutions) - **buy_top10_specific_open_interest** (int32): 買方前十大特定法人合計部位數 (Total open interest for top 10 specific buying institutions) - **buy_top10_specific_open_interest_per** (float32): 買方前十大特定法人合計百分比 (Percentage of open interest for top 10 specific buying institutions) - **sell_top5_specific_open_interest** (int32): 賣方前五大特定法人合計部位數 (Total open interest for top 5 specific selling institutions) - **sell_top5_specific_open_interest_per** (float32): 賣方前五大特定法人合計百分比 (Percentage of open interest for top 5 specific selling institutions) - **sell_top10_specific_open_interest** (int32): 賣方前十大特定法人合計部位數 (Total open interest for top 10 specific selling institutions) - **sell_top10_specific_open_interest_per** (float32): 賣方前十大特定法人合計百分比 (Percentage of open interest for top 10 specific selling institutions) - **date** (str): 日期 (Date) - **futures_id** (str): 期貨代碼 (Futures ID) ``` -------------------------------- ### Retrieve Institutional Investor Data for a Specific Stock Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Examples for fetching institutional investor buy/sell data for a specific stock ID within a date range. ```python df = api.taiwan_stock_institutional_investors( stock_id="2330", start_date='2020-04-01', end_date='2020-04-12', ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockInstitutionalInvestorsBuySell", "data_id": "2330", "start_date": "2020-04-01", "end_date": "2020-04-12", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockInstitutionalInvestorsBuySell", data_id= "2330", start_date= "2020-04-01", end_date= "2020-04-12" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### Retrieve Taiwan Stock Market Value Data Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Examples for fetching market value data for specific stocks, restricted to backer and sponsor members. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_stock_market_value( stock_id='2330', start_date='2023-01-01', end_date='2024-01-01' ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockMarketValue", "data_id": "2330", "start_date": "2023-01-01", "end_date": "2024-01-01", } resp = requests.get(url, headers=headers, params=parameter) data = resp.json() data = pd.DataFrame(data["data"]) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockMarketValue", data_id= "2330", start_date= "2023-01-01", end_date= "2024-01-01" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### Retrieve Taiwan Options Daily Data Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Examples for fetching daily options data using the FinMind Python package, direct requests, R, and asynchronous requests. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_option_daily( option_id='TXO', start_date='2020-04-01', end_date='2020-04-02', ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanOptionDaily", "data_id":"TXO", "start_date": "2020-04-01", "end_date": "2020-04-02", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) token = "" # 參考登入,獲取金鑰 url = 'https://api.finmindtrade.com/api/v4/data' response = httr::GET( url = url, query = list( dataset="TaiwanOptionDaily", data_id="TXO", start_date= "2020-04-01", end_date= "2020-04-02" ), add_headers(Authorization = paste("Bearer", token)) ) data = response %>% content df = do.call('rbind',data$data) %>%data.table ``` ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_option_daily( option_id_list=['TXO', 'TEO'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Fetch All Taiwan Stock Daily Data from a Specific Date via HTTP (Python) Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Retrieves all available daily stock price data starting from a specified date using a direct HTTP GET request. Requires authentication and specifies the dataset and start date. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockPrice", "start_date": "2020-04-06", } resp = requests.get(url, headers=headers, params=parameter) data = resp.json() data = pd.DataFrame(data["data"]) print(data.head()) ``` -------------------------------- ### Initialize DataLoader and Login with Token (Python) Source: https://finmind.github.io/llms.txt Initializes the DataLoader and logs in using an API token. Ensure you have obtained your token from finmindtrade.com. ```python from FinMind.data import DataLoader api = DataLoader() api.login_by_token(api_token='your_token') ``` -------------------------------- ### Fetch All Taiwan Stock Daily Data from a Specific Date via HTTP (R) Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Retrieves all available daily stock price data starting from a specified date using an HTTP GET request with the httr package in R. Requires authentication and specifies the dataset and start date. ```r library(httr) library(data.table) library(dplyr) url = 'https://api.finmindtrade.com/api/v4/data' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockPrice", start_date= "2020-04-06" ), add_headers(Authorization = paste("Bearer", token)) ) data = content(response) df = data$data %>% do.call('rbind',.) %>% data.table head(df) ``` -------------------------------- ### Retrieve Daily Tick Data for All Stocks Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Methods for fetching full-day tick data for all stocks, intended for SponsorPro members. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_stock_tick( date='2019-01-02', use_object=True, ) ``` ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/storage_objects" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockPriceTick", "date": '2019-01-02', } resp = requests.get(url, headers=headers, params=parameter) data = pd.read_parquet(io.BytesIO(resp.content)) print(data.head()) ``` ```r library(httr) library(data.table) library(dplyr) library(arrow) url = 'https://api.finmindtrade.com/api/v4/storage_objects' token = "" # 參考登入,獲取金鑰 response = httr::GET( url = url, query = list( dataset="TaiwanStockPriceTick", date= "2019-01-02" ), add_headers(Authorization = paste("Bearer", token)) ) con = content(response, "raw") data <- read_parquet(con) close(con) head(data) ``` -------------------------------- ### Async Batch Query for Taiwan Stocks (Python) Source: https://finmind.github.io/llms.txt Fetches daily stock data for multiple Taiwan stock IDs concurrently using `use_async=True`. This method is faster for multiple queries. Not supported for all dataset types. ```python df = api.taiwan_stock_daily( stock_id_list=['2330', '2317', '2454', '3008'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) ``` -------------------------------- ### GET /api/v4/data (TaiwanStockDelisting) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Retrieves information about delisted Taiwan stocks. ```APIDOC ## GET /api/v4/data ### Description Retrieves information about delisted Taiwan stocks. ### Method GET ### Endpoint https://api.finmindtrade.com/api/v4/data ### Parameters #### Query Parameters - **dataset** (string) - Required - Set to 'TaiwanStockDelisting' ### Request Example { "dataset": "TaiwanStockDelisting" } ### Response #### Success Response (200) - **date** (string) - Date - **stock_id** (string) - Stock ID - **stock_name** (string) - Stock Name ``` -------------------------------- ### Asynchronous Data Loading for Multiple Stocks Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Demonstrates using the DataLoader with asynchronous requests for multiple stock IDs. ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_stock_institutional_investors( stock_id_list=['2330', '2317', '2454', '3008'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### GET /datalist Source: https://finmind.github.io/llms.txt Lists all available data_id values for a specific dataset. ```APIDOC ## GET /datalist ### Description Returns a list of available data_id values for a given dataset. ### Method GET ### Endpoint /datalist ``` -------------------------------- ### Retrieve warrant trading report using async Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Demonstrates asynchronous data loading for warrant trading reports. ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') date = '2025-12-08' start = datetime.datetime.now() df = api.taiwan_stock_warrant_trading_daily_report( date=date, use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### Get All Taiwan Stock Month Revenue Data (Python) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Fetch monthly revenue data for all stocks within a specified date range. This is useful for broad market analysis. Ensure you are logged in. ```python from FinMind.data import DataLoader api = DataLoader() # api.login_by_token(api_token='token') df = api.taiwan_stock_month_revenue( start_date='2019-04-01', ) ``` -------------------------------- ### GET /user_info Source: https://finmind.github.io/llms-full.txt Retrieves current API usage statistics and quota limits. ```APIDOC ## GET https://api.web.finmindtrade.com/v2/user_info ### Description Check current API usage and quota limits. ### Method GET ### Endpoint https://api.web.finmindtrade.com/v2/user_info ### Response #### Success Response (200) - **user_count** (int) - Current API usage count - **api_request_limit** (int) - API request limit ### Response Example { "user_count": 150, "api_request_limit": 600 } ``` -------------------------------- ### GET /translation Source: https://finmind.github.io/llms.txt Retrieves the English-Chinese column name mapping for a specific dataset. ```APIDOC ## GET /translation ### Description Provides a mapping between English and Chinese column names for a dataset. ### Method GET ### Endpoint /translation ``` -------------------------------- ### Initialize DataLoader Source: https://finmind.github.io/tutor/TaiwanMarket/ConvertibleBond Initializes the FinMind DataLoader instance for subsequent data requests. ```python from FinMind.data import DataLoader api = DataLoader() ``` -------------------------------- ### GET /data Source: https://finmind.github.io/llms-full.txt Fetches financial data from a specified dataset based on provided filters. ```APIDOC ## GET /data ### Description Fetches dataset records based on the provided parameters. ### Method GET ### Endpoint /data ### Query Parameters - **dataset** (str) - Required - The name of the dataset to query - **data_id** (str) - Optional - Specific identifier for the data - **start_date** (str) - Optional - Start date in YYYY-MM-DD format - **end_date** (str) - Optional - End date in YYYY-MM-DD format ### Response #### Success Response (200) - **msg** (str) - Status message - **status** (int) - HTTP status code - **data** (array) - List of data records ### Response Example { "msg": "success", "status": 200, "data": [ { ... } ] } ``` -------------------------------- ### GET /api/v4/data (TaiwanStockMarketValue) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Retrieves daily market value data for Taiwan stocks. ```APIDOC ## GET /api/v4/data ### Description Retrieves daily market value data for Taiwan stocks. ### Method GET ### Endpoint https://api.finmindtrade.com/api/v4/data ### Parameters #### Query Parameters - **dataset** (string) - Required - Set to 'TaiwanStockMarketValue' - **start_date** (string) - Optional - Start date in YYYY-MM-DD format ### Request Example { "dataset": "TaiwanStockMarketValue", "start_date": "2023-01-03" } ### Response #### Success Response (200) - **date** (string) - Date - **stock_id** (string) - Stock ID - **market_value** (int64) - Market Value ``` -------------------------------- ### Get All Taiwan Stock Month Revenue Data (Python Requests) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental This Python snippet uses the requests library to fetch monthly revenue data for all stocks within a given date range. Authentication with a token is required. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanStockMonthRevenue", "start_date": "2019-01-01", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data.head()) ``` -------------------------------- ### GET /api/v4/data Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Retrieves Taiwan stock dividend data for a specified date range. ```APIDOC ## GET /api/v4/data ### Description Retrieves the Taiwan Stock Dividend dataset for a specific date range. ### Method GET ### Endpoint https://api.finmindtrade.com/api/v4/data ### Parameters #### Query Parameters - **dataset** (string) - Required - The dataset name, use 'TaiwanStockDividend'. - **start_date** (string) - Required - The start date for the data query (YYYY-MM-DD). ### Request Example { "dataset": "TaiwanStockDividend", "start_date": "2025-10-06" } ### Response #### Success Response (200) - **date** (string) - 權利分派基準日 - **stock_id** (string) - 股票代碼 - **year** (string) - 股利所屬年度 - **StockEarningsDistribution** (float64) - 股票股利:盈餘轉增資配股 - **StockStatutorySurplus** (float64) - 股票股利:法定盈餘公積資本公積轉增資配股 - **StockExDividendTradingDate** (string) - 除權交易日 - **CashEarningsDistribution** (float64) - 現金股利:盈餘轉增資配股 - **CashStatutorySurplus** (float64) - 現金股利:法定盈餘公積資本公積轉增資配股 - **CashExDividendTradingDate** (string) - 除息交易日 - **CashDividendPaymentDate** (string) - 現金股利發放日 - **AnnouncementDate** (string) - 公告日期 #### Response Example { "data": [ { "date": "2025-10-06", "stock_id": "2540", "year": "113年", "CashEarningsDistribution": 0.4 } ] } ``` -------------------------------- ### Fetch Taiwan Daily Short Sale Balances (Python) Source: https://finmind.github.io/tutor/TaiwanMarket/Chip Retrieves daily short sale balance data for Taiwan stocks. Requires authentication with an API token. ```python import requests import pandas as pd url = "https://api.finmindtrade.com/api/v4/data" token = "" # 參考登入,獲取金鑰 headers = {"Authorization": f"Bearer {token}"} parameter = { "dataset": "TaiwanDailyShortSaleBalances", "start_date": "2021-05-20", } data = requests.get(url, headers=headers, params=parameter) data = data.json() data = pd.DataFrame(data['data']) print(data) ``` -------------------------------- ### Load Multiple Futures Open Interest (Python DataLoader Async) Source: https://finmind.github.io/tutor/TaiwanMarket/Derivative Use the FinMind DataLoader with async to fetch open interest for multiple futures contracts. Requires login with an API token. ```python from FinMind.data import DataLoader from loguru import logger import datetime api = DataLoader() api.login_by_token(api_token='token') start = datetime.datetime.now() df = api.taiwan_futures_open_interest_large_traders( futures_id_list=['TXF', 'MXF', 'EXF'], start_date='2024-01-01', end_date='2024-12-31', use_async=True, ) cost = datetime.datetime.now() - start logger.info(cost) ``` -------------------------------- ### GET /api/v4/data (TaiwanStockStatisticsOfOrderBookAndTrade) Source: https://finmind.github.io/tutor/TaiwanMarket/Technical Retrieves 5-second interval order book and trade statistics for the Taiwan stock market. ```APIDOC ## GET /api/v4/data ### Description Retrieves 5-second interval statistics for order book and trade data. Note: Due to data volume, only one day of data is provided per request. ### Method GET ### Endpoint https://api.finmindtrade.com/api/v4/data ### Query Parameters - **dataset** (string) - Required - Set to 'TaiwanStockStatisticsOfOrderBookAndTrade' - **start_date** (string) - Required - The date to retrieve data for (YYYY-MM-DD) ### Response #### Success Response (200) - **Time** (string) - Time of the record - **TotalBuyOrder** (string) - Cumulative buy order count - **TotalBuyVolume** (int64) - Cumulative buy volume - **TotalSellOrder** (int64) - Cumulative sell order count - **TotalSellVolume** (int64) - Cumulative sell volume - **TotalDealOrder** (int64) - Cumulative deal order count - **TotalDealVolume** (int64) - Cumulative deal volume - **TotalDealMoney** (int64) - Cumulative deal money - **date** (string) - Date of the record ``` -------------------------------- ### GET /api/v4/data (TaiwanStockMarketValueWeight) Source: https://finmind.github.io/tutor/TaiwanMarket/Fundamental Retrieves market value weight data for Taiwan stocks (Restricted to backer/sponsor members). ```APIDOC ## GET /api/v4/data ### Description Retrieves market value weight data for Taiwan stocks. ### Method GET ### Endpoint https://api.finmindtrade.com/api/v4/data ### Parameters #### Query Parameters - **dataset** (string) - Required - Set to 'TaiwanStockMarketValueWeight' - **data_id** (string) - Optional - Stock ID - **start_date** (string) - Optional - Start date - **end_date** (string) - Optional - End date ### Request Example { "dataset": "TaiwanStockMarketValueWeight", "data_id": "2330", "start_date": "2024-01-01", "end_date": "2025-01-01" } ### Response #### Success Response (200) - **rank** (int64) - Rank - **stock_id** (string) - Stock ID - **stock_name** (string) - Stock Name - **weight_per** (float32) - Weight Percentage - **date** (string) - Date - **type** (string) - Market type (twse/tpex) ```