기본 정보
Method운영 도메인모의투자 도메인URLFormatContent-Type
다른 TR 확인하기
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
| etfobjt_idex_cd |
ETF대상지수코드 |
String |
Y |
3 |
|
| dt |
기간 |
String |
Y |
1 |
0:1주, 1:1달, 2:6개월, 3:1년 |
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| etfprft_rt_lst |
ETF수익율 |
LIST |
N |
|
|
| - etfprft_rt |
ETF수익률 |
String |
N |
20 |
|
| - cntr_prft_rt |
체결수익률 |
String |
N |
20 |
|
| - for_netprps_qty |
외인순매수수량 |
String |
N |
20 |
|
| - orgn_netprps_qty |
기관순매수수량 |
String |
N |
20 |
|
import requests
import json
# ETF수익율요청
def fn_ka40001(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40001', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
'etfobjt_idex_cd': '207', # ETF대상지수코드
'dt': '3', # 기간 0:1주, 1:1달, 2:6개월, 3:1년
}
# 3. API 실행
fn_ka40001(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40001(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
- ETF종목정보요청ka40002
-
요청
Header
-
| Element |
한글명 |
type |
|
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
Element한글명typeRequiredLengthDescription
| Element |
한글명 |
type |
|
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
-
| Element |
한글명 |
type |
|
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
-
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_nm |
종목명 |
String |
N |
20 |
|
| etfobjt_idex_nm |
ETF대상지수명 |
String |
N |
20 |
|
| wonju_pric |
원주가격 |
String |
N |
20 |
|
| etftxon_type |
ETF과세유형 |
String |
N |
20 |
|
| etntxon_type |
ETN과세유형 |
String |
N |
20 |
|
import requests
import json
# ETF종목정보요청
def fn_ka40002(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40002', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40002(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40002(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
- ETF일별추이요청ka40003
-
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
-
| Element |
한글명 |
type |
Required |
|
Description |
| etfdaly_trnsn |
ETF일별추이 |
LIST |
N |
|
|
| - cntr_dt |
체결일자 |
String |
N |
20 |
|
| - cur_prc |
현재가 |
String |
N |
20 |
|
| - pre_sig |
대비기호 |
String |
N |
20 |
|
| - pred_pre |
전일대비 |
String |
N |
20 |
|
| - pre_rt |
대비율 |
String |
N |
20 |
|
| - trde_qty |
거래량 |
String |
N |
20 |
|
| - nav |
NAV |
String |
N |
20 |
|
| - acc_trde_prica |
누적거래대금 |
String |
N |
20 |
|
| - navidex_dispty_rt |
NAV/지수괴리율 |
String |
N |
20 |
|
| - navetfdispty_rt |
NAV/ETF괴리율 |
String |
N |
20 |
|
| - trace_eor_rt |
추적오차율 |
String |
N |
20 |
|
| - trace_cur_prc |
추적현재가 |
String |
N |
20 |
|
| - trace_pred_pre |
추적전일대비 |
String |
N |
20 |
|
| - trace_pre_sig |
추적대비기호 |
String |
N |
20 |
|
- import requests
import json
# ETF일별추이요청
def fn_ka40003(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40003', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40003(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40003(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| txon_type |
과세유형 |
String |
Y |
1 |
0:전체, 1:비과세, 2:보유기간과세, 3:회사형, 4:외국, 5:비과세해외(보유기간관세) |
| navpre |
NAV대비 |
String |
Y |
1 |
0:전체, 1:NAV > 전일종가, 2:NAV < 전일종가 |
| mngmcomp |
운용사 |
String |
Y |
4 |
0000:전체, 3020:KODEX(삼성), 3027:KOSEF(키움), 3191:TIGER(미래에셋), 3228:KINDEX(한국투자), 3023:KStar(KB), 3022:아리랑(한화), 9999:기타운용사 |
| txon_yn |
과세여부 |
String |
Y |
1 |
0:전체, 1:과세, 2:비과세 |
| trace_idex |
추적지수 |
String |
Y |
1 |
0:전체 |
| stex_tp |
거래소구분 |
String |
Y |
1 |
1:KRX, 2:NXT, 3:통합 |
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| etfall_mrpr |
ETF전체시세 |
LIST |
N |
|
|
| - stk_cd |
종목코드 |
String |
N |
20 |
|
| - stk_cls |
종목분류 |
String |
N |
20 |
|
| - stk_nm |
종목명 |
String |
N |
20 |
|
| - close_pric |
종가 |
String |
N |
20 |
|
| - pre_sig |
대비기호 |
String |
N |
20 |
|
| - pred_pre |
전일대비 |
String |
N |
20 |
|
| - pre_rt |
대비율 |
String |
N |
20 |
|
| - trde_qty |
거래량 |
String |
N |
20 |
|
| - nav |
NAV |
String |
N |
20 |
|
| - trace_eor_rt |
추적오차율 |
String |
N |
20 |
|
| - txbs |
과표기준 |
String |
N |
20 |
|
| - dvid_bf_base |
배당전기준 |
String |
N |
20 |
|
| - pred_dvida |
전일배당금 |
String |
N |
20 |
|
| - trace_idex_nm |
추적지수명 |
String |
N |
20 |
|
| - drng |
배수 |
String |
N |
20 |
|
| - trace_idex_cd |
추적지수코드 |
String |
N |
20 |
|
| - trace_idex |
추적지수 |
String |
N |
20 |
|
| - trace_flu_rt |
추적등락율 |
String |
N |
20 |
|
import requests
import json
# ETF전체시세요청
def fn_ka40004(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40004', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'txon_type': '0', # 과세유형 0:전체, 1:비과세, 2:보유기간과세, 3:회사형, 4:외국, 5:비과세해외(보유기간관세)
'navpre': '0', # NAV대비 0:전체, 1:NAV > 전일종가, 2:NAV < 전일종가
'mngmcomp': '0000', # 운용사 0000:전체, 3020:KODEX(삼성), 3027:KOSEF(키움), 3191:TIGER(미래에셋), 3228:KINDEX(한국투자), 3023:KStar(KB), 3022:아리랑(한화), 9999:기타운용사
'txon_yn': '0', # 과세여부 0:전체, 1:과세, 2:비과세
'trace_idex': '0', # 추적지수 0:전체
'stex_tp': '1', # 거래소구분 1:KRX, 2:NXT, 3:통합
}
# 3. API 실행
fn_ka40004(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40004(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_nm |
종목명 |
String |
N |
20 |
|
| etfobjt_idex_nm |
ETF대상지수명 |
String |
N |
20 |
|
| wonju_pric |
원주가격 |
String |
N |
20 |
|
| etftxon_type |
ETF과세유형 |
String |
N |
20 |
|
| etntxon_type |
ETN과세유형 |
String |
N |
20 |
|
| etftisl_trnsn |
ETF시간대별추이 |
LIST |
N |
|
|
| - tm |
시간 |
String |
N |
20 |
|
| - close_pric |
종가 |
String |
N |
20 |
|
| - pre_sig |
대비기호 |
String |
N |
20 |
|
| - pred_pre |
전일대비 |
String |
N |
20 |
|
| - flu_rt |
등락율 |
String |
N |
20 |
|
| - trde_qty |
거래량 |
String |
N |
20 |
|
| - nav |
NAV |
String |
N |
20 |
|
| - trde_prica |
거래대금 |
String |
N |
20 |
|
| - navidex |
NAV지수 |
String |
N |
20 |
|
| - navetf |
NAVETF |
String |
N |
20 |
|
| - trace |
추적 |
String |
N |
20 |
|
| - trace_idex |
추적지수 |
String |
N |
20 |
|
| - trace_idex_pred_pre |
추적지수전일대비 |
String |
N |
20 |
|
| - trace_idex_pred_pre_sig |
추적지수전일대비기호 |
String |
N |
20 |
|
import requests
import json
# ETF시간대별추이요청
def fn_ka40006(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40006', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40006(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40006(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cls |
종목분류 |
String |
N |
20 |
|
| stk_nm |
종목명 |
String |
N |
20 |
|
| etfobjt_idex_nm |
ETF대상지수명 |
String |
N |
20 |
|
| etfobjt_idex_cd |
ETF대상지수코드 |
String |
N |
20 |
|
| objt_idex_pre_rt |
대상지수대비율 |
String |
N |
20 |
|
| wonju_pric |
원주가격 |
String |
N |
20 |
|
| etftisl_cntr_array |
ETF시간대별체결배열 |
LIST |
N |
|
|
| - cntr_tm |
체결시간 |
String |
N |
20 |
|
| - cur_prc |
현재가 |
String |
N |
20 |
|
| - pre_sig |
대비기호 |
String |
N |
20 |
|
| - pred_pre |
전일대비 |
String |
N |
20 |
|
| - trde_qty |
거래량 |
String |
N |
20 |
|
| - stex_tp |
거래소구분 |
String |
N |
20 |
KRX , NXT , 통합 |
import requests
import json
# ETF시간대별체결요청
def fn_ka40007(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40007', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40007(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40007(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
Element한글명typeRequiredLengthDescription
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| cntr_tm |
체결시간 |
String |
N |
20 |
|
| cur_prc |
현재가 |
String |
N |
20 |
|
| pre_sig |
대비기호 |
String |
N |
20 |
|
| pred_pre |
전일대비 |
String |
N |
20 |
|
| trde_qty |
거래량 |
String |
N |
20 |
|
| etfnetprps_qty_array |
ETF순매수수량배열 |
LIST |
N |
|
|
| - dt |
일자 |
String |
N |
20 |
|
| - cur_prc_n |
현재가n |
String |
N |
20 |
|
| - pre_sig_n |
대비기호n |
String |
N |
20 |
|
| - pred_pre_n |
전일대비n |
String |
N |
20 |
|
| - acc_trde_qty |
누적거래량 |
String |
N |
20 |
|
| - for_netprps_qty |
외인순매수수량 |
String |
N |
20 |
|
| - orgn_netprps_qty |
기관순매수수량 |
String |
N |
20 |
|
import requests
import json
# ETF일자별체결요청
def fn_ka40008(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40008', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40008(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40008(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Required |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
| Element |
한글명 |
type |
Required |
Length |
Description |
| etfnavarray |
ETFNAV배열 |
LIST |
N |
|
|
| - nav |
NAV |
String |
N |
20 |
|
| - navpred_pre |
NAV전일대비 |
String |
N |
20 |
|
| - navflu_rt |
NAV등락율 |
String |
N |
20 |
|
| - trace_eor_rt |
추적오차율 |
String |
N |
20 |
|
| - dispty_rt |
괴리율 |
String |
N |
20 |
|
| - stkcnt |
주식수 |
String |
N |
20 |
|
| - base_pric |
기준가 |
String |
N |
20 |
|
| - for_rmnd_qty |
외인보유수량 |
String |
N |
20 |
|
| - repl_pric |
대용가 |
String |
N |
20 |
|
| - conv_pric |
환산가격 |
String |
N |
20 |
|
| - drstk |
DR/주 |
String |
N |
20 |
|
| - wonju_pric |
원주가격 |
String |
N |
20 |
|
import requests
import json
# ETF시간대별체결요청
def fn_ka40009(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40009', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40009(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40009(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')
-
- ETF시간대별추이요청ka40010
-
요청
Header
| Element |
한글명 |
type |
Required |
Length |
Description |
| authorization |
접근토큰 |
String |
Y |
1000 |
토큰 지정시 토큰타입("Bearer") 붙혀서 호출 예) Bearer Egicyx... |
| cont-yn |
연속조회여부 |
String |
N |
1 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 cont-yn값 세팅 |
| next-key |
연속조회키 |
String |
N |
50 |
응답 Header의 연속조회여부값이 Y일 경우 다음데이터 요청시 응답 Header의 next-key값 세팅 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
-
| Element |
한글명 |
type |
Required |
Length |
Description |
| stk_cd |
종목코드 |
String |
Y |
6 |
|
응답
Header
-
| Element |
한글명 |
type |
Required |
Length |
Description |
| cont-yn |
연속조회여부 |
String |
N |
1 |
다음 데이터가 있을시 Y값 전달 |
| next-key |
연속조회키 |
String |
N |
50 |
다음 데이터가 있을시 다음 키값 전달 |
| api-id |
TR명 |
String |
Y |
10 |
|
Body
-
| Element |
한글명 |
type |
Required |
Length |
Description |
| etftisl_trnsn |
ETF시간대별추이 |
LIST |
N |
|
|
| - cur_prc |
현재가 |
String |
N |
20 |
|
| - pre_sig |
대비기호 |
String |
N |
20 |
|
| - pred_pre |
전일대비 |
String |
N |
20 |
|
| - trde_qty |
거래량 |
String |
N |
20 |
|
| - for_netprps |
외인순매수 |
String |
N |
20 |
|
import requests
import json
# ETF시간대별추이요청
def fn_ka40010(token, data, cont_yn='N', next_key=''):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/api/dostk/etf'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
'authorization': f'Bearer {token}', # 접근토큰
'cont-yn': cont_yn, # 연속조회여부
'next-key': next_key, # 연속조회키
'api-id': 'ka40010', # TR명
}
# 3. http POST 요청
response = requests.post(url, headers=headers, json=data)
# 4. 응답 상태 코드와 데이터 출력
print('Code:', response.status_code)
print('Header:', json.dumps({key: response.headers.get(key) for key in ['next-key', 'cont-yn', 'api-id']}, indent=4, ensure_ascii=False))
print('Body:', json.dumps(response.json(), indent=4, ensure_ascii=False)) # JSON 응답을 파싱하여 출력
# 실행 구간
if __name__ == '__main__':
# 1. 토큰 설정
MY_ACCESS_TOKEN = '사용자 AccessToken'# 접근토큰
# 2. 요청 데이터
params = {
'stk_cd': '069500', # 종목코드
}
# 3. API 실행
fn_ka40010(token=MY_ACCESS_TOKEN, data=params)
# next-key, cont-yn 값이 있을 경우
# fn_ka40010(token=MY_ACCESS_TOKEN, data=params, cont_yn='Y', next_key='nextkey..')