Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import java.math.BigDecimal
data class CurrencyExchangeRate(
val sourceSymbol: String,
val destSymbol: String,
val rate: BigDecimal
val rate: BigDecimal,
val isSwappable: Boolean

)

data class CurrencyExchangeRatesResponse(val rates: List<CurrencyExchangeRate>)
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ app:
url: http://opex-otp/v1
captcha:
url: http://opex-captcha
enabled: false
enabled: ${CAPTCHA_ENABLED:true}
device-management:
url: http://opex-device-management
custom-message:
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/kotlin/co/nilin/opex/common/OpexError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ enum class OpexError(val code: Int, val message: String?, val status: HttpStatus
WithdrawCannotBeRequested(6049, "Withdraw cannot be requested", HttpStatus.BAD_REQUEST),
OTPCannotBeRequested(6050, "OTP cannot be requested", HttpStatus.BAD_REQUEST),
WithdrawRequestExpired(6051,"Withdraw request expired", HttpStatus.BAD_REQUEST),
ForbiddenSwapPair(6052, null, HttpStatus.BAD_REQUEST),


// code 7000: api
OrderNotFound(7001, "No order found", HttpStatus.NOT_FOUND),
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ services:
- ADMIN_CLIENT_SECRET=${KC_ADMIN_CLIENT_SECRET}
- PRE_AUTH_CLIENT_SECRET=${KC_PRE_AUTH_CLIENT_SECRET}
- TOKEN_ISSUER_URL=${KC_ISSUER_URL}
- CAPTCHA_ENABLED=${CAPTCHA_ENABLED}
volumes:
- auth-gateway-keys:/app/keys
depends_on:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package co.nilin.opex.wallet.app.controller

import co.nilin.opex.wallet.app.dto.CurrencyExchangeRate
import co.nilin.opex.wallet.app.dto.CurrencyExchangeRatesResponse
import co.nilin.opex.wallet.app.dto.CurrencyPair
import co.nilin.opex.wallet.app.dto.SetCurrencyExchangeRateRequest
import co.nilin.opex.wallet.app.service.otc.GraphService
import co.nilin.opex.wallet.core.inout.CurrencyPrice

import co.nilin.opex.wallet.core.model.otc.*

import io.swagger.annotations.ApiResponse
import io.swagger.annotations.Example
import io.swagger.annotations.ExampleProperty
Expand Down Expand Up @@ -127,6 +124,44 @@ class CurrencyRatesController(
return rateService.getForbiddenPairs()
}

@PostMapping("/forbidden-swap-pairs")
@ApiResponse(
message = "OK",
code = 200,
)
suspend fun addForbiddenSwapPair(@RequestBody request: CurrencyPair) {
request.validate()
rateService.addForbiddenSwapPair(ForbiddenSwapPair(request.sourceSymbol, request.destSymbol))
}

@DeleteMapping("/forbidden-swap-pairs/{sourceSymbol}/{destSymbol}")
@ApiResponse(
message = "OK",
code = 200,
)
suspend fun deleteForbiddenSwapPair(
@PathVariable sourceSymbol: String,
@PathVariable destSymbol: String
): ForbiddenSwapPairs {
return rateService.deleteForbiddenSwapPair(ForbiddenSwapPair(sourceSymbol, destSymbol))
}

@GetMapping("/forbidden-swap-pairs")
@ApiResponse(
message = "OK",
code = 200,
examples = Example(
ExampleProperty(
value = "[{\"sourceSymbol\": \"BTC\",\n" +
" \"destSymbol\": \"ETH\" }]",
mediaType = "application/json"
)
)
)
suspend fun fetchForbiddenSwapPairs(): ForbiddenSwapPairs {
return rateService.getForbiddenSwapPairs()
}

@PostMapping("/transitive-symbols")
@ApiResponse(
message = "OK",
Expand Down Expand Up @@ -175,10 +210,7 @@ class CurrencyRatesController(
@RequestParam("sourceSymbol") sourceSymbol: String? = null,
@RequestParam("destSymbol") destSymbol: String? = null
): CurrencyExchangeRatesResponse {
return CurrencyExchangeRatesResponse(
graphService.buildRoutes(sourceSymbol, destSymbol)
.map { CurrencyExchangeRate(it.getSourceSymbol(), it.getDestSymbol(), it.getRate()) }
)
return CurrencyExchangeRatesResponse(graphService.getCurrencyExchangeRates(sourceSymbol, destSymbol))
}

@GetMapping("/currency/price")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import java.math.BigDecimal
data class CurrencyExchangeRate(
val sourceSymbol: String,
val destSymbol: String,
val rate: BigDecimal
val rate: BigDecimal,
val isSwappable: Boolean =true
)

data class CurrencyExchangeRatesResponse(val rates: List<CurrencyExchangeRate>)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package co.nilin.opex.wallet.app.service.otc

import co.nilin.opex.common.OpexError
import co.nilin.opex.wallet.app.dto.CurrencyExchangeRate
import co.nilin.opex.wallet.core.inout.CurrencyCommand
import co.nilin.opex.wallet.core.inout.CurrencyPrice
import co.nilin.opex.wallet.core.model.otc.ForbiddenPair
import co.nilin.opex.wallet.core.model.otc.ForbiddenSwapPair
import co.nilin.opex.wallet.core.model.otc.Rate
import co.nilin.opex.wallet.core.service.otc.RateService
import co.nilin.opex.wallet.core.spi.CurrencyServiceManager
Expand Down Expand Up @@ -33,7 +35,27 @@ class GraphService(
accumulator.multiply(element)
}
}
}

suspend fun getCurrencyExchangeRates(source: String? = null, dest: String? = null): List<CurrencyExchangeRate> {
val forbiddenSet = rateService
.getForbiddenSwapPairs()
.forbiddenSwapPairs
?.toSet()
?: emptySet()

val routes = buildRoutes(source, dest)

val exchangeRates = routes.map { route ->
val isSwappable = ForbiddenSwapPair(route.getSourceSymbol(), route.getDestSymbol()) !in forbiddenSet
CurrencyExchangeRate(
sourceSymbol = route.getSourceSymbol(),
destSymbol = route.getDestSymbol(),
rate = route.getRate(),
isSwappable = isSwappable
)
}
return exchangeRates
}

suspend fun buildRoutes(source: String? = null, dest: String? = null): MutableList<Route> {
Expand All @@ -57,6 +79,7 @@ class GraphService(
}
}
return routesWithMax2StepV2
// .applyForbiddenSwapPairs()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class CurrencyRatesControllerIT : KafkaEnabledTest() {
CurrencyExchangeRate(
"E",
"U",
BigDecimal.TEN
BigDecimal.TEN,
true
)
)
), routes
Expand Down Expand Up @@ -121,7 +122,8 @@ class CurrencyRatesControllerIT : KafkaEnabledTest() {
Assertions.assertEquals(
CurrencyExchangeRatesResponse(
listOf(
CurrencyExchangeRate("E", "U", BigDecimal.TEN), CurrencyExchangeRate("B", "U", BigDecimal.TEN)
CurrencyExchangeRate("E", "U", BigDecimal.TEN, true),
CurrencyExchangeRate("B", "U", BigDecimal.TEN, true)
)
), allRates
)
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet-app/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ testcontainers:
db:
username: ${dbusername:opex}
password: ${dbpassword:hiopex}
name: wallet
name: opex
version: "postgres:14.9"
logging:
level:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package co.nilin.opex.wallet.core.model.otc

data class ForbiddenSwapPair(
val sourceSymbol: String, val destinationSymbol: String
)

data class ForbiddenSwapPairs(
var forbiddenSwapPairs: List<ForbiddenSwapPair>?
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ interface RateService {

suspend fun getForbiddenPairs(): ForbiddenPairs

suspend fun addForbiddenSwapPair(forbiddenPair: ForbiddenSwapPair)

suspend fun deleteForbiddenSwapPair(forbiddenPair: ForbiddenSwapPair): ForbiddenSwapPairs

suspend fun getForbiddenSwapPairs(): ForbiddenSwapPairs

suspend fun addTransitiveSymbols(symbols: Symbols)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package co.nilin.opex.wallet.ports.postgres.dao

import co.nilin.opex.wallet.ports.postgres.model.ForbiddenSwapPairModel
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono

@Repository
interface ForbiddenSwapPairRepository : ReactiveCrudRepository<ForbiddenSwapPairModel, Long> {

fun findAllBy(): Flux<ForbiddenSwapPairModel>?

fun findBySourceSymbolAndDestinationSymbol(
sourceSymbol: String,
destinationSymbol: String
): Mono<ForbiddenSwapPairModel>?

fun deleteBySourceSymbolAndDestinationSymbol(sourceSymbol: String, destinationSymbol: String): Mono<Void>?

}
Loading
Loading