Working on DART api

This commit is contained in:
2023-07-09 13:37:17 +09:00
parent 824733ba45
commit 6c69e81154
8 changed files with 704 additions and 26 deletions

View File

@@ -0,0 +1,70 @@
//
// DomesticDart.swift
// KissMe
//
// Created by ened-book-m1 on 2023/07/09.
//
import Foundation
protocol DartRequest: Request {
var openApiKey: String { get }
}
extension DartRequest {
public var domain: String {
"https://opendart.fss.or.kr"
}
}
public struct DomesticDart {
public enum PublicNoticeType: String, Codable {
///
case regular = "A"
///
case mainPoint = "B"
///
case issue = "C"
///
case share = "D"
///
case etc = "E"
///
case externalAudit = "F"
///
case fund = "G"
///
case assetSecuritization = "H"
///
case exchange = "I"
///
case fairTradeCommission = "J"
}
public enum MarketType: String, Codable {
///
case stock = "Y"
///
case kosdaq = "K"
///
case konex = "N"
///
case etc = "E"
}
public enum ReportCode: String, Codable {
/// 1
case firstQuarter = "11013"
///
case half = "11012"
/// 3
case thridQuater = "11014"
///
case annual = "11011"
}
}

View File

@@ -0,0 +1,272 @@
//
// DomesticDartBusinessReport.swift
// KissMe
//
// Created by ened-book-m1 on 2023/07/09.
//
import Foundation
extension DomesticDart {
/// -
///
public struct ConditionalCapitalSecuritiesOutstandingBalanceRequest: DartRequest {
public typealias KResult = ConditionalCapitalSecuritiesOutstandingBalanceResult
public var url: String {
"/api/cndlCaplScritsNrdmpBlce.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"corp_code": corporationCode,
"bsns_year": businessYear,
"reprt_code": reportCode.rawValue,
]
}
public var result: KResult? = nil
public let openApiKey: String
let corporationCode: String
let businessYear: String
let reportCode: ReportCode
public init(openApiKey: String, corporationCode: String, businessYear: String, reportCode: ReportCode) {
self.openApiKey = openApiKey
self.corporationCode = corporationCode
self.businessYear = businessYear
self.reportCode = reportCode
}
}
/// -
///
public struct UnregisteredExecutivePayRequest: DartRequest {
public typealias KResult = UnregisteredExecutivePayResult
public var url: String {
"/api/unrstExctvMendngSttus.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"corp_code": corporationCode,
"bsns_year": businessYear,
"reprt_code": reportCode.rawValue,
]
}
public var result: KResult? = nil
public let openApiKey: String
let corporationCode: String
let businessYear: String
let reportCode: ReportCode
public init(openApiKey: String, corporationCode: String, businessYear: String, reportCode: ReportCode) {
self.openApiKey = openApiKey
self.corporationCode = corporationCode
self.businessYear = businessYear
self.reportCode = reportCode
}
}
/// -
///
public struct CorporateBondOutstandingBalanceRequest: DartRequest {
public typealias KResult = CorporateBondOutstandingBalanceResult
public var url: String {
"/api/cprndNrdmpBlce.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"corp_code": corporationCode,
"bsns_year": businessYear,
"reprt_code": reportCode.rawValue,
]
}
public var result: KResult? = nil
public let openApiKey: String
let corporationCode: String
let businessYear: String
let reportCode: ReportCode
public init(openApiKey: String, corporationCode: String, businessYear: String, reportCode: ReportCode) {
self.openApiKey = openApiKey
self.corporationCode = corporationCode
self.businessYear = businessYear
self.reportCode = reportCode
}
}
}
extension DomesticDart {
public struct ConditionalCapitalSecuritiesOutstandingBalanceResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
public let list: [Item]
private enum CodingKeys: String, CodingKey {
case status
case message
case list
}
}
public struct Item: Codable {
///
public let receiptNo: String
///
public let marketType: MarketType
///
public let corporationCode: String
///
public let corporationName: String
///
public let remainingExpiration1: String
///
public let remainingExpiration2: String
/// 1
public let year1Below: String
/// 1 2
public let year1Excess_year2Below: String
/// 2 3
public let year2Excess_year3Blow: String
/// 3 4
public let year3Excess_year4Below: String
/// 4 5
public let year4Excess_year5Below: String
/// 5 10
public let year5Excess_year10Below: String
/// 10 20
public let year10Excess_year20Below: String
/// 20 30
public let year20Excess_year30Below: String
/// 30
public let year30Excess: String
///
public let sum: String
private enum CodingKeys: String, CodingKey {
case receiptNo = "rcept_no"
case marketType = "corp_cls"
case corporationCode = "corp_code"
case corporationName = "corp_name"
case remainingExpiration1 = "remndr_exprtn1"
case remainingExpiration2 = "remndr_exprtn2"
case year1Below = "yy1_below"
case year1Excess_year2Below = "yy1_excess_yy2_below"
case year2Excess_year3Blow = "yy2_excess_yy3_below"
case year3Excess_year4Below = "yy3_excess_yy4_below"
case year4Excess_year5Below = "yy4_excess_yy5_below"
case year5Excess_year10Below = "yy5_excess_yy10_below"
case year10Excess_year20Below = "yy10_excess_yy20_below"
case year20Excess_year30Below = "yy20_excess_yy30_below"
case year30Excess = "yy30_excess"
case sum = "sm"
}
}
}
public struct UnregisteredExecutivePayResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
public let list: [Item]
private enum CodingKeys: String, CodingKey {
case status
case message
case list
}
}
public struct Item: Codable {
///
public let receiptNo: String
///
public let marketType: MarketType
///
public let corporationCode: String
///
public let corporationName: String
///
public let seperation: String
///
public let headcount: String
///
public let annualTotalSalaryAmount: String
/// 1
public let averageSalaryAmount: String
///
public let remark: String
private enum CodingKeys: String, CodingKey {
case receiptNo = "rcept_no"
case marketType = "corp_cls"
case corporationCode = "corp_code"
case corporationName = "corp_name"
case seperation = "se"
case headcount = "nmpr"
case annualTotalSalaryAmount = "fyer_salary_totamt"
case averageSalaryAmount = "jan_salary_am"
case remark = "rm"
}
}
}
public struct CorporateBondOutstandingBalanceResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
public let list: [Item]
private enum CodingKeys: String, CodingKey {
case status
case message
case list
}
}
public struct Item: Codable {
private enum CodingKeys: String, CodingKey {
}
}
}
}

