-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathindex.html
111 lines (102 loc) · 3.58 KB
/
index.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script>
Date.prototype.yyyymmdd = function()
{
var yyyy = this.getFullYear().toString();
var mm = (this.getMonth() + 1).toString();
var dd = this.getDate().toString();
return yyyy + (mm[1] ? mm : '0'+mm[0]) + (dd[1] ? dd : '0'+dd[0]);
}
</script>
</head>
<body>
<div>
<label>종목코드</label><input type="text" id="stockcode" value="003000" />
<button id="search">종목 검색</button>
<button id="chart">차트 데이터 검색</button>
</div>
<script>
var $code = $("#stockcode");
document.addEventListener("eventConnect.kiwoom", function(e) {
var errcode = e.detail;
if(errcode == 0) {
console.info("로그인 완료");
console.log(kiwoom.getLoginInfo("ACCNO").replace(/;$/,"").split(";"));
} else {
console.error(kiwoom.parseErrorCode(errcode));
}
});
document.addEventListener("receiveMsg.kiwoom", function(e) {
var data = e.detail;
console.info({
"scrNo" : data.scrNo,
"rQName" : data.rQName,
"trCode": data.trCode,
"msg" : data.msg
});
});
document.addEventListener("receiveTrData.kiwoom", function(e) {
var data = e.detail;
var len = kiwoom.getRepeatCnt(data.trCode, data.rQName);
console.info( data.rQName, data.trCode, len );
switch(data.trCode) {
case "opt10001" :
for(var i=0; i<len; i++) {
console.log("TR 데이터",{
"종목명" : kiwoom.commGetData(data.trCode, "", data.rQName, i, "종목명"),
"시가총액" : kiwoom.commGetData(data.trCode, "", data.rQName, i, "시가총액"),
"거래량" : kiwoom.commGetData(data.trCode, "", data.rQName, i, "거래량"),
"현재가" : kiwoom.commGetData(data.trCode, "", data.rQName, i, "현재가")
});
}
break;
case "opt10081" :
console.log("TR 데이터", JSON.parse(kiwoom.getCommDataEx(data.trCode, data.rQName)));
break;
}
});
document.addEventListener("receiveRealData.kiwoom", function(e) {
var data = e.detail;
console.info("실시간데이터", {
"jongmokCode" : data.jongmokCode,
"realType" : data.realType,
"realData": data.realData
});
console.log(kiwoom.commGetData(data.jongmokCode, data.realType, 10, 0, ""));
});
$("#search").click(function(e) {
var status = kiwoom.getConnectState();
if(status == 0) {
kiwoom.commConnect();
} else if(status == 1) {
search();
}
});
$("#chart").click(function(e) {
var status = kiwoom.getConnectState();
if(status == 0) {
kiwoom.commConnect();
} else if(status == 1) {
chart();
}
});
// 종목 TR 검색
function search() {
kiwoom.setInputValue("종목코드", $code.val());
// rQName과 화면번호는 사용자가 지정하여 구분하는 값
kiwoom.commRqData("주식기본정보", "opt10001", 0, "0001");
}
function chart() {
kiwoom.setInputValue("종목코드", $code.val());
kiwoom.setInputValue("기준일자", (new Date()).yyyymmdd());
kiwoom.setInputValue("수정주가구분 ", 0);
// rQName과 화면번호는 사용자가 지정하여 구분하는 값
kiwoom.commRqData("주식일봉차트조회요청", "opt10081", 0, "0002");
}
</script>
</body>
</html>