OHLC.dev editorialIDX

IDX Smart Money Analysis Using Python and RapidAPI

Build an IDX smart money analysis system using Python and RapidAPI to track broker activity, sector correlation, and subsector data from the Indonesia Stock Exchange.

August 28, 20265 min readRafatar
IDX Smart Money Analysis Using Python and RapidAPI

This project develops a Python-based smart money analysis system for the Indonesia Stock Exchange (IDX) using RapidAPI. The objective of this project is to analyze market structure through three main approaches:

  • Subsector identification

  • Sector correlation analysis

  • Broker summary analysis for smart money detection

The system uses Python libraries such as requests for API communication, pandas for data processing, matplotlib and seaborn for data visualization.

The workflow is divided into five cells, starting from API configuration, retrieving sector data, analyzing sector relationships, identifying broker activity, and detecting potential smart money accumulation.

Cell 1 - Import Library and API Configuration

# ==========================================
# IDX SMART MONEY PROJECT
# ==========================================

import requests
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns


API_HOST = "indonesia-stock-exchange-idx.p.rapidapi.com"


HEADERS = {
    "Content-Type": "application/json",
    "x-rapidapi-host": API_HOST,
    "x-rapidapi-key": "YOUR_API_KEY"
}


def get_api(url):

    response = requests.get(
        url,
        headers=HEADERS
    )

    print("Status:", response.status_code)

    if response.status_code == 200:
        return response.json()

    else:
        print(response.text)
        return None



def json_to_df(data):

    """
    Convert berbagai format JSON menjadi DataFrame
    """

    if data is None:
        return pd.DataFrame()


    if isinstance(data, dict):

        if "data" in data:
            data = data["data"]

        elif "result" in data:
            data = data["result"]


    return pd.DataFrame(data)

Explanation

Cell 1 prepares the environment and creates the basic API communication functions.

The get_api() function is responsible for sending HTTP requests to the IDX API and checking the response status. If the request is successful, the function returns JSON data that can be processed further.

The json_to_df() function converts different JSON response formats into pandas DataFrames. This function handles common API structures such as:

{
 "data":[...]
}

or

{
 "result":[...]
}

so the output can be directly analyzed using pandas.

Cell 2 - Get Subsector Data

# ==========================================
# GET SUBSECTORS
# ==========================================


sector_id = 7


url = (
    f"https://{API_HOST}"
    f"/api/sectors/{sector_id}/subsectors"
)


subsector_json = get_api(url)


subsector_df = json_to_df(
    subsector_json
)


print(
    "Jumlah subsector:",
    len(subsector_df)
)


subsector_df.head()

Explanation

Cell 2 retrieves subsector information from a selected sector.

The program defines:

sector_id = 7

and sends a request to the subsector endpoint:

/api/sectors/{sector_id}/subsectors

The returned JSON data is converted into a DataFrame named:

subsector_df

This dataset provides information about the companies or industries included within the selected sector.

Subsector classification is useful because investors can analyze market movement at a more detailed level compared with only looking at broad sectors.

Cell 3 - Sector Correlation Analysis

# ==========================================
# SECTOR CORRELATION
# ==========================================


sector = "energy"


url = (
    f"https://{API_HOST}"
    f"/api/sectors/correlation/{sector}"
)


correlation_json = get_api(url)


print("Raw API Response:")
print(correlation_json)



if isinstance(correlation_json, dict):

    possible_keys = [
        "data",
        "correlation",
        "matrix",
        "result"
    ]


    correlation_data = None


    for key in possible_keys:

        if key in correlation_json:

            correlation_data = correlation_json[key]
            break


    if correlation_data is None:

        correlation_data = correlation_json


else:

    correlation_data = correlation_json



try:

    correlation_df = pd.DataFrame(
        correlation_data
    )


except Exception:

    correlation_df = pd.DataFrame()



print(
    "Shape:",
    correlation_df.shape
)


