KIS Developers menu

API 문서 HOME API 문서 [국내주식] 실시간시세


[국내주식] 실시간시세

국내주식 실시간체결가[실시간-003]

WEBSOCKET

국내주식 실시간체결가[실시간-003]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    ws://ops.koreainvestment.com:31000
  • URL
    /tryitout/H0STCNT0
  • Format
    JSON
  • Content-Type
    text/plain

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py
실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

※ 데이터가 많은 경우 여러 건을 페이징 처리해서 데이터를 보내는 점 참고 부탁드립니다.
ex) 0|H0STCNT0|004|... 인 경우 004가 데이터 개수를 의미하여, 뒤에 체결데이터가 4건 들어옴
→ 0|H0STCNT0|004|005930^123929...(체결데이터1)...^005930^123929...(체결데이터2)...^005930^123929...(체결데이터3)...^005930^123929...(체결데이터4)...

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 286 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객타입 String Y 1 B : 법인
P : 개인
tr_type 거래타입 String Y 1 1 : 등록
2 : 해제
content-type 컨텐츠타입 String Y 1 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 1 [실전/모의투자]
H0STCNT0 : 실시간 주식 체결가
tr_key 구분값 String Y 1 종목번호 (6자리)
ETN의 경우, Q로 시작 (EX. Q500001)

Response

Body

Element 한글명 Type Required Length Description
MKSC_SHRN_ISCD 유가증권 단축 종목코드 String Y 9
STCK_CNTG_HOUR 주식 체결 시간 String Y 6
STCK_PRPR 주식 현재가 Number Y 4
PRDY_VRSS_SIGN 전일 대비 부호 String Y 1 1 : 상한
2 : 상승
3 : 보합
4 : 하한
5 : 하락
PRDY_VRSS 전일 대비 Number Y 4
PRDY_CTRT 전일 대비율 Number Y 8
WGHN_AVRG_STCK_PRC 가중 평균 주식 가격 Number Y 8
STCK_OPRC 주식 시가 Number Y 4
STCK_HGPR 주식 최고가 Number Y 4
STCK_LWPR 주식 최저가 Number Y 4
ASKP1 매도호가1 Number Y 4
BIDP1 매수호가1 Number Y 4
CNTG_VOL 체결 거래량 Number Y 8
ACML_VOL 누적 거래량 Number Y 8
ACML_TR_PBMN 누적 거래 대금 Number Y 8
SELN_CNTG_CSNU 매도 체결 건수 Number Y 4
SHNU_CNTG_CSNU 매수 체결 건수 Number Y 4
NTBY_CNTG_CSNU 순매수 체결 건수 Number Y 4
CTTR 체결강도 Number Y 8
SELN_CNTG_SMTN 총 매도 수량 Number Y 8
SHNU_CNTG_SMTN 총 매수 수량 Number Y 8
CCLD_DVSN 체결구분 String Y 1 1:매수(+)
3:장전
5:매도(-)
SHNU_RATE 매수비율 Number Y 8
PRDY_VOL_VRSS_ACML_VOL_RATE 전일 거래량 대비 등락율 Number Y 8
OPRC_HOUR 시가 시간 String Y 6
OPRC_VRSS_PRPR_SIGN 시가대비구분 String Y 1 1 : 상한
2 : 상승
3 : 보합
4 : 하한
5 : 하락
OPRC_VRSS_PRPR 시가대비 Number Y 4
HGPR_HOUR 최고가 시간 String Y 6
HGPR_VRSS_PRPR_SIGN 고가대비구분 String Y 1 1 : 상한
2 : 상승
3 : 보합
4 : 하한
5 : 하락
HGPR_VRSS_PRPR 고가대비 Number Y 4
LWPR_HOUR 최저가 시간 String Y 6
LWPR_VRSS_PRPR_SIGN 저가대비구분 String Y 1 1 : 상한
2 : 상승
3 : 보합
4 : 하한
5 : 하락
LWPR_VRSS_PRPR 저가대비 Number Y 4
BSOP_DATE 영업 일자 String Y 8
NEW_MKOP_CLS_CODE 신 장운영 구분 코드 String Y 2 (1) 첫 번째 비트
1 : 장개시전
2 : 장중
3 : 장종료후
4 : 시간외단일가
7 : 일반Buy-in
8 : 당일Buy-in

(2) 두 번째 비트
0 : 보통
1 : 종가
2 : 대량
3 : 바스켓
7 : 정리매매
8 : Buy-in
TRHT_YN 거래정지 여부 String Y 1 Y : 정지
N : 정상거래
ASKP_RSQN1 매도호가 잔량1 Number Y 8
BIDP_RSQN1 매수호가 잔량1 Number Y 8
TOTAL_ASKP_RSQN 총 매도호가 잔량 Number Y 8
TOTAL_BIDP_RSQN 총 매수호가 잔량 Number Y 8
VOL_TNRT 거래량 회전율 Number Y 8
PRDY_SMNS_HOUR_ACML_VOL 전일 동시간 누적 거래량 Number Y 8
PRDY_SMNS_HOUR_ACML_VOL_RATE 전일 동시간 누적 거래량 비율 Number Y 8
HOUR_CLS_CODE 시간 구분 코드 String Y 1 0 : 장중
A : 장후예상
B : 장전예상
C : 9시이후의 예상가, VI발동
D : 시간외 단일가 예상
MRKT_TRTM_CLS_CODE 임의종료구분코드 String Y 1
VI_STND_PRC 정적VI발동기준가 Number Y 4

Example

Request

