Skip to content

Commit

Permalink
feat: orderStatus interface - upbitOrderStatus API integration
Browse files Browse the repository at this point in the history
  • Loading branch information
traeper committed Jun 27, 2019
1 parent 6d78bee commit ce1c0a1
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ target/
/nbdist/
/.nb-gradle/

*.log
*.log

*/out/
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class CoinealOrderOperator(
secretKey: String,
private val coinealRawOrderOperation: CoinealRawOrderOperation
) : OrderOperation(accessKey, secretKey) {
override fun orderStatus(pair: CurrencyPair, orderId: Pageable): Mono<OrderStatus> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

override fun marketOrder(
pair: CurrencyPair,
tradeSideType: TradeSideType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.njkim.reactivecrypto.core.common.model.currency.Currency
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair
import com.njkim.reactivecrypto.core.common.model.order.OrderSideType
import com.njkim.reactivecrypto.core.common.model.order.OrderStatusType
import com.njkim.reactivecrypto.core.common.model.order.TradeSideType
import java.math.BigDecimal
import java.time.ZonedDateTime
Expand Down Expand Up @@ -58,6 +59,10 @@ interface ExchangeJsonObjectMapper {
return null
}

fun orderStatusTypeDeserializer(): JsonDeserializer<OrderStatusType>? {
return null
}

fun customConfiguration(simpleModule: SimpleModule) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.time.ZonedDateTime

data class OrderStatus(
val uniqueId: String,
val orderStatusType: OrderStatusType,

val orderSideType: OrderSideType,
val currencyPair: CurrencyPair,
Expand All @@ -34,4 +35,5 @@ data class OrderStatus(
val remainingFee: BigDecimal? = null,

val createDateTime: ZonedDateTime

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.njkim.reactivecrypto.core.common.model.order


/**
Created by jay on 27/06/2019
**/
enum class OrderStatusType {
WAIT, // 체결 대기
DONE, // 전체 체결 완료
CANCEL // 주문 취소
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@ abstract class OrderOperation(
abstract fun openOrders(pair: CurrencyPair, pageable: Pageable): Mono<Page<OrderStatus>>

abstract fun tradeHistory(pair: CurrencyPair, pageable: Pageable): Mono<Page<TickData>>

abstract fun orderStatus(pair: CurrencyPair, orderId: String): Mono<OrderStatus>
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
import com.njkim.reactivecrypto.core.ExchangeJsonObjectMapper
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair
import com.njkim.reactivecrypto.core.common.model.order.OrderSideType
import com.njkim.reactivecrypto.core.common.model.order.OrderStatusType
import com.njkim.reactivecrypto.core.common.model.order.TradeSideType
import com.njkim.reactivecrypto.upbit.model.UpbitOrderType
import org.apache.commons.lang3.StringUtils
Expand Down Expand Up @@ -64,6 +65,15 @@ class UpbitJsonObjectMapper : ExchangeJsonObjectMapper {
}
}

override fun orderStatusTypeDeserializer(): JsonDeserializer<OrderStatusType>? {
return object : JsonDeserializer<OrderStatusType>() {
override fun deserialize(p: JsonParser, ctxt: DeserializationContext?): OrderStatusType {
val valueAsString = p.valueAsString
return OrderStatusType.valueOf(valueAsString.toUpperCase())
}
}
}

/**
* upbit value : ask, bid
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@ package com.njkim.reactivecrypto.upbit.http

import com.fasterxml.jackson.module.kotlin.convertValue
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair
import com.njkim.reactivecrypto.core.common.model.order.OrderCancelResult
import com.njkim.reactivecrypto.core.common.model.order.OrderPlaceResult
import com.njkim.reactivecrypto.core.common.model.order.OrderStatus
import com.njkim.reactivecrypto.core.common.model.order.TickData
import com.njkim.reactivecrypto.core.common.model.order.TradeSideType
import com.njkim.reactivecrypto.core.common.model.order.*
import com.njkim.reactivecrypto.core.common.model.paging.Page
import com.njkim.reactivecrypto.core.common.model.paging.Pageable
import com.njkim.reactivecrypto.core.http.OrderOperation
import com.njkim.reactivecrypto.upbit.UpbitJsonObjectMapper
import com.njkim.reactivecrypto.upbit.http.raw.sign
import com.njkim.reactivecrypto.upbit.http.raw.upbitErrorHandling
import com.njkim.reactivecrypto.upbit.model.UpbitOrder
import com.njkim.reactivecrypto.upbit.model.UpbitOrderStatus
import com.njkim.reactivecrypto.upbit.model.UpbitOrderType
import org.springframework.web.reactive.function.BodyInserters
import org.springframework.web.reactive.function.client.WebClient
Expand All @@ -45,6 +42,39 @@ class UpbitOrderOperation(
override val secretKey: String,
private val privateWebClient: WebClient
) : OrderOperation(accessKey, secretKey) {
override fun orderStatus(pair: CurrencyPair, orderId: String): Mono<OrderStatus> {
val marketRequest =
mapOf(
"uuid" to orderId
)

val upbitRequest = UpbitJsonObjectMapper.instance.convertValue<Map<String, Any>>(marketRequest)
val sign = sign(upbitRequest, accessKey, secretKey)

return privateWebClient
.post()
.uri { it.path("/v1/order").build() }
.header("Authorization", "Bearer $sign")
.retrieve()
.upbitErrorHandling()
.bodyToMono<UpbitOrderStatus>()
.map {
OrderStatus(
it.uuid,
it.orderStatusType,
it.side,
it.currencyPair,
it.price,
it.volume,
it.executedVolume,
it.paidFee,
it.reservedFee,
it.remainingFee,
it.createdAt
)
}
}

override fun tradeHistory(pair: CurrencyPair, pageable: Pageable): Mono<Page<TickData>> {
TODO("not implemented")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2019 namjug-kim
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.njkim.reactivecrypto.upbit.model

import com.fasterxml.jackson.annotation.JsonProperty
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair
import com.njkim.reactivecrypto.core.common.model.order.OrderSideType
import com.njkim.reactivecrypto.core.common.model.order.OrderStatus
import com.njkim.reactivecrypto.core.common.model.order.OrderStatusType
import java.math.BigDecimal
import java.time.ZonedDateTime

/**
* @author traeper
*/
data class UpbitOrderStatus(

@get:JsonProperty("uuid")
val uuid: String,

@get:JsonProperty("side")
val side: OrderSideType,

@get:JsonProperty("ord_type")
val ordType: String,

@get:JsonProperty("price")
val price: BigDecimal,

@get:JsonProperty("state")
val orderStatusType: OrderStatusType,

@get:JsonProperty("market")
val currencyPair: CurrencyPair,

@get:JsonProperty("created_at")
val createdAt: ZonedDateTime,

@get:JsonProperty("volume")
val volume: BigDecimal,

@get:JsonProperty("remaining_volume")
val remainingVolume: BigDecimal,

@get:JsonProperty("reserved_fee")
val reservedFee: BigDecimal,

@get:JsonProperty("remaining_fee")
val remainingFee: BigDecimal,

@get:JsonProperty("paid_fee")
val paidFee: BigDecimal,

@get:JsonProperty("locked")
val locked: BigDecimal,

@get:JsonProperty("executed_volume")
val executedVolume: BigDecimal,

@get:JsonProperty("trades_count")
val tradesCount: Int
)

0 comments on commit ce1c0a1

Please sign in to comment.