Skip to main content

키움증권 REST API Python 라이브러리

Project description

kiwoompy

키움증권 REST API를 Python에서 편하게 쓰기 위한 라이브러리입니다.

PyPI Python Docs License

설치

pip install kiwoompy

uv 사용 시:

uv add kiwoompy

Python 3.12 이상이 필요합니다.

사전 준비

키움증권 OpenAPI에서 앱을 등록하고 App Key / App Secret을 발급받아야 합니다.

주의 — App Key와 App Secret은 코드에 직접 넣지 마세요. 환경 변수나 시크릿 매니저로 관리하세요.

빠른 시작

from kiwoompy import KiwoomClient

client = KiwoomClient(
    env="demo",               # "demo"(모의투자) / "real"(실계좌)
    appkey="YOUR_APP_KEY",
    secretkey="YOUR_APP_SECRET",
)

# 계좌 잔고 조회
balance = client.query.get_account_balance()
print(balance.tot_evlt_amt)   # 총평가금액

for item in balance.holdings:
    print(item.stk_nm, item.evlt_amt)
# 시장가 매수
result = client.order.buy("005930", quantity="1", trade_type="market")
print(result.ord_no)

# 지정가 매도
client.order.sell("005930", quantity="1", trade_type="limit", price="75000")

context manager도 지원합니다.

with KiwoomClient(env="demo", appkey="...", secretkey="...") as client:
    deposit = client.query.get_deposit(query_type="normal")
    print(deposit.entr)   # 예수금

기능

  • OAuth2 인증 — 접근토큰 발급·만료 자동 관리
  • 환경 분리 — 모의투자 / 실계좌 한 줄로 전환
  • 유량 제어 — 모의 2건/초, 실전 20건/초 자동 적용
  • 자동 재시도 — 네트워크 오류·5xx 지수 백오프 재시도 (최대 3회)
  • 입력값 보완 — 계좌번호 상품코드 누락 시 자동 보완
  • 타입 힌트 — IDE 자동완성·정적 분석 지원

에러 처리

from kiwoompy import KiwoomAuthError, KiwoomApiError

try:
    client = KiwoomClient(env="demo", appkey="wrong", secretkey="wrong")
except KiwoomAuthError as e:
    print(f"인증 실패: {e}")
except KiwoomApiError as e:
    print(f"API 오류: {e}")
예외 발생 조건
KiwoomAuthError 잘못된 키, 토큰 미발급 상태에서 API 호출
KiwoomApiError 네트워크 오류, 5xx 서버 오류, 응답 파싱 실패

문서

전체 사용법과 API 레퍼런스는 문서 사이트를 참고해 주세요.

👉 https://meonji-gogo.github.io/kiwoompy

키움증권 REST API 공지 알리미

키움증권 REST API 공지사항·변경 사항을 텔레그램으로 받아볼 수 있습니다.

👉 https://t.me/+2do4kWIhBmg3OTM1

라이선스

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kiwoompy-0.1.3.tar.gz (93.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kiwoompy-0.1.3-py3-none-any.whl (99.6 kB view details)

Uploaded Python 3

File details

Details for the file kiwoompy-0.1.3.tar.gz.

File metadata

  • Download URL: kiwoompy-0.1.3.tar.gz
  • Upload date:
  • Size: 93.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kiwoompy-0.1.3.tar.gz
Algorithm Hash digest
SHA256 85373b677296d55d265957ba21ba7b2387825f7238b8db0701778b2feb14f181
MD5 e02660900ec1a09bf488f9cd1e31bfbb
BLAKE2b-256 47c557d749094d2f54eeccb7bc5dbd237949959e772ba662935ca5b3ba27387a

See more details on using hashes here.

File details

Details for the file kiwoompy-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: kiwoompy-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 99.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for kiwoompy-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 736e040153b1db080f407878069e4db9496dbc8117813c48556b09bacc36f955
MD5 4fc4cfebbec8e9aff1c9d388779aeca5
BLAKE2b-256 b9e0534d06dbe1ba4641dd99109277c803721545fff36a058b9c17da36cd7da3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page