{
         "header":
         {
                  "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
                  "custtype":"P",
                  "tr_type":"1",
                  "content-type":"utf-8"
         },
         "body":
         {
                  "input":
                  {
                           "tr_id":"H0STCNT0",
                           "tr_key":"005930"
                  }
         }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0STCNT0", 
        "tr_key": "005930", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
005930^093354^71900^5^-100^-0.14^72023.83^72100^72400^71700^71900^71800^1^3052
507^219853241700^5105^6937^1832^84.90^1366314^1159996^1^0.39^20.28^090020^5^-2
00^090820^5^-500^092619^2^200^20230612^20^N^65945^216924^1118750^2199206^0.05^
2424142^125.92^0^^72100

국내주식 실시간호가[실시간-004]

WEBSOCKET

국내주식 실시간호가[실시간-004]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    ws://ops.koreainvestment.com:31000
  • URL
    /tryitout/H0STASP0
  • Format
     
  • Content-Type
    text/plain

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id
- 데이터 건수 : (ex. 001 데이터 건수를 참조하여 활용)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 286 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객타입 String Y 1 B : 법인
P : 개인
tr_type 거래타입 String Y 1 1 : 등록
2 : 해제
content-type 컨텐츠타입 String Y 1 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 1 [실전/모의투자]
H0STASP0 : 주식호가
tr_key 구분값 String Y 1 종목번호 (6자리)
ETN의 경우, Q로 시작 (EX. Q500001)

Response

Body

Element 한글명 Type Required Length Description
MKSC_SHRN_ISCD 유가증권 단축 종목코드 String Y 9
BSOP_HOUR 영업 시간 String Y 6
HOUR_CLS_CODE 시간 구분 코드 String Y 1 0 : 장중
A : 장후예상
B : 장전예상
C : 9시이후의 예상가, VI발동
D : 시간외 단일가 예상
ASKP1 매도호가1 Number Y 4
ASKP2 매도호가2 Number Y 4
ASKP3 매도호가3 Number Y 4
ASKP4 매도호가4 Number Y 4
ASKP5 매도호가5 Number Y 4
ASKP6 매도호가6 Number Y 4
ASKP7 매도호가7 Number Y 4
ASKP8 매도호가8 Number Y 4
ASKP9 매도호가9 Number Y 4
ASKP10 매도호가10 Number Y 4
BIDP1 매수호가1 Number Y 4
BIDP2 매수호가2 Number Y 4
BIDP3 매수호가3 Number Y 4
BIDP4 매수호가4 Number Y 4
BIDP5 매수호가5 Number Y 4
BIDP6 매수호가6 Number Y 4
BIDP7 매수호가7 Number Y 4
BIDP8 매수호가8 Number Y 4
BIDP9 매수호가9 Number Y 4
BIDP10 매수호가10 Number Y 4
ASKP_RSQN1 매도호가 잔량1 Number Y 8
ASKP_RSQN2 매도호가 잔량2 Number Y 8
ASKP_RSQN3 매도호가 잔량3 Number Y 8
ASKP_RSQN4 매도호가 잔량4 Number Y 8
ASKP_RSQN5 매도호가 잔량5 Number Y 8
ASKP_RSQN6 매도호가 잔량6 Number Y 8
ASKP_RSQN7 매도호가 잔량7 Number Y 8
ASKP_RSQN8 매도호가 잔량8 Number Y 8
ASKP_RSQN9 매도호가 잔량9 Number Y 8
ASKP_RSQN10 매도호가 잔량10 Number Y 8
BIDP_RSQN1 매수호가 잔량1 Number Y 8
BIDP_RSQN2 매수호가 잔량2 Number Y 8
BIDP_RSQN3 매수호가 잔량3 Number Y 8
BIDP_RSQN4 매수호가 잔량4 Number Y 8
BIDP_RSQN5 매수호가 잔량5 Number Y 8
BIDP_RSQN6 매수호가 잔량6 Number Y 8
BIDP_RSQN7 매수호가 잔량7 Number Y 8
BIDP_RSQN8 매수호가 잔량8 Number Y 8
BIDP_RSQN9 매수호가 잔량9 Number Y 8
BIDP_RSQN10 매수호가 잔량10 Number Y 8
TOTAL_ASKP_RSQN 총 매도호가 잔량 Number Y 8
TOTAL_BIDP_RSQN 총 매수호가 잔량 Number Y 8
OVTM_TOTAL_ASKP_RSQN 시간외 총 매도호가 잔량 Number Y 8
OVTM_TOTAL_BIDP_RSQN 시간외 총 매수호가 잔량 Number Y 8
ANTC_CNPR 예상 체결가 Number Y 4 동시호가 등 특정 조건하에서만 발생
ANTC_CNQN 예상 체결량 Number Y 8 동시호가 등 특정 조건하에서만 발생
ANTC_VOL 예상 거래량 Number Y 8 동시호가 등 특정 조건하에서만 발생
ANTC_CNTG_VRSS 예상 체결 대비 Number Y 4 동시호가 등 특정 조건하에서만 발생
ANTC_CNTG_VRSS_SIGN 예상 체결 대비 부호 String Y 1 동시호가 등 특정 조건하에서만 발생

1 : 상한
2 : 상승
3 : 보합
4 : 하한
5 : 하락
ANTC_CNTG_PRDY_CTRT 예상 체결 전일 대비율 Number Y 8
ACML_VOL 누적 거래량 Number Y 8
TOTAL_ASKP_RSQN_ICDC 총 매도호가 잔량 증감 Number Y 4
TOTAL_BIDP_RSQN_ICDC 총 매수호가 잔량 증감 Number Y 4
OVTM_TOTAL_ASKP_ICDC 시간외 총 매도호가 증감 Number Y 4
OVTM_TOTAL_BIDP_ICDC 시간외 총 매수호가 증감 Number Y 4
STCK_DEAL_CLS_CODE 주식 매매 구분 코드 String Y 2 사용 X (삭제된 값)

Example

Request

{
         "header":
         {
                  "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
                  "custtype":"P",
                  "tr_type":"1",
                  "content-type":"utf-8"
         },
         "body":
         {
                  "input":
                  {
                           "tr_id":"H0STASP0",
                           "tr_key":"005930"
                  }
         }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0STASP0", 
        "tr_key": "005930", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
005930^093730^0^71900^72000^72100^72200^72300^72400^72500^72600^72700^72800^71
800^71700^71600^71500^71400^71300^71200^71100^71000^70900^91918^117942^92673^7
9708^106729^141988^176192^113906^134077^104229^95221^159371^220746^284657^2127
42^195370^182710^209747^376432^158171^1159362^2095167^0^0^0^0^525579^-72000^5^
-100.00^3159115^0^8^0^0^0

국내주식 실시간체결통보[실시간-005]

WEBSOCKET

국내주식 실시간체결통보[실시간-005]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    ws://ops.koreainvestment.com:31000
  • URL
    /tryitout/H0STCNI0
  • Format
     
  • Content-Type
    test/plain

개요

국내주식 실시간 체결통보 수신 시에 (1) 주문·정정·취소·거부 접수 통보 와 (2) 체결 통보 가 모두 수신됩니다.
(14번째 값(CNTG_YN;체결여부)가 2이면 체결통보, 1이면 주문·정정·취소·거부 접수 통보입니다.)

※ 모의투자는 H0STCNI9 로 변경하여 사용합니다.

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id
- 데이터 건수 : (ex. 001 데이터 건수를 참조하여 활용)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

체결 통보 응답 결과는 암호화되어 출력됩니다. AES256 KEY IV를 활용해 복호화하여 활용하세요. 자세한 예제는 [도구>wikidocs]에 준비되어 있습니다.

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 286 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객타입 String Y 1 B : 법인
P : 개인
tr_type 거래타입 String Y 1 1 : 등록
2 : 해제
content-type 컨텐츠타입 String Y 1 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 1 [실전투자]
H0STCNI0 : 실시간 주식 체결통보

[모의투자]
H0STCNI9 : 실시간 주식 체결통보
tr_key 구분값 String Y 1 HTS ID

Response

Body

Element 한글명 Type Required Length Description
CUST_ID 고객 ID String Y 8
ACNT_NO 계좌번호 String Y 10
ODER_NO 주문번호 String Y 10
OODER_NO 원주문번호 String Y 10
SELN_BYOV_CLS 매도매수구분 String Y 2 01 : 매도
02 : 매수
RCTF_CLS 정정구분 String Y 1
ODER_KIND 주문종류 String Y 2 주문통보: 주문낸 주문종류로 수신 / 체결통보: 00으로 수신
00 : 지정가
01 : 시장가
02 : 조건부지정가
03 : 최유리지정가
04 : 최우선지정가
05 : 장전 시간외
06 : 장후 시간외
07 : 시간외 단일가
08 : 자기주식
09 : 자기주식S-Option
10 : 자기주식금전신탁
11 : IOC지정가 (즉시체결,잔량취소)
12 : FOK지정가 (즉시체결,전량취소)
13 : IOC시장가 (즉시체결,잔량취소)
14 : FOK시장가 (즉시체결,전량취소)
15 : IOC최유리 (즉시체결,잔량취소)
16 : FOK최유리 (즉시체결,전량취소)
ODER_COND 주문조건 String Y 1
STCK_SHRN_ISCD 주식 단축 종목코드 String Y 9
CNTG_QTY 체결 수량 String Y 10 체결통보(CNTG_YN=2): 체결 수량
주문·정정·취소·거부 접수 통보(CNTG_YN=1): 주문수량
을 의미함
CNTG_UNPR 체결단가 String Y 9
STCK_CNTG_HOUR 주식 체결 시간 String Y 6
RFUS_YN 거부여부 String Y 1 0 : 승인
1 : 거부
CNTG_YN 체결여부 String Y 1 1 : 주문,정정,취소,거부
2 : 체결 (★ 체결만 보실경우 2번만 보시면 됩니다)
ACPT_YN 접수여부 String Y 1 1 : 주문접수
2 : 확인
3: 취소(FOK/IOC)
BRNC_NO 지점번호 String Y 5
ODER_QTY 주문수량 String Y 9
ACNT_NAME 계좌명 String Y 12
CNTG_ISNM 체결종목명 String Y 14
CRDT_CLS 신용구분 String Y 2
CRDT_LOAN_DATE 신용대출일자 String Y 8
CNTG_ISNM40 체결종목명40 String Y 40
ODER_PRC 주문가격 String Y 9 체결통보(CNTG_YN=2): 주문 가격
주문·정정·취소·거부 접수 통보(CNTG_YN=1): 체결단가(빈값으로 수신)
을 의미함

Example

Request

{
         "header":
         {
                  "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
                  "custtype":"P",
                  "tr_type":"1",
                  "content-type":"utf-8"
         },
         "body":
         {
                  "input":
                  {
                           "tr_id":"H0STCNI0",
                           "tr_key":"HTS ID"
                  }
         }
}

Response

{
    "header": {
        "tr_id": "H0STCNI0", 
        "tr_key": "HTS ID", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output - 주문·정정·취소·거부 접수 통보
HTS ID^1234567801^0000002891^^02^0^01^0^136480^0000000001^000000000^094941^0
^1^1^06010^000000001^김한투^하림^10^^하림^

# output - 체결 통보
HTS ID^1234567801^0000002891^^02^0^00^0^136480^0000000001^000003190^094941^0
^2^2^06010^000000001^김한투^하림^10^^하림^000000000

국내지수 실시간체결 [실시간-026]

WEBSOCKET

국내지수 실시간체결 [실시간-026]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    모의투자 미지원
  • URL
    /tryitout/H0UPCNT0
  • Format
     
  • Content-Type
     

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0UPCNT0
tr_key 종목코드 String Y 6 업종구분코드

Response

Body

Element 한글명 Type Required Length Description
bstp_cls_code 업종 구분 코드 Object Y 4 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-bsop_hour 영업 시간 String Y 6
-prpr_nmix 현재가 지수 String Y 1
-prdy_vrss_sign 전일 대비 부호 String Y 1
-bstp_nmix_prdy_vrss 업종 지수 전일 대비 String Y 1
-acml_vol 누적 거래량 String Y 1
-acml_tr_pbmn 누적 거래 대금 String Y 1
-pcas_vol 건별 거래량 String Y 1
-pcas_tr_pbmn 건별 거래 대금 String Y 1
-prdy_ctrt 전일 대비율 String Y 1
-oprc_nmix 시가 지수 String Y 1
-nmix_hgpr 지수 최고가 String Y 1
-nmix_lwpr 지수 최저가 String Y 1
-oprc_vrss_nmix_prpr 시가 대비 지수 현재가 String Y 1
-oprc_vrss_nmix_sign 시가 대비 지수 부호 String Y 1
-hgpr_vrss_nmix_prpr 최고가 대비 지수 현재가 String Y 1
-hgpr_vrss_nmix_sign 최고가 대비 지수 부호 String Y 1
-lwpr_vrss_nmix_prpr 최저가 대비 지수 현재가 String Y 1
-lwpr_vrss_nmix_sign 최저가 대비 지수 부호 String Y 1
-prdy_clpr_vrss_oprc_rate 전일 종가 대비 시가2 비율 String Y 1
-prdy_clpr_vrss_hgpr_rate 전일 종가 대비 최고가 비율 String Y 1
-prdy_clpr_vrss_lwpr_rate 전일 종가 대비 최저가 비율 String Y 1
-uplm_issu_cnt 상한 종목 수 String Y 1
-ascn_issu_cnt 상승 종목 수 String Y 1
-stnr_issu_cnt 보합 종목 수 String Y 1
-down_issu_cnt 하락 종목 수 String Y 1
-lslm_issu_cnt 하한 종목 수 String Y 1
-qtqt_ascn_issu_cnt 기세 상승 종목수 String Y 1
-qtqt_down_issu_cnt 기세 하락 종목수 String Y 1
-tick_vrss TICK대비 String Y 1

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0UPCNT0",
            "tr_key": "0001"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0UPCNT0", 
        "tr_key": "0001", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0UPCNT0|001|0001^091240^2624.54^2^32.68^63952^1650684^439^10335^1.26^2615
.72^2624.82^2610.00^23.86^2^32.96^2^18.14^2^0.92^1.27^0.70^0^670^72^177^0^0^0^19

국내지수 실시간예상체결 [실시간-027]

WEBSOCKET

국내지수 실시간예상체결 [실시간-027]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
     
  • URL
    /tryitout/H0UPANC0
  • Format
     
  • Content-Type
     

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0UPANC0
tr_key 종목코드 String Y 6 업종구분코드

Response

Body

Element 한글명 Type Required Length Description
bstp_cls_code 업종 구분 코드 Object Y 4 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-bsop_hour 영업 시간 String Y 6
-prpr_nmix 현재가 지수 String Y 1
-prdy_vrss_sign 전일 대비 부호 String Y 1
-bstp_nmix_prdy_vrss 업종 지수 전일 대비 String Y 1
-acml_vol 누적 거래량 String Y 1
-acml_tr_pbmn 누적 거래 대금 String Y 1
-pcas_vol 건별 거래량 String Y 1
-pcas_tr_pbmn 건별 거래 대금 String Y 1
-prdy_ctrt 전일 대비율 String Y 1
-oprc_nmix 시가 지수 String Y 1
-nmix_hgpr 지수 최고가 String Y 1
-nmix_lwpr 지수 최저가 String Y 1
-oprc_vrss_nmix_prpr 시가 대비 지수 현재가 String Y 1
-oprc_vrss_nmix_sign 시가 대비 지수 부호 String Y 1
-hgpr_vrss_nmix_prpr 최고가 대비 지수 현재가 String Y 1
-hgpr_vrss_nmix_sign 최고가 대비 지수 부호 String Y 1
-lwpr_vrss_nmix_prpr 최저가 대비 지수 현재가 String Y 1
-lwpr_vrss_nmix_sign 최저가 대비 지수 부호 String Y 1
-prdy_clpr_vrss_oprc_rate 전일 종가 대비 시가2 비율 String Y 1
-prdy_clpr_vrss_hgpr_rate 전일 종가 대비 최고가 비율 String Y 1
-prdy_clpr_vrss_lwpr_rate 전일 종가 대비 최저가 비율 String Y 1
-uplm_issu_cnt 상한 종목 수 String Y 1
-ascn_issu_cnt 상승 종목 수 String Y 1
-stnr_issu_cnt 보합 종목 수 String Y 1
-down_issu_cnt 하락 종목 수 String Y 1
-lslm_issu_cnt 하한 종목 수 String Y 1
-qtqt_ascn_issu_cnt 기세 상승 종목수 String Y 1
-qtqt_down_issu_cnt 기세 하락 종목수 String Y 1
-tick_vrss TICK대비 String Y 1

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0UPANC0",
            "tr_key": "0001"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0UPANC0", 
        "tr_key": "0001", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0UPANC0|001|0001^085910^2607.71^2^15.85^5424^192338^5424^192338^0.61^0^43
9^201^251^201

국내지수 실시간프로그램매매 [실시간-028]

WEBSOCKET

국내지수 실시간프로그램매매 [실시간-028]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    모의투자 미지원
  • URL
    /tryitout/H0UPPGM0
  • Format
     
  • Content-Type
     

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0UPPGM0
tr_key 종목코드 String Y 6 업종구분코드

Response

Body

Element 한글명 Type Required Length Description
bstp_cls_code 업종 구분 코드 Object Y 4 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-bsop_hour 영업 시간 String Y 6
-arbt_seln_entm_cnqn 차익 매도 위탁 체결량 String Y 1
-arbt_seln_onsl_cnqn 차익 매도 자기 체결량 String Y 1
-arbt_shnu_entm_cnqn 차익 매수2 위탁 체결량 String Y 1
-arbt_shnu_onsl_cnqn 차익 매수2 자기 체결량 String Y 1
-nabt_seln_entm_cnqn 비차익 매도 위탁 체결량 String Y 1
-nabt_seln_onsl_cnqn 비차익 매도 자기 체결량 String Y 1
-nabt_shnu_entm_cnqn 비차익 매수2 위탁 체결량 String Y 1
-nabt_shnu_onsl_cnqn 비차익 매수2 자기 체결량 String Y 1
-arbt_seln_entm_cntg_amt 차익 매도 위탁 체결 금액 String Y 1
-arbt_seln_onsl_cntg_amt 차익 매도 자기 체결 금액 String Y 1
-arbt_shnu_entm_cntg_amt 차익 매수2 위탁 체결 금액 String Y 1
-arbt_shnu_onsl_cntg_amt 차익 매수2 자기 체결 금액 String Y 1
-nabt_seln_entm_cntg_amt 비차익 매도 위탁 체결 금액 String Y 1
-nabt_seln_onsl_cntg_amt 비차익 매도 자기 체결 금액 String Y 1
-nabt_shnu_entm_cntg_amt 비차익 매수2 위탁 체결 금액 String Y 1
-nabt_shnu_onsl_cntg_amt 비차익 매수2 자기 체결 금액 String Y 1
-arbt_smtn_seln_vol 차익 합계 매도 거래량 String Y 1
-arbt_smtm_seln_vol_rate 차익 합계 매도 거래량 비율 String Y 1
-arbt_smtn_seln_tr_pbmn 차익 합계 매도 거래 대금 String Y 1
-arbt_smtm_seln_tr_pbmn_rate 차익 합계 매도 거래대금 비율 String Y 1
-arbt_smtn_shnu_vol 차익 합계 매수2 거래량 String Y 1
-arbt_smtm_shnu_vol_rate 차익 합계 매수 거래량 비율 String Y 1
-arbt_smtn_shnu_tr_pbmn 차익 합계 매수2 거래 대금 String Y 1
-arbt_smtm_shnu_tr_pbmn_rate 차익 합계 매수 거래대금 비율 String Y 1
-arbt_smtn_ntby_qty 차익 합계 순매수 수량 String Y 1
-arbt_smtm_ntby_qty_rate 차익 합계 순매수 수량 비율 String Y 1
-arbt_smtn_ntby_tr_pbmn 차익 합계 순매수 거래 대금 String Y 1
-arbt_smtm_ntby_tr_pbmn_rate 차익 합계 순매수 거래대금 비율 String Y 1
-nabt_smtn_seln_vol 비차익 합계 매도 거래량 String Y 1
-nabt_smtm_seln_vol_rate 비차익 합계 매도 거래량 비율 String Y 1
-nabt_smtn_seln_tr_pbmn 비차익 합계 매도 거래 대금 String Y 1
-nabt_smtm_seln_tr_pbmn_rate 비차익 합계 매도 거래대금 비율 String Y 1
-nabt_smtn_shnu_vol 비차익 합계 매수2 거래량 String Y 1
-nabt_smtm_shnu_vol_rate 비차익 합계 매수 거래량 비율 String Y 1
-nabt_smtn_shnu_tr_pbmn 비차익 합계 매수2 거래 대금 String Y 1
-nabt_smtm_shnu_tr_pbmn_rate 비차익 합계 매수 거래대금 비율 String Y 1
-nabt_smtn_ntby_qty 비차익 합계 순매수 수량 String Y 1
-nabt_smtm_ntby_qty_rate 비차익 합계 순매수 수량 비율 String Y 1
-nabt_smtn_ntby_tr_pbmn 비차익 합계 순매수 거래 대금 String Y 1
-nabt_smtm_ntby_tr_pbmn_rate 비차익 합계 순매수 거래대금 비 String Y 1
-whol_entm_seln_vol 전체 위탁 매도 거래량 String Y 1
-entm_seln_vol_rate 위탁 매도 거래량 비율 String Y 1
-whol_entm_seln_tr_pbmn 전체 위탁 매도 거래 대금 String Y 1
-entm_seln_tr_pbmn_rate 위탁 매도 거래대금 비율 String Y 1
-whol_entm_shnu_vol 전체 위탁 매수2 거래량 String Y 1
-entm_shnu_vol_rate 위탁 매수 거래량 비율 String Y 1
-whol_entm_shnu_tr_pbmn 전체 위탁 매수2 거래 대금 String Y 1
-entm_shnu_tr_pbmn_rate 위탁 매수 거래대금 비율 String Y 1
-whol_entm_ntby_qt 전체 위탁 순매수 수량 String Y 1
-entm_ntby_qty_rat 위탁 순매수 수량 비율 String Y 1
-whol_entm_ntby_tr_pbmn 전체 위탁 순매수 거래 대금 String Y 1
-entm_ntby_tr_pbmn_rate 위탁 순매수 금액 비율 String Y 1
-whol_onsl_seln_vol 전체 자기 매도 거래량 String Y 1
-onsl_seln_vol_rate 자기 매도 거래량 비율 String Y 1
-whol_onsl_seln_tr_pbmn 전체 자기 매도 거래 대금 String Y 1
-onsl_seln_tr_pbmn_rate 자기 매도 거래대금 비율 String Y 1
-whol_onsl_shnu_vol 전체 자기 매수2 거래량 String Y 1
-onsl_shnu_vol_rate 자기 매수 거래량 비율 String Y 1
-whol_onsl_shnu_tr_pbmn 전체 자기 매수2 거래 대금 String Y 1
-onsl_shnu_tr_pbmn_rate 자기 매수 거래대금 비율 String Y 1
-whol_onsl_ntby_qty 전체 자기 순매수 수량 String Y 1
-onsl_ntby_qty_rate 자기 순매수량 비율 String Y 1
-whol_onsl_ntby_tr_pbmn 전체 자기 순매수 거래 대금 String Y 1
-onsl_ntby_tr_pbmn_rate 자기 순매수 대금 비율 String Y 1
-total_seln_qty 총 매도 수량 String Y 1
-whol_seln_vol_rate 전체 매도 거래량 비율 String Y 1
-total_seln_tr_pbmn 총 매도 거래 대금 String Y 1
-whol_seln_tr_pbmn_rate 전체 매도 거래대금 비율 String Y 1
-shnu_cntg_smtn 총 매수 수량 String Y 1
-whol_shun_vol_rate 전체 매수 거래량 비율 String Y 1
-total_shnu_tr_pbmn 총 매수2 거래 대금 String Y 1
-whol_shun_tr_pbmn_rate 전체 매수 거래대금 비율 String Y 1
-whol_ntby_qty 전체 순매수 수량 String Y 1
-whol_smtm_ntby_qty_rate 전체 합계 순매수 수량 비율 String Y 1
-whol_ntby_tr_pbmn 전체 순매수 거래 대금 String Y 1
-whol_ntby_tr_pbmn_rate 전체 순매수 거래대금 비율 String Y 1
-arbt_entm_ntby_qty 차익 위탁 순매수 수량 String Y 1
-arbt_entm_ntby_tr_pbmn 차익 위탁 순매수 거래 대금 String Y 1
-arbt_onsl_ntby_qty 차익 자기 순매수 수량 String Y 1
-arbt_onsl_ntby_tr_pbmn 차익 자기 순매수 거래 대금 String Y 1
-nabt_entm_ntby_qty 비차익 위탁 순매수 수량 String Y 1
-nabt_entm_ntby_tr_pbmn 비차익 위탁 순매수 거래 대금 String Y 1
-nabt_onsl_ntby_qty 비차익 자기 순매수 수량 String Y 1
-nabt_onsl_ntby_tr_pbmn 비차익 자기 순매수 거래 대금 String Y 1
-acml_vol 누적 거래량 String Y 1
-acml_tr_pbmn 누적 거래 대금 String Y 1

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0UPPGM0",
            "tr_key": "0001"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0UPPGM0", 
        "tr_key": "0001", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0UPPGM0|001|0001^085913^0^0^0^0^0^0^1^0^0^0^0^0^1^0^10^0^0^0.00^0^0.00^0^
0.00^0^0.00^0^0.00^0^0.00^0^0.00^1^0.00^1^0.00^10^0.00^1^0.00^9^0.00^0^0.00^1^0.00^1^0.00^10^0
.00^1^0.00^9^0.00^0^0.00^0^0.00^0^0.00^0^0.00^0^0.00^0^0.00^0^0.00^1^0.00^1^0.00^10^0.00^1^0.0
0^9^0.00^0^0^0^0^1^9^0^0^0^0

국내주식 실시간회원사 [실시간-047]

WEBSOCKET

국내주식 실시간회원사 [실시간-047]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    모의투자 미지원
  • URL
    /tryitout/H0STMBC0
  • Format
     
  • Content-Type
     

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0STMBC0
tr_key 종목코드 String Y 6 종목코드

Response

Body

Element 한글명 Type Required Length Description
mksc_shrn_iscd 유가증권단축종목코드 Object Y 9 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-seln2_mbcr_name1 매도2회원사명1 String Y 16
-seln2_mbcr_name2 매도2회원사명2 String Y 16
-seln2_mbcr_name3 매도2회원사명3 String Y 16
-seln2_mbcr_name4 매도2회원사명4 String Y 16
-seln2_mbcr_name5 매도2회원사명5 String Y 16
-byov_mbcr_name1 매수회원사명1 String Y 16
-byov_mbcr_name2 매수회원사명2 String Y 16
-byov_mbcr_name3 매수회원사명3 String Y 16
-byov_mbcr_name4 매수회원사명4 String Y 16
-byov_mbcr_name5 매수회원사명5 String Y 16
-total_seln_qty1 총매도수량1 String Y 8
-total_seln_qty2 총매도수량2 String Y 8
-total_seln_qty3 총매도수량3 String Y 8
-total_seln_qty4 총매도수량4 String Y 8
-total_seln_qty5 총매도수량5 String Y 8
-total_shnu_qty1 총매수2수량1 String Y 8
-total_shnu_qty2 총매수2수량2 String Y 8
-total_shnu_qty3 총매수2수량3 String Y 8
-total_shnu_qty4 총매수2수량4 String Y 8
-total_shnu_qty5 총매수2수량5 String Y 8
-seln_mbcr_glob_yn_1 매도거래원구분1 String Y 1
-seln_mbcr_glob_yn_2 매도거래원구분2 String Y 1
-seln_mbcr_glob_yn_3 매도거래원구분3 String Y 1
-seln_mbcr_glob_yn_4 매도거래원구분4 String Y 1
-seln_mbcr_glob_yn_5 매도거래원구분5 String Y 1
-shnu_mbcr_glob_yn_1 매수거래원구분1 String Y 1
-shnu_mbcr_glob_yn_2 매수거래원구분2 String Y 1
-shnu_mbcr_glob_yn_3 매수거래원구분3 String Y 1
-shnu_mbcr_glob_yn_4 매수거래원구분4 String Y 1
-shnu_mbcr_glob_yn_5 매수거래원구분5 String Y 1
-seln_mbcr_no1 매도거래원코드1 String Y 5
-seln_mbcr_no2 매도거래원코드2 String Y 5
-seln_mbcr_no3 매도거래원코드3 String Y 5
-seln_mbcr_no4 매도거래원코드4 String Y 5
-seln_mbcr_no5 매도거래원코드5 String Y 5
-shnu_mbcr_no1 매수거래원코드1 String Y 5
-shnu_mbcr_no2 매수거래원코드2 String Y 5
-shnu_mbcr_no3 매수거래원코드3 String Y 5
-shnu_mbcr_no4 매수거래원코드4 String Y 5
-shnu_mbcr_no5 매수거래원코드5 String Y 5
-seln_mbcr_rlim1 매도회원사비중1 String Y 8
-seln_mbcr_rlim2 매도회원사비중2 String Y 8
-seln_mbcr_rlim3 매도회원사비중3 String Y 8
-seln_mbcr_rlim4 매도회원사비중4 String Y 8
-seln_mbcr_rlim5 매도회원사비중5 String Y 8
-shnu_mbcr_rlim1 매수2회원사비중1 String Y 8
-shnu_mbcr_rlim2 매수2회원사비중2 String Y 8
-shnu_mbcr_rlim3 매수2회원사비중3 String Y 8
-shnu_mbcr_rlim4 매수2회원사비중4 String Y 8
-shnu_mbcr_rlim5 매수2회원사비중5 String Y 8
-seln_qty_icdc1 매도수량증감1 String Y 4
-seln_qty_icdc2 매도수량증감2 String Y 4
-seln_qty_icdc3 매도수량증감3 String Y 4
-seln_qty_icdc4 매도수량증감4 String Y 4
-seln_qty_icdc5 매도수량증감5 String Y 4
-shnu_qty_icdc1 매수2수량증감1 String Y 4
-shnu_qty_icdc2 매수2수량증감2 String Y 4
-shnu_qty_icdc3 매수2수량증감3 String Y 4
-shnu_qty_icdc4 매수2수량증감4 String Y 4
-shnu_qty_icdc5 매수2수량증감5 String Y 4
-glob_total_seln_qty 외국계총매도수량 String Y 8
-glob_total_shnu_qty 외국계총매수2수량 String Y 8
-glob_total_seln_qty_icdc 외국계총매도수량증감 String Y 4
-glob_total_shnu_qty_icdc 외국계총매수2수량증감 String Y 4
-glob_ntby_qty 외국계순매수수량 String Y 8
-glob_seln_rlim 외국계매도비중 String Y 8
-glob_shnu_rlim 외국계매수2비중 String Y 8
-seln2_mbcr_eng_name1 매도2영문회원사명1 String Y 20
-seln2_mbcr_eng_name2 매도2영문회원사명2 String Y 20
-seln2_mbcr_eng_name3 매도2영문회원사명3 String Y 20
-seln2_mbcr_eng_name4 매도2영문회원사명4 String Y 20
-seln2_mbcr_eng_name5 매도2영문회원사명5 String Y 20
-byov_mbcr_eng_name1 매수영문회원사명1 String Y 20
-byov_mbcr_eng_name2 매수영문회원사명2 String Y 20
-byov_mbcr_eng_name3 매수영문회원사명3 String Y 20
-byov_mbcr_eng_name4 매수영문회원사명4 String Y 20
-byov_mbcr_eng_name5 매수영문회원사명5 String Y 20

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0STMBC0",
            "tr_key": "005930"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0STMBC0", 
        "tr_key": "005930", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0STMBC0|001|005930^씨티그룹^미래에셋증권^모간서울^BNK증권^키움증권^미래
에셋증권^BNK증권^맥쿼리^NH투자증권^한국증권^903482^703873^484082^471203^246578^946273^571760^
343109^313536^311982^Y^N^Y^N^N^N^N^Y^N^N^00037^00005^00036^00086^00050^00005^00086^00035^0001
2^00003^19.06^14.85^10.21^9.94^5.20^19.96^12.06^7.24^6.61^6.58^14913^5054^7240^80000^3532^280
24^42986^0^5612^3043^1387564^681749^22153^0^-705815^29.27^14.38^^^^^^^^^^

국내주식 실시간프로그램매매 [실시간-048]

WEBSOCKET

국내주식 실시간프로그램매매 [실시간-048]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    모의투자 미지원
  • URL
    /tryitout/H0STPGM0
  • Format
     
  • Content-Type
     

개요

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0STPGM0
tr_key 종목코드 String Y 6 종목코드

Response

Body

Element 한글명 Type Required Length Description
mksc_shrn_iscd 유가증권단축종목코드 Object Y 9 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-stck_cntg_hour 주식체결시간 String Y 6
-seln_cnqn 매도체결량 String Y 1
-seln_tr_pbmn 매도거래대금 String Y 1
-shnu_cnqn 매수2체결량 String Y 1
-shnu_tr_pbmn 매수2거래대금 String Y 1
-ntby_cnqn 순매수체결량 String Y 1
-ntby_tr_pbmn 순매수거래대금 String Y 1
-seln_rsqn 매도호가잔량 String Y 1
-shnu_rsqn 매수호가잔량 String Y 1
-whol_ntby_qty 전체순매수호가잔량 String Y 1

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0STPGM0",
            "tr_key": "005930"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0STPGM0", 
        "tr_key": "005930", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0STPGM0|001|005930^092237^1413444^109159646900^1189408^91931710200^-2240
36^-17227936700^65033^15475^-49558

국내주식 장운영정보 [실시간-049]

WEBSOCKET

국내주식 장운영정보 [실시간-049]

기본정보

  • Method
    POST
  • 실전 Domain
    ws://ops.koreainvestment.com:21000
  • 모의 Domain
    모의투자 미지원
  • URL
    /tryitout/H0STMKO0
  • Format
     
  • Content-Type
     

개요

국내주식 장운영정보 연결 시, 연결종목의 VI 발동 시와 VI 해제 시에 데이터 수신됩니다.

[참고자료]
실시간시세(웹소켓) 파이썬 샘플코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/blob/main/websocket/python/ws_domestic_overseas_all.py

실시간시세(웹소켓) API 사용방법에 대한 자세한 설명은 한국투자증권 Wikidocs 참고 부탁드립니다.
https://wikidocs.net/book/7847 (국내주식 업데이트 완료, 추후 해외주식·국내선물옵션 업데이트 예정)

종목코드 마스터파일 파이썬 정제코드는 한국투자증권 Github 참고 부탁드립니다.
https://github.com/koreainvestment/open-trading-api/tree/main/stocks_info

[호출 데이터]
헤더와 바디 값을 합쳐 JSON 형태로 전송합니다.

[응답 데이터]
1. 정상 등록 여부 (JSON)
- JSON["body"]["msg1"] - 정상 응답 시, SUBSCRIBE SUCCESS
- JSON["body"]["output"]["iv"] - 실시간 결과 복호화에 필요한 AES256 IV (Initialize Vector)
- JSON["body"]["output"]["key"] - 실시간 결과 복호화에 필요한 AES256 Key

2. 실시간 결과 응답 ( | 로 구분되는 값)
ex) 0|H0STCNT0|004|005930^123929^73100^5^...
- 암호화 유무 : 0 암호화 되지 않은 데이터 / 1 암호화된 데이터
- TR_ID : 등록한 tr_id (ex. H0STCNT0)
- 데이터 건수 : (ex. 001 인 경우 데이터 건수 1건, 004인 경우 데이터 건수 4건)
- 응답 데이터 : 아래 response 데이터 참조 ( ^로 구분됨)

LAYOUT

Request

Header

Element 한글명 Type Required Length Description
approval_key 웹소켓 접속키 String Y 36 실시간 (웹소켓) 접속키 발급 API(/oauth2/Approval)를 사용하여 발급받은 웹소켓 접속키
custtype 고객 타입 String Y 1 B : 법인 / P : 개인
tr_type 등록/해제 String Y 1 "1: 등록, 2:해제"
content-type 컨텐츠타입 String Y 20 utf-8

Body

Element 한글명 Type Required Length Description
tr_id 거래ID String Y 7 H0STMKO0
tr_key 종목코드 String Y 6 종목코드

Response

Body

Element 한글명 Type Required Length Description
mksc_shrn_iscd 유가증권단축종목코드 Object Y 9 '각 항목사이에는 구분자로 ^ 사용,
모든 데이터타입은 String으로 변환되어 push 처리됨'
-trht_yn 거래정지여부 String Y 1
-tr_susp_reas_cntt 거래정지사유내용 String Y 100
-mkop_cls_code 장운영구분코드 String Y 3
-antc_mkop_cls_code 예상장운영구분코드 String Y 3
-mrkt_trtm_cls_code 임의연장구분코드 String Y 1
-divi_app_cls_code 동시호가배분처리구분코드 String Y 2
-iscd_stat_cls_code 종목상태구분코드 String Y 2
-vi_cls_code VI적용구분코드 String Y 1
-ovtm_vi_cls_code 시간외단일가VI적용구분코드 String Y 1

Example

Request

{
    "header": {
        "approval_key": "35xxxxxa-bxxa-4xxb-87xxx-f56xxxxxxxxxx",
        "custtype": "P",
        "tr_type": "1",
        "content-type": "utf-8"
    },
    "body": {
        "input": {
            "tr_id": "H0STMKO0",
            "tr_key": "396300"
        }
    }
}

Response

# 연결 확인
{
    "header": {
        "tr_id": "H0STMKO0", 
        "tr_key": "396300", 
        "encrypt": "N"
        }, 
    "body": {
        "rt_cd": "0", 
        "msg_cd": "OPSP0000",
        "msg1": "SUBSCRIBE SUCCESS", 
        "output": {
            "iv": "0123456789abcdef", 
            "key": "abcdefghijklmnopabcdefghijklmnop"}
        }
}

# output
0|H0STMKO0|001|396300^N^(null)^^311^^^55^N^N