Understanding market sectors and stock classifications is an important part of investment research. Investors often need both company-level information and sector-level insights to better evaluate market opportunities.
This notebook demonstrates how to combine getUsStocksParent and getAllSectors using Python and the Indonesia Stock Exchange (IDX) API.
By retrieving data from both endpoints, investors can access stock parent information alongside sector classifications in a single workflow.
Cell 1 — Import Library
import requests
import pandas as pd
import time
from IPython.display import displayExplanation
Cell 1 imports the required Python libraries.
The notebook uses:
requestsfor API communicationpandasfor data processingtimefor delay management between requestsdisplayfor presenting dataframes in Google Colab
These libraries provide the foundation for retrieving and analyzing data from the IDX API.
Cell 2 — Konfigurasi API
RAPIDAPI_KEY = "YOUR_API_KEY"
BASE_URL = "https://indonesia-stock-exchange-idx.p.rapidapi.com"
HEADERS = {
"Content-Type": "application/json",
"x-rapidapi-host": "indonesia-stock-exchange-idx.p.rapidapi.com",
"x-rapidapi-key": RAPIDAPI_KEY
}Explanation
Cell 2 configures the API connection.
The notebook defines the API key, base URL, and request headers required to access the Indonesia Stock Exchange API through RapidAPI.
These settings are reused throughout the workflow whenever an API request is executed.
Cell 3 — Function API
def fetch_api(endpoint, params=None, retries=3, delay=3):Explanation
Cell 3 creates a reusable API request function.
The function handles:
API requests
Parameter management
Error handling
Rate-limit retries
If the API returns a successful response, the function converts the data into JSON format.
If a rate limit error occurs, the function automatically waits and retries the request.
This approach makes the notebook more reliable and scalable.
Cell 4 — Ambil & Gabungkan Data API
us_stocks_parent = fetch_api(
"/api/main/us-stocks-parent",
params={"symbols": "GOTO,BUKA"}
)
all_sectors = fetch_api("/api/sectors")Explanation
Cell 4 retrieves data from two IDX API endpoints.
The notebook calls:
getUsStocksParent
This endpoint retrieves parent stock information for selected symbols.
getAllSectors
This endpoint retrieves sector classifications available within the market.
After both API requests are completed, the responses are stored inside a single dictionary called api_result.
Combining both datasets simplifies data management and creates a unified research workflow.
Cell 5 — Rapikan & Tampilkan Data
us_stocks_parent_df = extract_table(
api_result["getUsStocksParent"]
)
all_sectors_df = extract_table(
api_result["getAllSectors"]
)Explanation
Cell 5 transforms API responses into structured dataframes.
The notebook uses the extract_table() function to automatically detect the response structure and convert it into tabular format.
The resulting dataframes are:
us_stocks_parent_dfall_sectors_df
The notebook then displays both datasets and generates a summary showing the total number of records retrieved from each API.
This step converts raw API responses into a format that is easier to analyze and interpret.
Result:

OVERALL WORKFLOW
This notebook follows a simple market intelligence workflow.
First, it imports the required Python libraries.
Second, it configures API authentication and request headers.
Third, it creates a reusable API function with built-in error handling.
Fourth, it retrieves data from the US Stocks Parent API and the All Sectors API.
Fifth, it combines both API responses into a single structure.
Finally, it converts the responses into dataframes and generates a summary report.
WHY THIS CASE MATTERS
Investors often analyze stocks and sectors separately.
However, combining stock-level information with sector classifications can provide additional context for market research.
US Stocks Parent data helps identify stock relationships and company structures, while sector data provides a broader market perspective.
By integrating both datasets, investors can build more comprehensive market analysis workflows and improve investment research efficiency.
CONCLUSION
This tutorial demonstrates how to combine getUsStocksParent and getAllSectors using Python and the IDX API.
The notebook retrieves stock parent information, collects sector classification data, handles API responses, converts data into structured dataframes, and generates summary statistics.
The final workflow provides:
US stock parent monitoring
Sector classification analysis
Structured dataframe generation
API response normalization
Market intelligence reporting
For investors, analysts, and fintech developers, this project provides a practical foundation for building data-driven market research and sector analysis tools.
