From a53ee1919cd2f5ed368be779b6c5f8aea26def4c Mon Sep 17 00:00:00 2001 From: Amir Rajabi Date: Sun, 25 May 2025 13:06:30 +0330 Subject: [PATCH 1/3] add password to env --- docker-compose.yml | 1 + .../src/main/resources/application.yml | 2 +- .../postgres/dao/PairSettingRepository.kt | 5 +-- .../service/PairSettingInitializer.kt | 33 ++++++++++++------- .../src/main/resources/schema.sql | 4 +-- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 21d09312a..a49f586fe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -342,6 +342,7 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SYMBOLS=BTC_USDT,ETH_USDT,BTC_IRT,ETH_IRT,USDT_IRT,ETH_BUSD,BTC_BUSD,BNB_BUSD + - MATCHING_GATEWAY_DB_PASS=${MATCHING_GATEWAY_DB_PASS} networks: - default depends_on: 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..72f63b9a9 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: ${MATCHING_GATEWAY_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 From 37b2dac76ce26052b3f6fb30b705264da591c0e8 Mon Sep 17 00:00:00 2001 From: Amir Rajabi <34955519+AmirRajabii@users.noreply.github.com> Date: Sun, 25 May 2025 13:14:44 +0330 Subject: [PATCH 2/3] Update application.yml --- .../matching-gateway-app/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 72f63b9a9..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: ${MATCHING_GATEWAY_DB_PASS:hiopex} + password: ${DB_PASS:hiopex} initialization-mode: always cloud: bootstrap: From 28b45e1c1f5d48dad1b0d3a2abaf053b2ec47be2 Mon Sep 17 00:00:00 2001 From: Amir Rajabi <34955519+AmirRajabii@users.noreply.github.com> Date: Sun, 25 May 2025 13:15:25 +0330 Subject: [PATCH 3/3] Update docker-compose.yml --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a49f586fe..21d09312a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -342,7 +342,6 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SYMBOLS=BTC_USDT,ETH_USDT,BTC_IRT,ETH_IRT,USDT_IRT,ETH_BUSD,BTC_BUSD,BNB_BUSD - - MATCHING_GATEWAY_DB_PASS=${MATCHING_GATEWAY_DB_PASS} networks: - default depends_on: