Skip to content

Commit 24ef1b0

Browse files
修复了当 cachePath 不以 "/" 结尾时文件夹创建上的 Bug
修改了示例项目默认 cachePath
1 parent 3b413a2 commit 24ef1b0

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.gradle
33
build
44
plugins
5+
data
56
CtpAccounts.kt

examples/library-basic/app/src/main/kotlin/com/example/basic/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fun main() {
2525
"brokerId" to "1234", // BROKER ID
2626
"appId" to "rf_ktrader_1.0.0", // APPID
2727
"authCode" to "ASDFGHJKL", // 授权码
28-
"cachePath" to "./build/flow/", // 本地缓存文件存储目录
28+
"cachePath" to "./data/ctp", // 本地缓存文件存储目录
2929
"disableAutoSubscribe" to false, // 是否禁用自动订阅
3030
"disableFeeCalculation" to false, // 是否禁用费用计算
3131
)

examples/plugin-basic/app/src/main/kotlin/com/example/basic/App.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fun main() {
4040
"brokerId" to "1234", // BROKER ID
4141
"appId" to "rf_ktrader_1.0.0", // APPID
4242
"authCode" to "ASDFGHJKL", // 授权码
43-
"cachePath" to "./build/flow/", // 本地缓存文件存储目录
43+
"cachePath" to "./data/ctp", // 本地缓存文件存储目录
4444
"disableAutoSubscribe" to false, // 是否禁用自动订阅
4545
"disableFeeCalculation" to false, // 是否禁用费用计算
4646
)

lib/src/main/kotlin/org/rationalityfrontline/ktrader/broker/ctp/CtpMdApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ internal class CtpMdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
6363
val lastTicks = mutableMapOf<String, Tick>()
6464

6565
init {
66-
val mdCachePath = "${config.cachePath.ifBlank { "./ctp_cache/" }}${config.investorId.ifBlank { "unknown" }}/md/"
66+
val cachePath = config.cachePath.ifBlank { ".data/ctp/" }
67+
val mdCachePath = "${if (cachePath.endsWith('/')) cachePath else "$cachePath/"}${config.investorId.ifBlank { "unknown" }}/md/"
6768
File(mdCachePath).mkdirs()
6869
mdApi = CThostFtdcMdApi.CreateFtdcMdApi(mdCachePath)
6970
mdSpi = CtpMdSpi()

lib/src/main/kotlin/org/rationalityfrontline/ktrader/broker/ctp/CtpTdApi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ internal class CtpTdApi(val config: CtpConfig, val kEvent: KEvent, val sourceId:
147147
private val cancelStatistics: MutableMap<String, Int> = mutableMapOf()
148148

149149
init {
150-
val tdCachePath = "${config.cachePath.ifBlank { "./ctp_cache/" }}${config.investorId.ifBlank { "unknown" }}/td/"
150+
val cachePath = config.cachePath.ifBlank { ".data/ctp/" }
151+
val tdCachePath = "${if (cachePath.endsWith('/')) cachePath else "$cachePath/"}${config.investorId.ifBlank { "unknown" }}/td/"
151152
File(tdCachePath).mkdirs()
152153
cacheFile = File("${tdCachePath}cache.txt")
153154
tdApi = CThostFtdcTraderApi.CreateFtdcTraderApi(tdCachePath)

0 commit comments

Comments
 (0)