68 lines
2.6 KiB
Swift
68 lines
2.6 KiB
Swift
//
|
|
// KissConsole+Price.swift
|
|
// KissMeConsole
|
|
//
|
|
// Created by ened-book-m1 on 2023/06/11.
|
|
//
|
|
|
|
import Foundation
|
|
import KissMe
|
|
|
|
|
|
struct PriceTime {
|
|
}
|
|
|
|
|
|
|
|
extension KissConsole {
|
|
|
|
func getCurrentPrice(productNo: String, printConsole: Bool = false) async -> Bool {
|
|
do {
|
|
let result = try await account!.getCurrentPrice(productNo: productNo)
|
|
guard let output = result.output else {
|
|
print("Invalid result's output for \(productNo)")
|
|
return false
|
|
}
|
|
|
|
if printConsole {
|
|
printCurrentPrice(output)
|
|
}
|
|
|
|
let price = CapturePrice(captureTime: Date(), price: output)
|
|
|
|
let fileUrl = KissConsole.productPriceUrl(productNo: productNo)
|
|
try [price].writeCsv(toFile: fileUrl, appendable: true, localized: localized)
|
|
|
|
try await Task.sleep(nanoseconds: 1_000_000_000 / PreferredCandleTPS)
|
|
} catch {
|
|
print(error)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
private func printCurrentPrice(_ output: CurrentPriceResult.OutputDetail) {
|
|
let productName = getProduct(shortCode: output.shortProductCode)?.itemName ?? ""
|
|
print("\t종목명: ", productName)
|
|
print("\t업종명: ", output.koreanMarketName, output.koreanBusinessTypeName ?? "")
|
|
print("\t주식 현재가: ", output.currentStockPrice)
|
|
print("\t전일 대비: ", output.previousDayVariableRatio)
|
|
print("\t누적 거래 대금: ", output.accumulatedTradingAmount)
|
|
print("\t누적 거래량: ", output.accumulatedVolume)
|
|
print("\t전일 대비 거래량 비율: ", output.previousDayDiffVolumeRatio)
|
|
print("\t주식 시가: ", output.stockOpenningPrice)
|
|
print("\t주식 최고가: ", output.highestStockPrice)
|
|
print("\t주식 최저가: ", output.lowestStockPrice)
|
|
print("\t외국인 순매수 수량: ", output.foreignNetBuyingQuantity)
|
|
print("\t외국인 보유 수량: ", output.foreignHoldQuantity)
|
|
print("\t최종 공매도 체결 수량: ", output.lastShortSellingConclusionQuantity)
|
|
print("\t프로그램매매 순매수 수량: ", output.programTradeNetBuyingQuantity)
|
|
print("\t자본금: ", output.capital)
|
|
print("\t상장 주수: ", output.listedStockCount)
|
|
print("\tHTS 시가총액: ", output.htsTotalMarketValue)
|
|
print("\tPER: ", output.per)
|
|
print("\tPBR: ", output.pbr)
|
|
print("\t주식 단축 종목코드", output.shortProductCode)
|
|
}
|
|
}
|