View File

@@ -0,0 +1,317 @@
//
// DomesticDartNotice.swift
// KissMe
//
// Created by ened-book-m1 on 2023/07/09.
//
import Foundation
extension DomesticDart {
/// -
///
public struct NoticeListRequest: DartRequest {
public typealias KResult = NoticeListResult
public var url: String {
"/api/list.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"corp_code": corporationCode,
"bgn_de": startDate.yyyyMMdd,
"end_de": endDate.yyyyMMdd,
//"last_reprt_at": "N",
//"pblntf_ty": noticeType.rawValue,
//"pblntf_detail_ty": "",
//"corp_cls": marketType.rawValue,
//"sort": "date",
//"sort_mth": "desc",
"page_no": pageNo,
"page_count": pageCount,
]
}
public var result: KResult? = nil
public let openApiKey: String
let corporationCode: String
let startDate: Date
let endDate: Date
//let noticeType: PublicNoticeType
//let marketType: MarketType
let pageNo: Int
let pageCount: Int
public init(openApiKey: String, corporationCode: String, startDate: Date, endDate: Date, pageNo: Int, pageCount: Int) {
self.openApiKey = openApiKey
self.corporationCode = corporationCode
self.startDate = startDate
self.endDate = endDate
self.pageNo = pageNo
self.pageCount = pageCount
}
}
/// -
///
public struct CompanyRequest: DartRequest {
public typealias KResult = CompanyResult
public var url: String {
"/api/company.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"corp_code": corporationCode,
]
}
public var result: KResult? = nil
public let openApiKey: String
let corporationCode: String
public init(openApiKey: String, corporationCode: String) {
self.openApiKey = openApiKey
self.corporationCode = corporationCode
}
}
/// -
///
public struct DocumentRequest: DartRequest {
public typealias KResult = Data
public var url: String {
"/api/document.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
"rcept_no": receiptNo,
]
}
public var result: KResult? = nil
public let openApiKey: String
let receiptNo: String
public init(openApiKey: String, receiptNo: String) {
self.openApiKey = openApiKey
self.receiptNo = receiptNo
}
}
/// -
///
public struct CorporationCodesRequest: DartRequest {
public typealias KResult = CorporationCodesResult
public var url: String {
"/api/document.json"
}
public var method: Method { .get }
public var header: [String : String?] {
[:]
}
public var body: [String: Any] {
return [
"crtfc_key": openApiKey,
]
}
public var result: KResult? = nil
public let openApiKey: String
public init(openApiKey: String) {
self.openApiKey = openApiKey
}
}
}
extension DomesticDart {
public struct NoticeListResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
public let pageNo: Int
public let pageCount: Int
public let totalCount: Int
public let totalPage: Int
public let list: [Item]
private enum CodingKeys: String, CodingKey {
case status
case message
case pageNo = "page_no"
case pageCount = "page_count"
case totalCount = "total_count"
case totalPage = "total_page"
case list
}
}
public struct Item: Codable {
///
public let marketType: MarketType
/// ()
public let corporationName: String
///
public let corporationCode: String
///
public let productNo: String
///
public let reportName: String
///
public let receiptNo: String
///
public let submissionName: String
///
public let receiptDate: String
///
public let remark: String
private enum CodingKeys: String, CodingKey {
case marketType = "corp_cls"
case corporationName = "corp_name"
case corporationCode = "corp_code"
case productNo = "stock_code"
case reportName = "report_nm"
case receiptNo = "rcept_no"
case submissionName = "flr_nm"
case receiptDate = "rcept_dt"
case remark = "rm"
}
}
}
public struct CompanyResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
///
public let corporationName: String
///
public let englishCorporationName: String
/// () ()
public let stockName: String
///
public let productCode: String
///
public let ceoName: String
///
public let marketType: MarketType
///
public let corporationNo: String
///
public let businessNo: String
///
public let address: String
///
public let homepage: String
/// IR
public let ir: String
///
public let phoneNumber: String
///
public let faxNumber: String
///
public let industryCode: String
/// (YYYYMMDD)
public let establishedDate: String
/// (MM)
public let accountMonth: String
private enum CodingKeys: String, CodingKey {
case status
case message
case corporationName = "corp_name"
case englishCorporationName = "corp_name_eng"
case stockName = "stock_name"
case productCode = "stock_code"
case ceoName = "ceo_nm"
case marketType = "corp_cls"
case corporationNo = "jurir_no"
case businessNo = "bizr_no"
case address = "adres"
case homepage = "hm_url"
case ir = "ir_url"
case phoneNumber = "phn_no"
case faxNumber = "fax_no"
case industryCode = "induty_code"
case establishedDate = "est_dt"
case accountMonth = "acc_mt"
}
}
}
public struct CorporationCodesResult: Codable {
public let result: Result
public struct Result: Codable {
public let status: String
public let message: String
public let list: [Item]
private enum CodingKeys: String, CodingKey {
case status
case message
case list
}
}
public struct Item: Codable {
///
public let corporationCode: String
///
public let corporationName: String
///
public let productCode: String
///
public let modifyDate: String
private enum CodingKeys: String, CodingKey {
case corporationCode = "corp_code"
case corporationName = "corp_name"
case productCode = "stock_code"
case modifyDate = "modify_date"
}
}
}
}

