What is the KIS API?

The KIS API (Korea Investment & Securities API) is a REST/WebSocket API that allows developers to:

  • Get real-time stock quotes
  • Place buy/sell orders programmatically
  • Access account balance and portfolio data
  • Stream real-time market data via WebSocket

Prerequisites

  1. A Korea Investment & Securities brokerage account
  2. KIS API access approval
  3. Python 3.8+ installed

Step 1: Open a KIS Account

Visit the Korea Investment & Securities website and apply for an account. Foreigners can apply online in many cases.

Step 2: Apply for API Access

  1. Log into your KIS account
  2. Navigate to API Application menu
  3. Apply for Open API access
  4. Wait for approval (usually 1-3 business days)

Step 3: Get Your API Keys

Once approved, you’ll receive:

  • App Key
  • App Secret
  • Account Number

Store these securely — never commit them to GitHub.

Step 4: Get Access Token

import requests
import json

APP_KEY = "your_app_key"
APP_SECRET = "your_app_secret"

def get_access_token():
    url = "https://openapi.koreainvestment.com:9443/oauth2/tokenP"
    headers = {"content-type": "application/json"}
    body = {
        "grant_type": "client_credentials",
        "appkey": APP_KEY,
        "appsecret": APP_SECRET
    }
    res = requests.post(url, headers=headers, data=json.dumps(body))
    return res.json()["access_token"]

token = get_access_token()
print(f"Access token obtained successfully")

Step 5: Get Stock Price

def get_stock_price(ticker, token):
    url = "https://openapi.koreainvestment.com:9443/uapi/domestic-stock/v1/quotations/inquire-price"
    headers = {
        "Content-Type": "application/json",
        "authorization": f"Bearer {token}",
        "appkey": APP_KEY,
        "appsecret": APP_SECRET,
        "tr_id": "FHKST01010100"
    }
    params = {
        "FID_COND_MRKT_DIV_CODE": "J",
        "FID_INPUT_ISCD": ticker
    }
    res = requests.get(url, headers=headers, params=params)
    return res.json()["output"]["stck_prpr"]

# Get Samsung Electronics price
price = get_stock_price("005930", token)
print(f"Samsung current price: {price} KRW")

Next Steps

  • How to Get Your KIS API Key with Screenshots
  • Build a Korean Stock Screener with pykrx
  • Automate Korean Stock Alerts with GitHub Actions