Skip to content

Commit

Permalink
๐Ÿ“œ v0.1.41: ํ•ด์™ธ ์ฃผ๋ฌธ ์ •์ •/์ทจ์†Œ, KDoc ์ถ”๊ฐ€, ๋ฒ„๊ทธ ์ˆ˜์ •
Browse files Browse the repository at this point in the history
- OrderOverseasAmend, OrderOverseasCancel ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
- StockDomestic, StockOverseas ํด๋ž˜์Šค์— amend, cancel ๋ฉ”์„œ๋“œ๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
- ์š”์ฒญ Response์— ํ•„๋“œ๋ฅผ ์„ค๋ช…ํ•˜๋Š” KDoc๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
- ๋น ์ ธ์žˆ๊ฑฐ๋‚˜ ์ž˜๋ชป๋œ SerialName์˜ ํ•„๋“œ๋ฅผ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • Loading branch information
devngho committed Nov 19, 2023
1 parent 3f52bf3 commit 534d426
Show file tree
Hide file tree
Showing 47 changed files with 1,084 additions and 169 deletions.
111 changes: 57 additions & 54 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
kotlin("multiplatform") version "1.9.0"
kotlin("plugin.serialization") version "1.9.0"
kotlin("multiplatform") version "1.9.20"
kotlin("plugin.serialization") version "1.9.20"
id("org.jetbrains.dokka") version "1.9.0"
id("io.kotest.multiplatform") version "5.7.2"
`maven-publish`
signing
}

group = "io.github.devngho"
version = "0.1.40"
version = "0.1.41"

repositories {
mavenCentral()
Expand Down Expand Up @@ -84,61 +84,53 @@ kotlin {
kotlinOptions.jvmTarget = "19"
}
}

val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")

when {
hostOs == "Mac OS X" -> macosX64("native")
hostOs == "Linux" -> linuxX64("native")
isMingwX64 -> mingwX64("native")
hostOs == "Mac OS X" -> macosX64()
hostOs == "Linux" -> linuxX64()
isMingwX64 -> mingwX64()
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
}


