103 lines
3.3 KiB
Swift
103 lines
3.3 KiB
Swift
//
|
|
// test.swift
|
|
// KissMeConsole
|
|
//
|
|
// Created by ened-book-m1 on 2023/05/16.
|
|
//
|
|
|
|
import Foundation
|
|
import KissMe
|
|
|
|
|
|
private func test_array_to_csv() {
|
|
|
|
}
|
|
|
|
|
|
private func test_login_get_volume_ranking() async {
|
|
let isMock = false
|
|
let credential: Credential
|
|
|
|
do {
|
|
/// isMock 이 true 이면, mock-server.json 에서 로딩하여 생성
|
|
/// isMock 이 false 이면, real-server.json 에서 로딩하여 생성
|
|
/// server.json 의 구조
|
|
/// {
|
|
/// "isMock": true,
|
|
/// "accountNo": "12345678-90"
|
|
/// "appKey": "xxxxxxxx",
|
|
/// "appSecret": "yyyyyyyyyyyyyyyyyy"
|
|
/// }
|
|
///
|
|
credential = try KissCredential(isMock: isMock)
|
|
} catch {
|
|
print("\(error)")
|
|
return
|
|
}
|
|
|
|
|
|
let account = KissAccount(credential: credential)
|
|
do {
|
|
if try await account.login() {
|
|
let option = RankingOption(divisionClass: .equity, belongClass: .averageVolume)
|
|
let result = try await account.getVolumeRanking(option: option)
|
|
print("\(result)")
|
|
}
|
|
} catch {
|
|
print("\(error)")
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
private func test_json_result() {
|
|
let str = "{\"rt_cd\":\"1\",\"msg_cd\":\"EGW00205\",\"msg1\":\"credentials_type이 유효하지 않습니다.(Bearer)\"}"
|
|
|
|
do {
|
|
let decoder = JSONDecoder()
|
|
decoder.keyDecodingStrategy = .useDefaultKeys
|
|
|
|
let data = Data(str.utf8)
|
|
let result = try decoder.decode(VolumeRankResult.self, from: data)
|
|
print("\(result)")
|
|
}
|
|
catch {
|
|
print("\(error)")
|
|
}
|
|
}
|
|
|
|
|
|
private func test_xml_result() {
|
|
/*
|
|
let str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><response><header><resultCode>00</resultCode><resultMsg>NORMAL SERVICE.</resultMsg></header><body><items><item><korSecnNm>이스트아시아홀딩스인베스트먼트리미티드</korSecnNm><shotnIsin>900110</shotnIsin></item><item><korSecnNm>삼천당제약</korSecnNm><shotnIsin>000250</shotnIsin></item><item><korSecnNm>중앙에너비스</korSecnNm><shotnIsin>000440</shotnIsin></item><item><korSecnNm>신라섬유</korSecnNm><shotnIsin>001000</shotnIsin></item><item><korSecnNm>안국약품</korSecnNm><shotnIsin>001540</shotnIsin></item><item><korSecnNm>무림에스피</korSecnNm><shotnIsin>001810</shotnIsin></item><item><korSecnNm>이화공영</korSecnNm><shotnIsin>001840</shotnIsin></item><item><korSecnNm>피에스텍</korSecnNm><shotnIsin>002230</shotnIsin></item><item><korSecnNm>삼일기업공사</korSecnNm><shotnIsin>002290</shotnIsin></item><item><korSecnNm>한일사료</korSecnNm><shotnIsin>005860</shotnIsin></item></items><numOfRows>10</numOfRows><pageNo>1</pageNo><totalCount>1637</totalCount></body></response>"
|
|
|
|
let data = Data(str.utf8)
|
|
|
|
class ResultHelper: NSObject, XMLParserDelegate {
|
|
|
|
struct Result: Codable {
|
|
|
|
}
|
|
|
|
var result: Result?
|
|
|
|
func parserDidStartDocument(_ parser: XMLParser) {
|
|
}
|
|
|
|
func parserDidEndDocument(_ parser: XMLParser) {
|
|
}
|
|
}
|
|
|
|
|
|
do {
|
|
let helper = ResultHelper()
|
|
let parser = XMLParser(data: data)
|
|
parser.shouldProcessNamespaces = true
|
|
parser.delegate = helper
|
|
if parser.parse() {
|
|
print(helper.result)
|
|
}
|
|
}
|
|
*/
|
|
}
|