python wrapper for korea broker's REST API services
Project description
모히토 (Mojito)
대한민국 증권사의 Rest API 기반의 Open API에 대한 통합 파이썬 레퍼 모듈입니다. 통합 모듈이라 칵테일 이름인 모히토를 프로젝트명으로 사용하고 있으며, 돈 벌어서 몰디브가서 모히토 한 잔 하자는 의미도 있습니다.
설치
$ pip install mojito2
사용법
한국투자증권
현재가 조회
import mojito
key = "발급받은 API KEY"
secret = "발급받은 API SECRET"
broker = mojito.KoreaInvestment(api_key=key, api_secret=secret)
resp = broker.fetch_price("005930")
pprint.pprint(resp)
일봉 데이터 조회
import mojito
key = "발급받은 API KEY"
secret = "발급받은 API SECRET"
broker = mojito.KoreaInvestment(api_key=key, api_secret=secret)
resp = broker.fetch_daily_price("J", "005930")
pprint.pprint(resp)
잔고 조회
resp = broker.fetch_balance("00000000") # 계좌번호 8자리
pprint.pprint(resp)
주문
resp = broker.create_market_buy_order("00000000", "005930", 10) # 계좌번호 8자리, 삼성전자, 10주, 시장
pprint.pprint(resp)
{'rt_cd': '0',
'msg_cd': 'APBK0013',
'msg1': '주문 전송 완료 되었습니다.',
'output': {'KRX_FWDG_ORD_ORGNO': '91252',
'ODNO': '0000117057',
'ORD_TMD': '121052'}}
주문 취소
resp = broker.cancel_order("00000000", "91252", "0000117057", "00", 60000, 5, "Y") # 계좌번호, KRX_FWDG_ORD_ORGNO, ODNO, 지정가 주문, 가격, 수량, 모두
print(resp)
미국주식 주문
broker = KoreaInvestment(key, secret, exchange="NASD")
resp = broker.create_limit_buy_order("63398082", "TQQQ", 35, 1)
print(resp)
실시간주식 체결가 (웹소켓)
broker_ws = KoreaInvestmentWS(key, secret, "H0STCNT0", "005930")
broker_ws.start()
for i in range(3):
data = broker_ws.get()
print(data)
실시간주식 호가 (웹소켓)
broker_ws = KoreaInvestmentWS(key, secret, "H0STASP0", "005930")
broker_ws.start()
for i in range(3):
data = broker_ws.get()
print(data)
실시간주식체결통보
broker_ws = KoreaInvestmentWS(key, secret, "H0STCNI0", "userid") # 사용자 아이디
broker_ws.start()
for i in range(3):
data = broker_ws.get()
print(data)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mojito2-0.0.6.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mojito2-0.0.6.tar.gz.
File metadata
- Download URL: mojito2-0.0.6.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a09951940c0bb4aef3d46e78e548911180ac016c3d2e7b443c80f02d164bcdb
|
|
| MD5 |
db835ef9fc16450c54ea14899bae6edb
|
|
| BLAKE2b-256 |
b43c1f4bfd3e171fe0f7885692eb07630cb7b56492cce30963f52a0b7c59e452
|
File details
Details for the file mojito2-0.0.6-py3-none-any.whl.
File metadata
- Download URL: mojito2-0.0.6-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e92aab777b1a9d618d6a7377d869b5b9ad73696e7d9e7cfdbd7309bd0c4fdd
|
|
| MD5 |
267d2bb453ff0553d90f8e2ceec26b7c
|
|
| BLAKE2b-256 |
57ca33e46bfceceadcb271477a3f8b68d04605f1e74fd247f439c18892db9888
|