-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.py
More file actions
46 lines (34 loc) · 1.14 KB
/
test.py
File metadata and controls
46 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os
appkey = os.environ.get('kiwoom_appkey')
secretkey = os.environ.get('kiwoom_secretkey')
import requests
import json
# 접근토큰 발급
def fn_au10001(data):
# 1. 요청할 API URL
#host = 'https://mockapi.kiwoom.com' # 모의투자
host = 'https://api.kiwoom.com' # 실전투자
endpoint = '/oauth2/token'
url = host + endpoint
# 2. header 데이터
headers = {
'Content-Type': 'application/json;charset=UTF-8', # 컨텐츠타입
}
# 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. 요청 데이터
params = {
'grant_type': 'client_credentials', # grant_type
'appkey': appkey, # 앱키
'secretkey': secretkey, # 시크릿키
}
# 2. API 실행
fn_au10001(data=params)
print(appkey)
print(secretkey)