tossinvest-client
토스증권 Open API를 파이썬에서 쓰기 위한 작은 비공식 클라이언트입니다.
비공식 프로젝트입니다. 토스증권(비바리퍼블리카)과 관계없는 개인 프로젝트이며, 토스증권이 만들거나 검증하지 않았습니다. An unofficial, minimal Python client for the Toss Securities Open API. Not affiliated with Toss Securities.
API를 직접 부를 때 번거로운 부분을 대신 처리합니다.
- 토큰: 받아서 파일에 저장해 두고 만료 5분 전에 새로 받습니다. 만료·폐기 오류가 오면 한 번 새로 받아 다시 보냅니다.
- 호출 간격: 토스 문서의 경로별 초당 한도에 맞춰 알아서 쉬었다 보냅니다.
- 다시 보내기: 429(요청 과다)는
Retry-After만큼 쉬고, 5xx·네트워크 오류는 잠깐 쉬고 다시 보냅니다. 주문 정정·취소는 두 번 처리될 수 있어 5xx·네트워크 오류 때 다시 보내지 않습니다. - 오류: 응답의 오류 코드·메시지·data를
TossError로 돌려줍니다. 허용 IP 미등록(403)이면 어디서 등록하는지 알려 줍니다. - 나눠 조회: 현재가·종목 정보는 200개씩 나눠 부르고 합쳐 줍니다.
- 계좌: 계좌가 필요한 요청에는 종합 위탁 계좌(첫 번째
BROKERAGE)를 자동으로 붙입니다.
설치
pip install git+https://github.com/hoyeon71/tossinvest-client
Python 3.10 이상, 필요한 패키지는 requests 하나입니다.
준비
- 토스증권 PC 웹 → 설정 → Open API에서
client_id,client_secret을 발급받습니다. - 같은 메뉴의 허용 IP 관리에 이 프로그램을 돌릴 PC의 인터넷 주소를 등록합니다. 등록하지 않은 곳에서 부르면 403으로 막힙니다.
- 키는 코드에 적지 말고 환경 변수 등으로 넘기세요.
사용
import os
from tossinvest_client import TossClient, TossError
c = TossClient(os.environ["TOSS_CLIENT_ID"], os.environ["TOSS_CLIENT_SECRET"])
c.prices(["005930"]) # 현재가
c.candles("005930") # 일봉 200개 (interval="1m" 이면 1분봉)
c.holdings() # 보유 종목
c.buying_power("KRW") # 원화 매수 가능 금액
try:
# ⚠ 실제 주문이 나갑니다. price를 주면 지정가, 안 주면 시장가
order_id = c.place_order("005930", "BUY", 1, client_order_id="my-order-0001")
except TossError as e:
print(e.status, e.code, e.message, e.data)
| 메서드 | 하는 일 | 돌려주는 것 |
|---|---|---|
accounts() |
계좌 목록 | 목록 |
holdings() |
보유 종목 | API 응답 그대로 |
buying_power(currency) |
매수 가능 금액 ("KRW", "USD") |
숫자 |
prices(symbols) |
현재가 | 목록 |
candles(symbol, count=200, before=None, interval="1d") |
봉 | API 응답 그대로 |
orderbook(symbol) |
호가 | API 응답 그대로 |
stocks(symbols), stocks_all(exchange) |
종목 정보, 시장 전체 종목 | 목록 |
market_calendar(market) |
장 운영 달력 ("kr", "us") |
API 응답 그대로 |
upper_limit(symbol) |
당일 상한가 (미국처럼 가격제한이 없으면 None) |
숫자 또는 None |
warnings(symbol) |
투자 경고 | 목록 |
usd_krw() |
원/달러 환율 (500~3000 밖이면 오류) | 숫자 |
open_orders(symbol) |
미체결 주문 | 목록 |
place_order(symbol, side, quantity, client_order_id, price=None) |
주문 (side는 "BUY"/"SELL") |
주문번호 |
modify_order(order_id, price) |
정정 (price=None이면 시장가로) |
새 주문번호 |
cancel_order(order_id) |
취소 | 새 주문번호 |
"API 응답 그대로"는 토스 응답의 result 값을 손대지 않고 돌려준다는 뜻입니다. 필드 이름은 토스증권 Open API 문서를 보세요.
주의
- 주문 함수는 실제 계좌로 주문을 냅니다. 처음에는 소량으로 확인하세요. 이 코드로 생긴 손실은 쓰는 사람의 책임입니다(MIT 라이선스, 보증 없음). 투자 조언이 아닙니다.
client_order_id는 주문마다 다른 값을 쓰세요. 같은 값으로 다시 보내면 토스가 한 번만 처리하므로, 네트워크 오류 뒤 다시 보내도 주문이 두 번 나가지 않습니다.- 접근 토큰은
~/.cache/tossinvest-client/token.json에 저장됩니다(TossClient(..., token_path=...)로 바꿀 수 있음). 이 파일을 가진 사람은 만료 전까지 계좌를 조회·주문할 수 있으니 공유하지 마세요.client_secret은 파일에 쓰지 않습니다. - 짧은 시간에 소액 주문을 대량으로 반복하면 토스가 어뷰징으로 보고 매매를 제한할 수 있습니다.
토스증권 데이터 이용 정책
토스증권 Open API로 받은 정보는 투자자 본인의 매매 목적으로만 써야 하고, 상업적 이용은 물론 비상업적 용도라도 제3자에게 배포하는 것은 금지되어 있습니다(토스증권 Open API FAQ). 이 라이브러리는 코드만 담고 있고 데이터는 담고 있지 않습니다. 받은 시세·계좌 데이터를 공개하거나 남에게 넘기지 마세요.
지원하지 않는 것
실시간 시세(WebSocket), 조건 주문 등 위 표에 없는 API는 아직 없습니다.
시험
python tests/test_tossinvest_client.py
인터넷 없이 가짜 응답으로 시험합니다. 마지막까지 오류 없이 끝나면 통과입니다.
라이선스
MIT
Metadata
Release files for tossinvest-client 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tossinvest_client-0.1.0.tar.gz | 10.8 kB | With provenance | Details for tossinvest_client-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tossinvest_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tossinvest_client-0.1.0-py3-none-any.whl |
Total release size: 19.6 kB
Release files / tossinvest_client-0.1.0.tar.gz
| Download URL | tossinvest_client-0.1.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f21c1ac102175c2f35ecad51a7650b1b22f3d6387bfe4347e7e77c56d03503f6
|
|
BLAKE2b-256 checksum How to use checksums |
535331892014d41d05d6f704a00402024846d596b2132bf826926af4a08939f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / tossinvest_client-0.1.0-py3-none-any.whl
| Download URL | tossinvest_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dbb11c076ea99ee4527645dcc52b61026ea10eac9fa23843c64c3c4c28a1d76
|
|
BLAKE2b-256 checksum How to use checksums |
068a96d3b7a5f104135d90c44177835e65a5c95ea31d07f95386f867f7d91a12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for tossinvest-client 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for tossinvest_client-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.