Skip to content

CrackerCat/tushare-kmp

 
 

Repository files navigation

🚧 项目开发中 - 此项目正在积极开发中,API 可能会发生变化

TuShare API Kotlin 客户端

License Maven Central

用于 TuShare 金融数据 API 的 Kotlin 客户端,支持Kotlin MultiplatformKotlin Coroutines

📦 安装配置

1. 添加依赖

在你的 build.gradle 文件中添加以下依赖:

repositories {
    mavenCentral()
}

dependencies {
    implementation "li.mercury.tushare:tushare-kmp:latest-version"
}

2. 选择Ktor Engine

选择并添加一个 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

在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

你可以在 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"
    )
)

🎯 支持的功能

沪深股票

指数行情

快讯公告

📚 使用指南

详细的使用指南和示例请查看:

🌍 多平台支持

该库支持以下平台:

  • JVM
  • Android
  • iOS
  • macOS
  • watchOS
  • tvOS
  • Linux
  • Windows
  • JavaScript
  • WebAssembly

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
    )
)

⭐️ 支持

欣赏这个项目?以下是你可以帮助的方式:

  1. Star: 在右上角给它一个星标,这对我们很重要!
  2. 贡献: 发现问题或有功能想法?提交 PR 吧。
  3. 反馈: 有建议?开个 issue

📄 许可证

TuShare Kotlin API 客户端是在 GNU Lesser General Public License v2.1 下开源的软件。

这是一个非官方库,它与 TuShare 官方无关联也未得到其认可。欢迎贡献。


关于 TuShare

TuShare 是一个提供中国金融市场数据的开放平台,包括股票、期货、基金、宏观经济等各类金融数据。该项目是 TuShare API 的非官方 Kotlin 客户端实现。

About

A multiplatform client for TuShare

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%