sourceSets {
val ktorVersion = "2.1.3"
val coroutineVersion = "1.7.3"
val kotestVersion = "5.7.2"

val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("com.soywiz.korlibs.krypto:krypto:4.0.0-alpha-1")

implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
implementation("com.ionspin.kotlin:bignum:0.3.7")
implementation("com.ionspin.kotlin:bignum-serialization-kotlinx:0.3.7")
}
commonMain.dependencies {
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("com.soywiz.korlibs.krypto:krypto:4.0.0-alpha-1")

implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-websockets:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
implementation("com.ionspin.kotlin:bignum:0.3.7")
implementation("com.ionspin.kotlin:bignum-serialization-kotlinx:0.3.7")
}
val commonTest by getting {
dependencies {
implementation("io.kotest:kotest-framework-engine:$kotestVersion")
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
commonTest.dependencies {
implementation("io.kotest:kotest-framework-engine:$kotestVersion")
implementation("io.kotest:kotest-assertions-core:$kotestVersion")
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
val jvmMain by getting {
dependencies {
implementation(kotlin("stdlib"))
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
jvmMain.dependencies {
implementation(kotlin("stdlib"))
implementation("io.ktor:ktor-client-cio:$ktorVersion")
}
val jvmTest by getting {
dependencies {
implementation(kotlin("reflect"))
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
}
jvmTest.dependencies {
implementation(kotlin("reflect"))
implementation("io.ktor:ktor-client-cio:$ktorVersion")
implementation("io.kotest:kotest-runner-junit5:$kotestVersion")
}
val nativeMain by getting {
dependencies {
implementation("io.ktor:ktor-client-curl:$ktorVersion")
}
nativeMain.dependencies {
implementation("io.ktor:ktor-client-curl:$ktorVersion")
}

applyDefaultHierarchyTemplate()
}
}

Expand All @@ -152,19 +144,30 @@ tasks {
"publishJvmPublicationToMavenLocal"
)
}
getByName("signNativePublication") {
if (version.toString().endsWith("SNAPSHOT")) dependsOn(
"publishJvmPublicationToSonatypeSnapshotRepositoryRepository",
"publishJvmPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToSonatypeSnapshotRepositoryRepository"
)
else dependsOn(
"publishJvmPublicationToSonatypeReleaseRepositoryRepository",
"publishJvmPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToSonatypeReleaseRepositoryRepository"
)

val hostOs = System.getProperty("os.name")
val isMingwX64 = hostOs.startsWith("Windows")
val nativeTargets = mutableListOf<String>()

if (hostOs == "MAac OS X") nativeTargets.add("MacOSX64")
if (hostOs == "Linux") nativeTargets.add("LinuxX64")
if (isMingwX64) nativeTargets.add("MingwX64")

nativeTargets.forEach { target ->
getByName("sign${target}Publication") {
if (version.toString().endsWith("SNAPSHOT")) dependsOn(
"publishJvmPublicationToSonatypeSnapshotRepositoryRepository",
"publishJvmPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToSonatypeSnapshotRepositoryRepository"
)
else dependsOn(
"publishJvmPublicationToSonatypeReleaseRepositoryRepository",
"publishJvmPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToMavenLocal",
"publishKotlinMultiplatformPublicationToSonatypeReleaseRepositoryRepository"
)
}
}
named<Test>("jvmTest") {
useJUnitPlatform()
Expand Down
16 changes: 16 additions & 0 deletions src/commonMain/kotlin/layer/IStockDomestic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package io.github.devngho.kisopenapi.layer
import com.ionspin.kotlin.bignum.integer.BigInteger
import io.github.devngho.kisopenapi.KisOpenApi
import io.github.devngho.kisopenapi.requests.InquireLivePrice
import io.github.devngho.kisopenapi.requests.OrderAmend
import io.github.devngho.kisopenapi.requests.OrderBuy
import io.github.devngho.kisopenapi.requests.OrderCancel
import io.github.devngho.kisopenapi.requests.response.StockPriceBase
import io.github.devngho.kisopenapi.requests.response.StockTrade
import io.github.devngho.kisopenapi.requests.util.Closeable
Expand All @@ -20,5 +22,19 @@ interface IStockDomestic : IStockBase{

suspend fun buy(count: BigInteger, type: OrderTypeCode, price: BigInteger = BigInteger(0)): OrderBuy.OrderResponse
suspend fun sell(count: BigInteger, type: OrderTypeCode, price: BigInteger = BigInteger(0)): OrderBuy.OrderResponse
suspend fun amend(
order: OrderBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
price: BigInteger = BigInteger(0),
orderAll: Boolean
): OrderAmend.OrderResponse

suspend fun cancel(
order: OrderBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
orderAll: Boolean
): OrderCancel.OrderResponse
suspend fun useLiveConfirmPrice(block: Closeable.(InquireLivePrice.InquireLivePriceResponse) -> Unit)
}
14 changes: 14 additions & 0 deletions src/commonMain/kotlin/layer/IStockOverseas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.ionspin.kotlin.bignum.decimal.BigDecimal
import com.ionspin.kotlin.bignum.integer.BigInteger
import io.github.devngho.kisopenapi.KisOpenApi
import io.github.devngho.kisopenapi.requests.InquireOverseasLivePrice
import io.github.devngho.kisopenapi.requests.OrderOverseasAmend
import io.github.devngho.kisopenapi.requests.OrderOverseasBuy
import io.github.devngho.kisopenapi.requests.OrderOverseasCancel
import io.github.devngho.kisopenapi.requests.response.StockOverseasPriceBase
import io.github.devngho.kisopenapi.requests.util.Closeable
import io.github.devngho.kisopenapi.requests.util.OrderTypeCode
Expand All @@ -21,5 +23,17 @@ interface IStockOverseas : IStockBase{

suspend fun buy(count: BigInteger, type: OrderTypeCode, price: BigDecimal = BigDecimal.fromInt(0)): OrderOverseasBuy.OrderResponse
suspend fun sell(count: BigInteger, type: OrderTypeCode, price: BigDecimal = BigDecimal.fromInt(0)): OrderOverseasBuy.OrderResponse
suspend fun amend(
order: OrderOverseasBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
price: BigDecimal = BigDecimal.fromInt(0)
): OrderOverseasAmend.OrderResponse

suspend fun cancel(
order: OrderOverseasBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode
): OrderOverseasCancel.OrderResponse
suspend fun useLiveConfirmPrice(block: Closeable.(InquireOverseasLivePrice.InquireLivePriceResponse) -> Unit)
}
37 changes: 37 additions & 0 deletions src/commonMain/kotlin/layer/StockDomestic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,43 @@ class StockDomestic(override val client: KisOpenApi, override val ticker: String
}
}

override suspend fun amend(
order: OrderBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
price: BigInteger,
orderAll: Boolean
): OrderAmend.OrderResponse {
if (client.account == null) throw RequestError("Amend request need account.")
else {
return OrderAmend(client).call(
OrderAmend.OrderData(
type, count, price,
order.output?.orderNumber ?: throw RequestError("Amend request need order number."), orderAll
)
)
}
}

override suspend fun cancel(
order: OrderBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
orderAll: Boolean
): OrderCancel.OrderResponse {
if (client.account == null) throw RequestError("Cancel request need account.")
else {
return OrderCancel(client).call(
OrderCancel.OrderData(
type,
count,
order.output?.orderNumber ?: throw RequestError("Cancel request need order number."),
orderAll
)
)
}
}

override suspend fun useLiveConfirmPrice(block: Closeable.(InquireLivePrice.InquireLivePriceResponse) -> Unit) {
runBlocking {
InquireLivePrice(client).apply {
Expand Down
38 changes: 38 additions & 0 deletions src/commonMain/kotlin/layer/StockOverseas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,44 @@ class StockOverseas(override val client: KisOpenApi, override val ticker: String
}
}

override suspend fun amend(
order: OrderOverseasBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode,
price: BigDecimal
): OrderOverseasAmend.OrderResponse {
if (client.account == null) throw RequestError("Amend request need account.")
else {
return OrderOverseasAmend(client).call(
OrderOverseasAmend.OrderData(
ticker,
market,
count,
price,
order.output?.orderNumber ?: throw RequestError("Amend request need order number.")
)
)
}
}

override suspend fun cancel(
order: OrderOverseasBuy.OrderResponse,
count: BigInteger,
type: OrderTypeCode
): OrderOverseasCancel.OrderResponse {
if (client.account == null) throw RequestError("Cancel request need account.")
else {
return OrderOverseasCancel(client).call(
OrderOverseasCancel.OrderData(
ticker,
market,
count,
order.output?.orderNumber ?: throw RequestError("Cancel request need order number.")
)
)
}
}

override suspend fun useLiveConfirmPrice(block: Closeable.(InquireOverseasLivePrice.InquireLivePriceResponse) -> Unit) {
runBlocking {
InquireOverseasLivePrice(client).apply {
Expand Down
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/requests/InquireBalance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class InquireBalance(override val client: KisOpenApi):
@SerialName("asst_icdc_erng_rt") @Contextual override val assetChangeRate: BigDecimal?,
@SerialName("rlzt_pfls") @Contextual override val realizedProfitLoss: BigInteger?,
@SerialName("rlzt_erng_rt") @Contextual override val realizedProfitLossRate: BigDecimal?,
@SerialName("rlzt_evlu_pfls") @Contextual override val realEvalProfitLoss: BigInteger?,
@SerialName("rlzt_evlu_pfls_erng_rt") @Contextual override val realEvalProfitLossRate: BigDecimal?,
@SerialName("real_evlu_pfls") @Contextual override val realEvalProfitLoss: BigInteger?,
@SerialName("real_evlu_pfls_erng_rt") @Contextual override val realEvalProfitLossRate: BigDecimal?,
): BalanceAccount {
@SerialName("error_description")
override val errorDescription: String? = null
Expand Down
6 changes: 3 additions & 3 deletions src/commonMain/kotlin/requests/InquireConfirm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class InquireConfirm(override val client: KisOpenApi):
): StockPriceBase, StockPriceChange

data class InquireConfirmData(
val stockCode: String,
override val ticker: String,
/** ๊ธฐ๋ณธ์ ์œผ๋กœ KisOpenApi corp ๊ฐ’์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค. */
override var corp: CorporationRequest? = null,
override var tradeContinuous: String? = ""
) : Data, TradeContinuousData
) : Data, TradeContinuousData, Ticker

@Suppress("SpellCheckingInspection")
override suspend fun call(data: InquireConfirmData): InquireConfirmResponse = client.rateLimiter.rated {
Expand All @@ -60,7 +60,7 @@ class InquireConfirm(override val client: KisOpenApi):
val res = client.httpClient.get(url) {
auth(client)
tradeId("FHKST01010300")
stock(data.stockCode)
stock(data.ticker)
data.corp?.let { corporation(it) }
}
res.body<InquireConfirmResponse>().apply {
Expand Down
8 changes: 3 additions & 5 deletions src/commonMain/kotlin/requests/InquireHoliday.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.devngho.kisopenapi.requests
import io.github.devngho.kisopenapi.KisOpenApi
import io.github.devngho.kisopenapi.requests.response.*
import io.github.devngho.kisopenapi.requests.util.*
import io.github.devngho.kisopenapi.requests.util.YYYYMMDDSerializer.YYYYMMDD
import io.ktor.client.call.*
import io.ktor.client.request.*
import kotlinx.serialization.SerialName
Expand Down Expand Up @@ -50,10 +51,7 @@ class InquireHoliday(override val client: KisOpenApi):
}

data class InquireHolidayData(
/**
* date style : YYYYMMDD
*/
val baseDate: String,
val baseDate: Date,
override var corp: CorporationRequest? = null,
override var tradeContinuous: String? = "",
val continuousAreaFK: String = "",
Expand All @@ -70,7 +68,7 @@ class InquireHoliday(override val client: KisOpenApi):

url {
parameters.run {
set("BASS_DT", data.baseDate)
set("BASS_DT", data.baseDate.YYYYMMDD)
set("CTX_AREA_NK", data.continuousAreaNK)
set("CTX_AREA_FK", data.continuousAreaFK)
}
Expand Down
6 changes: 4 additions & 2 deletions src/commonMain/kotlin/requests/InquireLivePrice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.ionspin.kotlin.bignum.integer.toBigInteger
import io.github.devngho.kisopenapi.KisOpenApi
import io.github.devngho.kisopenapi.requests.response.CorporationRequest
import io.github.devngho.kisopenapi.requests.response.LiveResponse
import io.github.devngho.kisopenapi.requests.response.Ticker
import io.github.devngho.kisopenapi.requests.util.HourCode
import io.github.devngho.kisopenapi.requests.util.SignPrice
import io.github.devngho.kisopenapi.requests.util.YNSerializer
Expand Down Expand Up @@ -96,8 +97,9 @@ class InquireLivePrice(override val client: KisOpenApi): LiveRequest<InquireLive
override val errorCode: String? = null
}

data class InquireLivePriceData(val stockCode: String, override var corp: CorporationRequest? = null) : LiveData {
override fun tradeKey(client: KisOpenApi): String = stockCode
data class InquireLivePriceData(override val ticker: String, override var corp: CorporationRequest? = null) :
LiveData, Ticker {
override fun tradeKey(client: KisOpenApi): String = ticker
}

private lateinit var job: Job
Expand Down
Loading

0 comments on commit 534d426

Please sign in to comment.