Programming/MFC-C++

네이버 주식 시세 조회

빠릿베짱이 2015. 7. 13. 14:05
반응형


http://m.stock.naver.com/api/json/search/searchListJson.nhn?keyword=%EC%97%A0%EC%94%A8


{

"result": {

            "d":[

                   {"cd":"097520","nm":"엠씨넥스","mt":"1","nv":33600,"cv":-1750,"cr":-4.95,"rf":"5","pcv":35350,

                    "mks":3023,"aq":129409,"aa":4527989}

                ],

            "t":"search",

            "totCnt":1

          },

"resultCode":"success"

}


http://api.finance.naver.com/service/itemSummary.nhn?itemcode=097520

itemcode = > 종목 코드

리턴값

{

"marketSum":221817, -> 시가 총액  2218억 17백만

"risefall":2,    -> 1 : 상한 , 2 : 상승, 3: 보합? , 4 : 하한, 5, 하락

"diff":3200,    -> 전일대비 가격 차이

"rate":9.51,  -> 상승율

"high":38900, ->고가

"low":34150, ->저가

"quant":329660, -> 거래량

"amount":12156468, -> 거래대금

"per":24.31, -> PER

"eps":1516.0, -> EPS

"pbr":4.25, -> PBR

"now":36850  -> 현재가

}


var doUpdateInformation = function() {
	var sApiUrl = "http://api.finance.naver.com/service/itemSummary.nhn?itemcode=097520"

	oUpdateAjax = jindo.$Ajax(sApiUrl, {
		type : 'jsonp',
		jsonp_charset : "utf-8",
		onload : function(response) {
			if(response != null && response.readyState() == 4) {
				var json = response.json();
				
				if (json.now == undefined) {
					startInformationTimer();
					return;
				}
				
				var sMarketSum = (json.marketSum + "");
				sMarketSum = sMarketSum.substring(0, sMarketSum.length - 2);
				sMarketSum = changeNumberFormat(sMarketSum);

				var sPer = changeNumberFormat(json.per);
				var sEps = changeNumberFormat(json.eps);
				var sPbr = changeNumberFormat(json.pbr);
				var sNowVal = changeNumberFormat(json.now);
				var sDiff = changeNumberFormat(json.diff);
				var sRate = changeNumberFormat(json.rate) + "%";
				var sQuant = changeNumberFormat(json.quant);
				var sAmount = changeNumberFormat(json.amount);
				var sHigh = changeNumberFormat(json.high);
				var sLow = changeNumberFormat(json.low);

				if (sRate == "0%") {
					sRate = "0.00%";
				}

				if (json.per == undefined) {
					sPer = "N/A";
				}
				
				if (json.eps == undefined) {
					sEps = "N/A";
				}
				
				if (json.pbr == undefined) {
					sPbr = "N/A";
				}
				
				jindo.$A(jindo.$$("#_market_sum")).forEach(function(v) {
					jindo.$Element(v).text(sMarketSum);
				}, this);

				jindo.$A(jindo.$$("#_per")).forEach(function(v) {
					jindo.$Element(v).text(sPer);
				}, this);

				jindo.$A(jindo.$$("#_eps")).forEach(function(v) {
					jindo.$Element(v).text(sEps);
				}, this);

				jindo.$A(jindo.$$("#_sise_market_sum")).forEach(function(v) {
					jindo.$Element(v).text(sMarketSum);
				}, this);

				jindo.$A(jindo.$$("#_sise_per")).forEach(function(v) {
					jindo.$Element(v).text(sPer);
				}, this);

				jindo.$A(jindo.$$("#_sise_eps")).forEach(function(v) {
					jindo.$Element(v).text(sEps);
				}, this);

				jindo.$A(jindo.$$("#_pbr")).forEach(function(v) {
					jindo.$Element(v).text(sPbr);
				}, this);

				jindo.$A(jindo.$$("#_nowVal")).forEach(function(v) {
					jindo.$Element(v).text(sNowVal);
				}, this);

				jindo.$A(jindo.$$("#_diff")).forEach(function(v) {
					var sFormat = null;
					var sDiffToDisplay = sDiff.replace("-", "");

					if (json.risefall == 1) {
						sFormat = "<em class=\"bu_p bu_pup2\" style=\"margin:0 4px 0 0\"><span class=\"blind\">상한</span></em><span class=\"tah p11 red01\">%s</span>";
					} else if (json.risefall == 2) {
						sFormat = "<em class=\"bu_p bu_pup\" style=\"margin:0 4px 0 0\"><span class=\"blind\">상승</span></em><span class=\"tah p11 red01\">%s</span>";
					} else if (json.risefall == 3) {
						sFormat = "<span class=\"tah p11\">%s</span>";
					} else if (json.risefall == 4) {
						sFormat = "<em class=\"bu_p bu_pdn2\" style=\"margin:0 4px 0 0\"><span class=\"blind\">하한</span></em><span class=\"tah p11 nv01\">%s</span>";
					} else {
						sFormat = "<em class=\"bu_p bu_pdn\" style=\"margin:0 4px 0 0\"><span class=\"blind\">하락</span></em><span class=\"tah p11 nv01\">%s</span>";
					}

					var sHtml = jindo.$S(sFormat).format(sDiffToDisplay);

					jindo.$Element(v).html(sHtml);
				}, this);

				jindo.$A(jindo.$$("#_rate")).forEach(function(v) {
					var sCss = "red01";
					var sRateToDisplay = sRate;

					if (sRate.indexOf("-") > -1) {
						sCss = "nv01";
					} else if (sRate.indexOf("0.00") > -1) {
						sCss = "";
					} else {
						sRateToDisplay = "+" + sRateToDisplay;
					}

					var sHtml = "<span class=\"tah p11 " + sCss + "\">" + sRateToDisplay + "</span>";
					jindo.$Element(v).html(sHtml);
				}, this);

				jindo.$A(jindo.$$("#_quant")).forEach(function(v) {
					jindo.$Element(v).text(sQuant);
				}, this);

				jindo.$A(jindo.$$("#_amount")).forEach(function(v) {
					jindo.$Element(v).text(sAmount);
				}, this);

				jindo.$A(jindo.$$("#_high")).forEach(function(v) {
					jindo.$Element(v).text(sHigh);
				}, this);

				jindo.$A(jindo.$$("#_low")).forEach(function(v) {
					jindo.$Element(v).text(sLow);
				}, this);

				startInformationTimer();
			}
		},
		timeout : 2,
		ontimeout : function() {
			startInformationTimer();
		},
		async : true
	});
	oUpdateAjax.request();
}


반응형