52 lines
1.8 KiB
Swift
52 lines
1.8 KiB
Swift
//
|
|
// KissConsole+Investor.swift
|
|
// KissMeConsole
|
|
//
|
|
// Created by ened-book-m1 on 2023/06/11.
|
|
//
|
|
|
|
import Foundation
|
|
import KissMe
|
|
|
|
|
|
extension KissConsole {
|
|
func getInvestor(productNo: String) async throws -> Bool {
|
|
let result = try await account!.getInvestorVolume(productNo: productNo)
|
|
if let output = result.output {
|
|
print("Total output: \(output.count) productNo: \(productNo)")
|
|
|
|
var months = [String: [Domestic.Investor]]()
|
|
for item in output {
|
|
let yyyyMM = String(item.stockBusinessDate.prefix(6))
|
|
if let _ = months[yyyyMM] {
|
|
months[yyyyMM]!.append(item)
|
|
}
|
|
else {
|
|
months[yyyyMM] = [item]
|
|
}
|
|
}
|
|
|
|
for (month, items) in months {
|
|
let descItems = items.sorted(by: { $0.stockBusinessDate > $1.stockBusinessDate })
|
|
guard descItems.count > 0 else {
|
|
continue
|
|
}
|
|
|
|
let fileUrl = KissConsole.investorFileUrl(productNo: productNo, day: month+"01")
|
|
try descItems.mergeCsv(toFile: fileUrl, merging: { this, file in
|
|
var merged = this
|
|
for old in file {
|
|
if nil == this.first(where: { $0.stockBusinessDate == old.stockBusinessDate }) {
|
|
merged.append(old)
|
|
}
|
|
}
|
|
merged.sort(by: { $0.stockBusinessDate > $1.stockBusinessDate })
|
|
return merged
|
|
}, localized: localized)
|
|
}
|
|
}
|
|
try await Task.sleep(nanoseconds: 1_000_000_000 / PreferredInvestorTPS)
|
|
return true
|
|
}
|
|
}
|