Skip to content

Commit

Permalink
feat: add biannce error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
traeper committed Jul 4, 2019
1 parent f315597 commit cfae98e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.quantinel.remarketer.strategy.sdk.binance

import com.fasterxml.jackson.module.kotlin.convertValue
import com.njkim.reactivecrypto.binance.BinanceJsonObjectMapper
import com.njkim.reactivecrypto.binance.http.raw.binanceErrorHandling
import com.njkim.reactivecrypto.binance.model.BinanceOrderCancelResponse
import com.njkim.reactivecrypto.binance.model.BinancePlaceOrderResponse
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair
Expand Down Expand Up @@ -67,6 +68,7 @@ class BinanceRawTradeOperator internal constructor(private val webClient: WebCli
.build()
}
.retrieve()
.binanceErrorHandling()
.bodyToMono()
}

Expand Down Expand Up @@ -148,6 +150,7 @@ class BinanceRawTradeOperator internal constructor(private val webClient: WebCli
.build()
}
.retrieve()
.binanceErrorHandling()
.bodyToMono()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.njkim.reactivecrypto.binance.http.raw

import com.njkim.reactivecrypto.binance.model.BinanceApiException
import com.njkim.reactivecrypto.binance.model.BinanceErrorResponse
import org.springframework.web.reactive.function.client.WebClient

/**
Created by jay on 2019-07-04
**/
fun WebClient.ResponseSpec.binanceErrorHandling(): WebClient.ResponseSpec = onStatus(
{ it.isError },
{ clientResponse ->
clientResponse.bodyToMono(BinanceErrorResponse::class.java)
.map { BinanceApiException(clientResponse.statusCode(), it) }
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.binance.model

import org.springframework.http.HttpStatus

data class BinanceApiException(
val httpStatus: HttpStatus,
val binanceErrorResponse: BinanceErrorResponse
) : RuntimeException()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.binance.model

data class BinanceErrorResponse(val code: Int, val msg: String)

0 comments on commit cfae98e

Please sign in to comment.