Skip to main content

python wrapper for korea broker's REST API services

Project description

Korea Investment Stock

대한민국 증권사의 Rest API 기반의 Open API에 대한 통합 파이썬 레퍼 모듈입니다. 통합 모듈이라 칵테일 이름인 모히토를 프로젝트명으로 사용하고 있으며, 돈 벌어서 몰디브가서 모히토 한 잔 하자는 의미도 있습니다.

설치

$ pip install korea-investment-stock

지원 API

카테고리 기능 함수
OAuth 인증 Hasheky issue_hashkey()
OAuth 인증 접근토근발급(P) issue_access_token()
OAuth 인증 접근토근폐기(P) 미지원
국내주식주문 주식주문(현금)
국내주식주문 주식잔고조회 fetch_balance()

사용법

한국투자증권

https://wikidocs.net/book/7845

현재가 조회

import korea_investment_stock
import pprint

key = "발급받은 API KEY"
secret = "발급받은 API SECRET"
acc_no = "12345678-01"

broker = korea_investment_stock.KoreaInvestment(api_key=key, api_secret=secret, acc_no=acc_no)
resp = broker.fetch_price("005930")
pprint.pprint(resp)

일봉 데이터 조회

import korea_investment_stock
import pprint

key = "발급받은 API KEY"
secret = "발급받은 API SECRET"
acc_no = "12345678-01"

broker = korea_investment_stock.KoreaInvestment(api_key=key, api_secret=secret, acc_no=acc_no)
resp = broker.fetch_daily_price("005930")
pprint.pprint(resp)

잔고 조회

resp = broker.fetch_balance()
pprint.pprint(resp)

주문

resp = broker.create_market_buy_order("005930", 10) # 삼성전자, 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("91252", "0000117057", "00", 60000, 5, "Y") # KRX_FWDG_ORD_ORGNO, ODNO, 지정가 주문, 가격, 수량, 모두 
print(resp)

미국주식 주문

broker = KoreaInvestment(key, secret, acc_no=acc_no, exchange="NASD")
resp = broker.create_limit_buy_order("TQQQ", 35, 1)
print(resp)

웹소켓

import pprint
import korea_investment_stock

with open("../../koreainvestment.key", encoding="utf-8") as f:
    lines = f.readlines()
key = lines[0].strip()
secret = lines[1].strip()

if __name__ == "__main__":
    broker_ws = korea_investment_stock.KoreaInvestmentWS(key, secret, ["H0STCNT0", "H0STASP0"], ["005930", "000660"],
                                                         user_id="idjhh82")
    broker_ws.start()
    while True:
        data_ = broker_ws.get()
        if data_[0] == '체결':
            print(data_[1])
        elif data_[0] == '호가':
            print(data_[1])
        elif data_[0] == '체잔':
            print(data_[1])

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

korea_investment_stock-0.2.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

korea_investment_stock-0.2.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file korea_investment_stock-0.2.0.tar.gz.

File metadata

  • Download URL: korea_investment_stock-0.2.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for korea_investment_stock-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5b1e47831cd95a7ab21914d2ea8c6cb80a25d74fd1a90d376fad891408c2c3e8
MD5 326213194406512801a4313f5d6cea8e
BLAKE2b-256 3f8e29da76cb981a8dab37bbdc4fb1e2a481ac5e1c4c5a59617612f3d8c2c38a

See more details on using hashes here.

File details

Details for the file korea_investment_stock-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for korea_investment_stock-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fea2882f5ce23bd483f03e11702bc70862c70d824b226abeb2e682b83e00e1db
MD5 8ee5c656292795eed9561b19aae7859a
BLAKE2b-256 5afc9fd7166cb2a56160a397d05a2bc63c005694edf2bdc45e49b472237326fc

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