View File

@@ -0,0 +1,24 @@
//
// DomesticExtra.swift
// KissMe
//
// Created by ened-book-m1 on 2023/07/09.
//
import Foundation
public struct DomesticExtra {
public typealias Shorts = ShortSellingBalanceResult.OutBlock
public typealias IndexProduct = AllIndicesResult.Block
}
protocol KrxRequest: Request {
}
extension KrxRequest {
public var domain: String {
"http://data.krx.co.kr"
}
}

View File

@@ -44,9 +44,6 @@ extension DomesticExtra {
public struct IndexPriceRequest: KrxRequest {
public typealias KResult = IndexPriceResult
public var domain: String {
"http://data.krx.co.kr"
}
public var url: String {
"/comm/bldAttendant/getJsonData.cmd"
}
@@ -86,9 +83,6 @@ extension DomesticExtra {
public struct IndexPortfolioRequest: KrxRequest {
public typealias KResult = IndexPortfolioResult
public var domain: String {
"http://data.krx.co.kr"
}
public var url: String {
"/comm/bldAttendant/getJsonData.cmd"
}
@@ -129,9 +123,6 @@ extension DomesticExtra {
public struct AllIndicesRequest: KrxRequest {
public typealias KResult = AllIndicesResult
public var domain: String {
"http://data.krx.co.kr"
}
public var url: String {
"/comm/bldAttendant/getJsonData.cmd"
}

View File

@@ -8,15 +8,6 @@
import Foundation
public struct DomesticExtra {
public typealias Shorts = ShortSellingBalanceResult.OutBlock
public typealias IndexProduct = AllIndicesResult.Block
}
protocol KrxRequest: Request {
}
extension DomesticExtra {
/// - -
@@ -24,9 +15,6 @@ extension DomesticExtra {
public struct ShortSellingBalanceRequest: KrxRequest {
public typealias KResult = ShortSellingBalanceResult
public var domain: String {
"http://data.krx.co.kr"
}
public var url: String {
"/comm/bldAttendant/getJsonData.cmd"
}

View File

@@ -39,6 +39,10 @@
341F5F142A16CD7A00962D48 /* DomesticShopProduct.swift in Sources */ = {isa = PBXBuildFile; fileRef = 341F5F132A16CD7A00962D48 /* DomesticShopProduct.swift */; };
3435A7F72A35D82000D604F1 /* DomesticShortSelling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3435A7F62A35D82000D604F1 /* DomesticShortSelling.swift */; };
349C26AB2A1EAE2400F3EC91 /* KissProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 349C26AA2A1EAE2400F3EC91 /* KissProfile.swift */; };
34C1BA4D2A59CD3400423D64 /* DomesticDartNotice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1BA4C2A59CD3400423D64 /* DomesticDartNotice.swift */; };
34C1BA4F2A5A603F00423D64 /* DomesticExtra.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1BA4E2A5A603F00423D64 /* DomesticExtra.swift */; };
34C1BA512A5A607D00423D64 /* DomesticDart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1BA502A5A607D00423D64 /* DomesticDart.swift */; };
34C1BA532A5A683D00423D64 /* DomesticDartBusinessReport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34C1BA522A5A683D00423D64 /* DomesticDartBusinessReport.swift */; };
34D3680F2A2AA0BE005E6756 /* PropertyIterable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34D3680E2A2AA0BE005E6756 /* PropertyIterable.swift */; };
34E7B9112A49BD2800B3AB9F /* DomesticIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34E7B9102A49BD2800B3AB9F /* DomesticIndex.swift */; };
34F1900C2A41982A0068C697 /* KissIndexResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34F1900B2A41982A0068C697 /* KissIndexResult.swift */; };
@@ -90,6 +94,10 @@
341F5F132A16CD7A00962D48 /* DomesticShopProduct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticShopProduct.swift; sourceTree = "<group>"; };
3435A7F62A35D82000D604F1 /* DomesticShortSelling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticShortSelling.swift; sourceTree = "<group>"; };
349C26AA2A1EAE2400F3EC91 /* KissProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KissProfile.swift; sourceTree = "<group>"; };
34C1BA4C2A59CD3400423D64 /* DomesticDartNotice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticDartNotice.swift; sourceTree = "<group>"; };
34C1BA4E2A5A603F00423D64 /* DomesticExtra.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticExtra.swift; sourceTree = "<group>"; };
34C1BA502A5A607D00423D64 /* DomesticDart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticDart.swift; sourceTree = "<group>"; };
34C1BA522A5A683D00423D64 /* DomesticDartBusinessReport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticDartBusinessReport.swift; sourceTree = "<group>"; };
34D3680E2A2AA0BE005E6756 /* PropertyIterable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyIterable.swift; sourceTree = "<group>"; };
34E7B9102A49BD2800B3AB9F /* DomesticIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomesticIndex.swift; sourceTree = "<group>"; };
34F1900B2A41982A0068C697 /* KissIndexResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KissIndexResult.swift; sourceTree = "<group>"; };
@@ -174,8 +182,8 @@
341F5EE62A0F3EFB00962D48 /* Domestic */ = {
isa = PBXGroup;
children = (
34C1BA4B2A595A5F00423D64 /* DART */,
34E7B90F2A4994AF00B3AB9F /* KRX300 */,
3435A7F52A35D68000D604F1 /* ShortSelling */,
341F5F122A16CD3C00962D48 /* Shop */,
341F5EE42A0F3EF400962D48 /* DomesticStock.swift */,
341F5EF62A0F8B0500962D48 /* DomesticStockResult.swift */,
@@ -223,18 +231,22 @@
path = Shop;
sourceTree = "<group>";
};
3435A7F52A35D68000D604F1 /* ShortSelling */ = {
34C1BA4B2A595A5F00423D64 /* DART */ = {
isa = PBXGroup;
children = (
3435A7F62A35D82000D604F1 /* DomesticShortSelling.swift */,
34C1BA502A5A607D00423D64 /* DomesticDart.swift */,
34C1BA4C2A59CD3400423D64 /* DomesticDartNotice.swift */,
34C1BA522A5A683D00423D64 /* DomesticDartBusinessReport.swift */,
);
path = ShortSelling;
path = DART;
sourceTree = "<group>";
};
34E7B90F2A4994AF00B3AB9F /* KRX300 */ = {
isa = PBXGroup;
children = (
34C1BA4E2A5A603F00423D64 /* DomesticExtra.swift */,
34E7B9102A49BD2800B3AB9F /* DomesticIndex.swift */,
3435A7F62A35D82000D604F1 /* DomesticShortSelling.swift */,
);
path = KRX300;
sourceTree = "<group>";
@@ -369,7 +381,10 @@
files = (
341F5EFB2A10909D00962D48 /* LoginResult.swift in Sources */,
340A4DC42A4E4345005A1FBA /* ArrayDecodable.swift in Sources */,
34C1BA532A5A683D00423D64 /* DomesticDartBusinessReport.swift in Sources */,
34C1BA4F2A5A603F00423D64 /* DomesticExtra.swift in Sources */,
340A4DC82A4E43C5005A1FBA /* GeneralError.swift in Sources */,
34C1BA512A5A607D00423D64 /* DomesticDart.swift in Sources */,
340A4DCE2A4EA5D8005A1FBA /* Runner.swift in Sources */,
341F5F0B2A15115400962D48 /* KissShop.swift in Sources */,
3435A7F72A35D82000D604F1 /* DomesticShortSelling.swift in Sources */,
@@ -393,6 +408,7 @@
341F5F012A11155100962D48 /* DomesticStockSearchResult.swift in Sources */,
341F5F142A16CD7A00962D48 /* DomesticShopProduct.swift in Sources */,
341F5EF22A0F887200962D48 /* DomesticFutures.swift in Sources */,
34C1BA4D2A59CD3400423D64 /* DomesticDartNotice.swift in Sources */,
34D3680F2A2AA0BE005E6756 /* PropertyIterable.swift in Sources */,
341F5F112A1685E700962D48 /* ShopRequest.swift in Sources */,
341F5EF92A0F907300962D48 /* DomesticStockPriceResult.swift in Sources */,