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.6.tar.gz (95.7 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.6-py3-none-any.whl (101.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kiwoompy-0.1.6.tar.gz
  • Upload date:
  • Size: 95.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.6.tar.gz
Algorithm Hash digest
SHA256 076f2011afc3a957b1dc7f07c966f077bdbacbe567b38b865828ad1c69fb8e49
MD5 6b3ed2771227fc6529ab15075292cb88
BLAKE2b-256 43bdb920926ae39032d15cac3a7f488231e1f8760a85abf8acaa474aa8709b75

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kiwoompy-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 101.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c78ea0cb09b70ae0862b29d5895f8eea535dd1fa6a8f0feb0a64f5bdc9d79e6c
MD5 445e41ac34b2b473c01f4f68bc460ea8
BLAKE2b-256 28fd0be6970a11b3b6cae6cc9372156254cb2dcc2b1c095ca3166897397d1ad5

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