diff --git a/matching-gateway/matching-gateway-app/src/main/resources/application.yml b/matching-gateway/matching-gateway-app/src/main/resources/application.yml index 933c1c37b..03e5c1f69 100644 --- a/matching-gateway/matching-gateway-app/src/main/resources/application.yml +++ b/matching-gateway/matching-gateway-app/src/main/resources/application.yml @@ -12,7 +12,7 @@ spring: r2dbc: url: r2dbc:postgresql://${DB_IP_PORT:localhost}/opex username: ${dbusername:opex} - password: ${dbpassword:hiopex} + password: ${DB_PASS:hiopex} initialization-mode: always cloud: bootstrap: diff --git a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/dao/PairSettingRepository.kt b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/dao/PairSettingRepository.kt index b5fa13ff2..12fcff723 100644 --- a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/dao/PairSettingRepository.kt +++ b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/dao/PairSettingRepository.kt @@ -5,11 +5,12 @@ import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository import reactor.core.publisher.Mono +import java.math.BigDecimal @Repository interface PairSettingRepository : ReactiveCrudRepository { fun findByPair(pair: String): Mono - @Query("insert into pair_setting(pair,is_available) values(:pair,:isAvailable) ") - fun insert(pair: String, isAvailable: Boolean): Mono + @Query("insert into pair_setting(pair,is_available,min_order,max_order,order_types) values(:pair,:isAvailable,:minOrder,:maxOrder,:orderTypes) ") + fun insert(pair: String, isAvailable: Boolean , minOrder : BigDecimal, maxOrder : BigDecimal,orderTypes : String): Mono } diff --git a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingInitializer.kt b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingInitializer.kt index d7368fb4c..0137f55f9 100644 --- a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingInitializer.kt +++ b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingInitializer.kt @@ -1,6 +1,5 @@ package co.nilin.opex.matching.gateway.ports.postgres.service -import co.nilin.opex.common.OpexError import co.nilin.opex.matching.gateway.ports.postgres.dao.PairSettingRepository import co.nilin.opex.matching.gateway.ports.postgres.dto.PairSetting import co.nilin.opex.matching.gateway.ports.postgres.util.CacheManager @@ -12,6 +11,7 @@ import kotlinx.coroutines.reactive.awaitFirstOrNull import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Service +import java.math.BigDecimal import java.util.concurrent.TimeUnit import javax.annotation.PostConstruct @@ -30,9 +30,9 @@ class PairSettingInitializer( fun initialize() { logger.info( """ - ================================================ - Initialize Pair Settings - ================================================ +================================================================================================ + Initialize Pair Settings +================================================================================================ """ ) scope.launch { @@ -40,16 +40,27 @@ class PairSettingInitializer( symbols.split(",").forEach { pair -> val existingPair = pairSettingRepository.findByPair(pair).awaitFirstOrNull() - val pairToCache = existingPair ?: pairSettingRepository.insert(pair, false).awaitFirstOrNull() - ?: throw OpexError.BadRequest.exception() - logger.info("Added Pair: $pair") + val pairToCache = existingPair ?: pairSettingRepository.insert( + pair, + false, + BigDecimal.ONE, + BigDecimal.ONE, + "LIMIT_ORDER,MARKET_ORDER" + ).then(pairSettingRepository.findByPair(pair)).awaitFirstOrNull() + .also { if (it == null) logger.warn("Failed to insert pair: $pair") } + ?: return@forEach - cacheManager.put(pair, pairToCache.toPairSetting(), 5, TimeUnit.MINUTES) + if (existingPair != null) logger.info("Pair already exists: $pair") else logger.info("Added Pair: $pair") - if (existingPair != null) { - logger.info("Pair already exists: $pair") - } + cacheManager.put(pair, pairToCache.toPairSetting(), 5, TimeUnit.MINUTES) } + logger.info( + """ +================================================================================================ + Completed Successfully +================================================================================================ + """ + ) } catch (e: Exception) { logger.error("Error initializing Pair Settings: ${e.message}") throw e diff --git a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/resources/schema.sql b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/resources/schema.sql index a32c74251..c8a595b04 100644 --- a/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/resources/schema.sql +++ b/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/resources/schema.sql @@ -11,12 +11,12 @@ $$ IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'pair_setting' AND column_name = 'min_order') THEN ALTER TABLE pair_setting - ADD COLUMN min_order DECIMAL NOT NULL default 0.000001; + ADD COLUMN min_order DECIMAL NOT NULL default 1; END IF; IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'pair_setting' AND column_name = 'max_order') THEN ALTER TABLE pair_setting - ADD COLUMN max_order DECIMAL NOT NULL default 100; + ADD COLUMN max_order DECIMAL NOT NULL default 1; END IF; IF NOT EXISTS (SELECT 1 FROM information_schema.columns