Overview
If you’re building a Korean stock trading system in Python, you’ll encounter two main tools: KIS API and pykrx. Here’s a detailed breakdown of when to use each.
What is pykrx?
pykrx is an open-source library that scrapes publicly available data from the KRX website. It requires no account or API key.
Best for:
- Historical data research
- Backtesting trading strategies
- Stock screening and analysis
- Learning and prototyping
What is KIS API?
KIS API is the official API from Korea Investment & Securities. It requires a brokerage account and API approval.
Best for:
- Live trading automation
- Real-time price data
- Order placement and management
- Production trading systems
Detailed Comparison
| Feature | pykrx | KIS API |
|---|---|---|
| Account required | No | Yes |
| API approval required | No | Yes |
| Real-time quotes | No | Yes |
| Historical data | Yes (good) | Yes (limited) |
| Order placement | No | Yes |
| WebSocket streaming | No | Yes |
| Rate limits | Unofficial, scraping | Official limits |
| Reliability | Medium | High |
| Cost | Free | Free (with account) |
| Setup time | 5 minutes | 1-3 days |
My Recommendation
Use pykrx when:
- You’re learning and prototyping
- You need historical data for backtesting
- You want to screen stocks without a live account
- You’re building research tools
Use KIS API when:
- You’re ready to trade with real money
- You need real-time data
- You want to place automated orders
- You’re building a production trading bot
Using Both Together
The best approach is to use both:
# Use pykrx for historical backtesting
from pykrx import stock
historical_data = stock.get_market_ohlcv_by_date("20240101", "20241231", "005930")
# Use KIS API for live trading signals
import requests
live_price = get_kis_price("005930", token) # KIS API
# Compare and make trading decision
if live_price < historical_data["종가"].mean() * 0.95:
place_buy_order("005930", quantity=10) # KIS API