print(
    correlation_df.head()
)

Explanation

Cell 3 performs correlation analysis between stocks or components inside a selected sector.

In this example:

sector = "energy"

is used to analyze relationships within the Energy sector.

The parser searches multiple possible response keys:

data
correlation
matrix
result

because API responses may have different JSON structures.

The final result is converted into:

correlation_df

which represents the correlation matrix used for further analysis.

Correlation analysis helps identify whether stocks move together or have different price behavior.

A high positive correlation indicates similar movement patterns, while low correlation indicates diversification potential.

Cell 4 - Broker Summary Smart Money Detector

# ==========================================
# BROKER SUMMARY FINAL PARSER
# ==========================================


ticker = "BBCA"


url = (
f"https://{API_HOST}/api/market-detector/"
f"broker-summary/{ticker}"
"?limit=25"
"&marketBoard=MARKET_BOARD_ALL"
"&transactionType=TRANSACTION_TYPE_NET"
"&investorType=INVESTOR_TYPE_ALL"
"&from=2026-01-02"
"&to=2026-01-02"
)


broker_json = get_api(url)



def find_list(obj):

    if isinstance(obj, list):
        return obj


    if isinstance(obj, dict):

        for key, value in obj.items():

            result = find_list(value)

            if result is not None:
                return result


    return None



broker_data = find_list(
    broker_json
)



broker_df = pd.DataFrame(
    broker_data
)


print(
    broker_df.columns.tolist()
)


display(
    broker_df.head()
)

Explanation

Cell 4 retrieves broker transaction activity for a selected stock.

The example uses:

ticker = "BBCA"

and accesses the broker summary endpoint:

/api/market-detector/broker-summary/{ticker}

with parameters including:

  • transaction type: NET

  • investor type: ALL

  • market board: ALL

  • analysis period: selected date range

Because API responses may contain nested lists, the function:

find_list()

searches recursively until it finds the transaction dataset.

The result is converted into:

broker_df

which contains broker transaction information.

This dataset is the foundation for detecting potential smart money activity.


Cell 5 - Smart Money Analysis Dashboard

# ==========================================
# SMART MONEY ANALYSIS
# ==========================================


broker_col = None
net_col = None


for col in broker_df.columns:

    col_lower = col.lower()


    if "broker" in col_lower:
        broker_col = col


    if "net" in col_lower:
        net_col = col



print(
    "Broker:",
    broker_col
)

print(
    "Net:",
    net_col
)



if broker_col and net_col:


    broker_df[net_col] = pd.to_numeric(
        broker_df[net_col],
        errors="coerce"
    )


    smart_money = (
        broker_df
        .sort_values(
            net_col,
            ascending=False
        )
        .head(10)
    )


    display(
        smart_money
    )


else:

    print(
        "Struktur data berbeda."
    )

Explanation

Cell 5 performs the final smart money detection.

The program automatically searches for two important fields:

  • Broker name

  • Net transaction value

The detection process checks every column name and identifies columns containing:

broker
net

After identifying the required columns, the net transaction value is converted into numeric format.

The brokers are then sorted from the highest net buying activity to the lowest:

sort_values(net_col, ascending=False)

and the top 10 brokers are displayed as potential smart money participants.


Conclusion

This project demonstrates how Python and RapidAPI can be used to build an IDX smart money analysis workflow.

The system combines three important market analysis perspectives:

  1. Subsector Analysis

    Identifies detailed industry classification inside a sector.

  2. Sector Correlation Analysis

    Measures relationships between stocks within a selected sector.

  3. Broker Summary Analysis

    Detects broker activity and identifies potential smart money accumulation.

The project provides an efficient framework for market monitoring and stock screening. However, broker accumulation and correlation data should not be considered as standalone trading signals. Additional analysis such as company fundamentals, valuation, liquidity, technical structure, and market conditions should still be evaluated before making investment decisions.