
TuShare API client enables seamless interaction with financial data services, offering versatile configurations, multi-platform support, and coroutines for efficient data retrieval in investment analysis.
🚧 项目开发中 - 此项目正在积极开发中,API 可能会发生变化
用于 TuShare 金融数据 API 的 Kotlin 客户端,支持Kotlin Multiplatform和Kotlin Coroutines。
在你的 build.gradle 文件中添加以下依赖:
repositories {
mavenCentral()
}
dependencies {
implementation "li.mercury.tushare:tushare-kmp:latest-version"
}选择并添加一个 Ktor Engine 到你的依赖中:
dependencies {
// Android/JVM
implementation "io.ktor:ktor-client-okhttp:ktor-latest-version"
// iOS/Native
implementation "io.ktor:ktor-client-darwin:ktor-latest-version"
// JavaScript
implementation "io.ktor:ktor-client-js:ktor-latest-version"
}在Kotlin Multiplatform多平台项目中,你可以将 tushare 客户端依赖添加到 commonMain:
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("li.mercury.tushare:tushare-kmp:latest-version")
// 选择一个适合的 Ktor 引擎,这里以cio为例子
implementation("io.ktor:ktor-client-cio:ktor-latest-version")
}
}
}
}你可以在 Maven 项目中使用 JVM 客户端:
<dependencies>
<dependency>
<groupId>li.mercury.tushare</groupId>
<artifactId>tushare-kmp-jvm</artifactId>
<version>latest-version</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-okhttp-jvm</artifactId>
<version>ktor-latest-version</version>
<scope>runtime</scope>
</dependency>
</dependencies>[!NOTE] TuShare 建议使用环境变量存储 API token。 了解更多最佳实践。
创建 TuShare 客户端实例:
val tuShare = TuShare(
token = "your-tushare-token",
timeout = Timeout(socket = 60.seconds),
// 其他配置...
)或者使用预配置的 TuShareConfig:
val config = TuShareConfig(
token = apiToken,
timeout = Timeout(socket = 60.seconds),
// 其他配置...
)
val tuShare = TuShare(config)// 获取股票基本信息
val stockBasic = tuShare.stockBasic(
StockBasicParams(
isHs = "N",
listStatus = "L"
)
)
// 获取日线行情
val daily = tuShare.daily(
DailyParams(
tsCode = "000001.SZ",
startDate = "20240101",
endDate = "20241231"
)
)
// 获取指数行情
val indexDaily = tuShare.indexDaily(
IndexDailyParams(
tsCode = "000001.SH",
startDate = "20240101"
)
)详细的使用指南和示例请查看:
该库支持以下平台:
https://www.jetbrains.com/help/kotlin-multiplatform-dev/supported-platforms.html
val tuShare = TuShare(
token = "your-token",
host = TuShareHost.TuShare,
timeout = Timeout(
socket = 60.seconds,
connect = 30.seconds,
request = 120.seconds
),
loggingConfig = LoggingConfig(
level = LogLevel.INFO,
),
retry = RetryStrategy(
maxRetries = 3,
),
proxy = Socks(
host = "proxy.example.com",
port = 8080
)
)欣赏这个项目?以下是你可以帮助的方式:
TuShare Kotlin API 客户端是在 GNU Lesser General Public License v2.1 下开源的软件。
这是一个非官方库,它与 TuShare 官方无关联也未得到其认可。欢迎贡献。
TuShare 是一个提供中国金融市场数据的开放平台,包括股票、期货、基金、宏观经济等各类金融数据。该项目是 TuShare API 的非官方 Kotlin 客户端实现。
🚧 项目开发中 - 此项目正在积极开发中,API 可能会发生变化
用于 TuShare 金融数据 API 的 Kotlin 客户端,支持Kotlin Multiplatform和Kotlin Coroutines。
在你的 build.gradle 文件中添加以下依赖:
repositories {
mavenCentral()
}
dependencies {
implementation "li.mercury.tushare:tushare-kmp:latest-version"
}选择并添加一个 Ktor Engine 到你的依赖中:
dependencies {
// Android/JVM
implementation "io.ktor:ktor-client-okhttp:ktor-latest-version"
// iOS/Native
implementation "io.ktor:ktor-client-darwin:ktor-latest-version"
// JavaScript
implementation "io.ktor:ktor-client-js:ktor-latest-version"
}在Kotlin Multiplatform多平台项目中,你可以将 tushare 客户端依赖添加到 commonMain:
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("li.mercury.tushare:tushare-kmp:latest-version")
// 选择一个适合的 Ktor 引擎,这里以cio为例子
implementation("io.ktor:ktor-client-cio:ktor-latest-version")
}
}
}
}你可以在 Maven 项目中使用 JVM 客户端:
<dependencies>
<dependency>
<groupId>li.mercury.tushare</groupId>
<artifactId>tushare-kmp-jvm</artifactId>
<version>latest-version</version>
</dependency>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-client-okhttp-jvm</artifactId>
<version>ktor-latest-version</version>
<scope>runtime</scope>
</dependency>
</dependencies>[!NOTE] TuShare 建议使用环境变量存储 API token。 了解更多最佳实践。
创建 TuShare 客户端实例:
val tuShare = TuShare(
token = "your-tushare-token",
timeout = Timeout(socket = 60.seconds),
// 其他配置...
)或者使用预配置的 TuShareConfig:
val config = TuShareConfig(
token = apiToken,
timeout = Timeout(socket = 60.seconds),
// 其他配置...
)
val tuShare = TuShare(config)// 获取股票基本信息
val stockBasic = tuShare.stockBasic(
StockBasicParams(
isHs = "N",
listStatus = "L"
)
)
// 获取日线行情
val daily = tuShare.daily(
DailyParams(
tsCode = "000001.SZ",
startDate = "20240101",
endDate = "20241231"
)
)
// 获取指数行情
val indexDaily = tuShare.indexDaily(
IndexDailyParams(
tsCode = "000001.SH",
startDate = "20240101"
)
)详细的使用指南和示例请查看:
该库支持以下平台:
https://www.jetbrains.com/help/kotlin-multiplatform-dev/supported-platforms.html
val tuShare = TuShare(
token = "your-token",
host = TuShareHost.TuShare,
timeout = Timeout(
socket = 60.seconds,
connect = 30.seconds,
request = 120.seconds
),
loggingConfig = LoggingConfig(
level = LogLevel.INFO,
),
retry = RetryStrategy(
maxRetries = 3,
),
proxy = Socks(
host = "proxy.example.com",
port = 8080
)
)欣赏这个项目?以下是你可以帮助的方式:
TuShare Kotlin API 客户端是在 GNU Lesser General Public License v2.1 下开源的软件。
这是一个非官方库,它与 TuShare 官方无关联也未得到其认可。欢迎贡献。
TuShare 是一个提供中国金融市场数据的开放平台,包括股票、期货、基金、宏观经济等各类金融数据。该项目是 TuShare API 的非官方 Kotlin 客户端实现。