Files
KissMe/KissMeConsole/Sources/test.swift

103 lines
3.3 KiB
Swift
Raw Normal View History

//
// test.swift
// KissMeConsole
//
// Created by ened-book-m1 on 2023/05/16.
//
import Foundation
import KissMe
2023-05-21 13:51:31 +09:00
func test_array_to_csv() {
}
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
}
}
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)")
}
}
2023-05-19 01:17:09 +09:00
func test_xml_result() {
2023-05-28 16:08:49 +09:00
/*
2023-05-19 01:17:09 +09:00
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)
}
}
2023-05-28 16:08:49 +09:00
*/
2023-05-19 01:17:09 +09:00
}