Check market time
This commit is contained in:
@@ -72,6 +72,14 @@ extension Domestic.Candle: @retroactive Equatable {
|
||||
return Data(value: UInt32(date.timeIntervalSince2020))
|
||||
}
|
||||
|
||||
var isValidInMarketTime: Bool {
|
||||
guard let (hh, mm, ss) = stockConclusionTime.HHmmss else {
|
||||
return false
|
||||
}
|
||||
let timeInSeconds = (hh * 3600 + mm * 60 + ss)
|
||||
return 9 * 3600 <= timeInSeconds && timeInSeconds <= 16 * 3600
|
||||
}
|
||||
|
||||
public static func == (lhs: Domestic.Candle, rhs: Domestic.Candle) -> Bool {
|
||||
return
|
||||
lhs.stockBusinessDate == rhs.stockBusinessDate &&
|
||||
@@ -271,7 +279,10 @@ extension KissConsole {
|
||||
return candleFiles
|
||||
}
|
||||
|
||||
func buildCandleMinuteDB(productNo: String, csvFiles: [URL], removeOldDB: Bool = false) -> Bool {
|
||||
/// - Parameters:
|
||||
/// remoeOldDB: 이미 생성된 DB 파일이 있으면 삭제함.
|
||||
/// trimAfterMarket: 거래시간 09:00 ~ 16:00 을 벗어난 경우, DB 에 기록하지 않음.
|
||||
func buildCandleMinuteDB(productNo: String, csvFiles: [URL], removeOldDB: Bool = false, trimAfterMarket: Bool = true) -> Bool {
|
||||
for csvFile in csvFiles {
|
||||
let candleMinName = CandleMinuteFileName()
|
||||
if let (_, yyyyMMdd) = candleMinName.matchedUrl(csvFile.path), let year = Int(yyyyMMdd.prefix(4)) {
|
||||
@@ -288,6 +299,11 @@ extension KissConsole {
|
||||
try db.begin()
|
||||
|
||||
for candle in candles {
|
||||
if trimAfterMarket {
|
||||
guard candle.isValidInMarketTime else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
let candleData = try CandleData(candle: candle)
|
||||
let item = KissDB.DataItem(key: candleData.key, value: candleData.data)
|
||||
try db.insertData(item: item)
|
||||
@@ -313,7 +329,9 @@ extension KissConsole {
|
||||
return yearDbPath
|
||||
}
|
||||
|
||||
func validateCandleMinuteDB(productNo: String, year: String) -> Bool {
|
||||
/// - Parameters:
|
||||
/// trimAfterMarket: 거래시간 09:00 ~ 16:00 을 벗어난 경우, DB 의 검사에서 제외함.
|
||||
func validateCandleMinuteDB(productNo: String, year: String, trimAfterMarket: Bool = true) -> Bool {
|
||||
let yearDbPath = candleMinuteDBPath(productNo: productNo, year: year)
|
||||
guard let (_, yearCsvFiles) = collectCandleMinuteFiles(productNo: productNo, year: year, month: nil, day: nil).first else {
|
||||
print("No csv files of productNo: \(productNo), year: \(year)")
|
||||
@@ -330,6 +348,11 @@ extension KissConsole {
|
||||
for csvFile in yearCsvFiles {
|
||||
let candles = try [Domestic.Candle].readCsv(fromFile: csvFile)
|
||||
for candle in candles {
|
||||
if trimAfterMarket {
|
||||
guard candle.isValidInMarketTime else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
guard let keyOfCandleData = candle.keyOfCandleData else {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -45,7 +45,20 @@ struct DB1_CandleData_Tests: KissTestCase {
|
||||
assertEqual(yyyyMMdd, "20230705")
|
||||
}
|
||||
|
||||
let test_4_BuildSamsungDB = {
|
||||
let test_4_MarketTime = {
|
||||
do {
|
||||
let c1 = try Domestic.Candle(array: ["20230614", "090000", "31826451600", "72000", "72100", "72200", "72000", "441290"], source: "")
|
||||
let c2 = try Domestic.Candle(array: ["20230614", "115900", "535421242800", "71400", "71500", "71500", "71400", "4345"], source: "")
|
||||
let c3 = try Domestic.Candle(array: ["20230614", "164000", "891989441300", "71900", "71900", "71900", "71900", "0"], source: "")
|
||||
assertEqual(c1.isValidInMarketTime, true, message: "c1")
|
||||
assertEqual(c2.isValidInMarketTime, true, message: "c2")
|
||||
assertEqual(c3.isValidInMarketTime, false, message: "c3")
|
||||
} catch {
|
||||
print("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
let test_5_BuildSamsungDB = {
|
||||
let productNo = Self.samsungProductNo
|
||||
let year = Self.year
|
||||
let month = Self.month
|
||||
@@ -80,7 +93,7 @@ struct DB1_CandleData_Tests: KissTestCase {
|
||||
Self.insertCount = itemCount
|
||||
}
|
||||
|
||||
let test_5_CountSamsungDB: () -> Void = {
|
||||
let test_6_CountSamsungDB: () -> Void = {
|
||||
let productNo = Self.samsungProductNo
|
||||
let year = Self.year
|
||||
let yyyyMM = String(year) + Self.month
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
KissConsole().run()
|
||||
|
||||
#if false
|
||||
KissConsole().run()
|
||||
#else
|
||||
import KissMe
|
||||
|
||||
//test_get_websocket_key_and_contact_price()
|
||||
|
||||
Submodule libraries/KissMeme updated: db14c42c4d...feb81bf03a
Reference in New Issue
Block a user