diff --git a/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/FinancialActionsJob.kt b/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/FinancialActionsJob.kt index d4e02be81..c95291fea 100644 --- a/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/FinancialActionsJob.kt +++ b/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/FinancialActionsJob.kt @@ -3,10 +3,12 @@ package co.nilin.opex.app.scheduler import co.nilin.opex.accountant.core.api.FinancialActionJobManager import kotlinx.coroutines.runBlocking import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Profile import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service @Service +@Profile("scheduled") class FinancialActionsJob( val financialActionJobManager: FinancialActionJobManager ) { diff --git a/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/TempEventsJob.kt b/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/TempEventsJob.kt index 6956089d2..e98faedb5 100644 --- a/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/TempEventsJob.kt +++ b/Accountant/accountant-app/src/main/kotlin/co/nilin/opex/app/scheduler/TempEventsJob.kt @@ -4,10 +4,12 @@ import co.nilin.opex.accountant.core.spi.TempEventPersister import co.nilin.opex.accountant.core.spi.TempEventRepublisher import kotlinx.coroutines.runBlocking import org.slf4j.LoggerFactory +import org.springframework.context.annotation.Profile import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service @Service +@Profile("scheduled") class TempEventsJob( val tempEventPersister: TempEventPersister, val tempEventRepublisher: TempEventRepublisher, @@ -20,7 +22,7 @@ class TempEventsJob( runBlocking { try { //read unprocessed temp event and call republish - val tempEvents = tempEventPersister.fetchTempEvents(0, 100); + val tempEvents = tempEventPersister.fetchTempEvents(0, 100) if (tempEvents.isNotEmpty()) { tempEventRepublisher.republish(tempEvents.map { event -> event.eventBody }) tempEventPersister.removeTempEvents(tempEvents) diff --git a/Accountant/accountant-app/src/main/resources/application-docker.yml b/Accountant/accountant-app/src/main/resources/application-docker.yml index 238e144fa..09d0ed7da 100644 --- a/Accountant/accountant-app/src/main/resources/application-docker.yml +++ b/Accountant/accountant-app/src/main/resources/application-docker.yml @@ -10,3 +10,5 @@ spring: cloud: consul: host: ${CONSUL_HOST} + main: + allow-bean-definition-overriding: true \ No newline at end of file diff --git a/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresConfig.kt b/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresConfig.kt index cb04c037f..e8b7b159a 100644 --- a/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresConfig.kt +++ b/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresConfig.kt @@ -9,7 +9,7 @@ import org.springframework.r2dbc.core.DatabaseClient class PostgresConfig(db: DatabaseClient) { init { - val sql = """ + val sql = """ CREATE TABLE IF NOT EXISTS orders ( id SERIAL PRIMARY KEY, ouid VARCHAR(72) NOT NULL UNIQUE, @@ -79,21 +79,12 @@ class PostgresConfig(db: DatabaseClient) { event_type VARCHAR(72) NOT NULL, event_body TEXT, event_date TIMESTAMP - ); - insert into pair_config values('btc_usdt', 'btc', 'usdt', 0.000001, 0.01, 55000)ON CONFLICT DO NOTHING; - insert into pair_fee_config values(1, 'btc_usdt', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_fee_config values(2, 'btc_usdt', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_config values('nln_usdt', 'nln', 'usdt', 1.0, 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_fee_config values(3, 'nln_usdt', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_fee_config values(4, 'nln_usdt', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_config values('nln_btc', 'nln', 'btc', 1.0, 0.000001, 1/5500000) ON CONFLICT DO NOTHING; - insert into pair_fee_config values(5, 'nln_btc', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; - insert into pair_fee_config values(6, 'nln_btc', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + ); commit; """ val initDb = db.sql { sql } initDb // initialize the database - .then() - .subscribe() // execute + .then() + .subscribe() // execute } } diff --git a/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresDemoConfig.kt b/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresDemoConfig.kt new file mode 100644 index 000000000..239c623da --- /dev/null +++ b/Accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/port/accountant/postgres/config/PostgresDemoConfig.kt @@ -0,0 +1,31 @@ +package co.nilin.opex.port.accountant.postgres.config + +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories +import org.springframework.r2dbc.core.DatabaseClient + +@Configuration +@Profile("demo") +class PostgresDemoConfig(db: DatabaseClient) { + + init { + val sql = """ + insert into pair_config values('btc_usdt', 'btc', 'usdt', 0.000001, 0.01, 55000)ON CONFLICT DO NOTHING; + insert into pair_fee_config values(1, 'btc_usdt', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_fee_config values(2, 'btc_usdt', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_config values('nln_usdt', 'nln', 'usdt', 1.0, 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_fee_config values(3, 'nln_usdt', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_fee_config values(4, 'nln_usdt', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_config values('nln_btc', 'nln', 'btc', 1.0, 0.000001, 1/5500000) ON CONFLICT DO NOTHING; + insert into pair_fee_config values(5, 'nln_btc', 'ASK', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + insert into pair_fee_config values(6, 'nln_btc', 'BID', '*', 0.01, 0.01) ON CONFLICT DO NOTHING; + commit; + """ + val initDb = db.sql { sql } + initDb // initialize the database + .then() + .subscribe() // execute + } + +} \ No newline at end of file diff --git a/Api/api-app/src/main/resources/application-docker.yml b/Api/api-app/src/main/resources/application-docker.yml index 2c3e93788..0ebdb297a 100644 --- a/Api/api-app/src/main/resources/application-docker.yml +++ b/Api/api-app/src/main/resources/application-docker.yml @@ -11,6 +11,8 @@ spring: consul: host: ${CONSUL_HOST} port: 8500 + main: + allow-bean-definition-overriding: true app: cors: diff --git a/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresConfig.kt b/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresConfig.kt index 9ac3d700a..b451a97b1 100644 --- a/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresConfig.kt +++ b/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresConfig.kt @@ -57,9 +57,6 @@ class PostgresConfig(db: DatabaseClient) { symbol VARCHAR(72) PRIMARY KEY, value VARCHAR(72) UNIQUE NOT NULL ); - INSERT INTO symbol_maps(symbol, value) VALUES('btc_usdt', 'BTCUSDT') ON CONFLICT DO NOTHING; - INSERT INTO symbol_maps(symbol, value) VALUES('eth_usdt', 'ETHUSDT') ON CONFLICT DO NOTHING; - INSERT INTO symbol_maps(symbol, value) VALUES('eth_btc', 'ETHBTC') ON CONFLICT DO NOTHING; create or replace function interval_generator(start_ts timestamp without TIME ZONE, end_ts timestamp without TIME ZONE, round_interval INTERVAL) returns TABLE(start_time timestamp without TIME ZONE, end_time timestamp without TIME ZONE) as $$ diff --git a/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresDemoConfig.kt b/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresDemoConfig.kt new file mode 100644 index 000000000..5ad1b2dbd --- /dev/null +++ b/Api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/port/api/postgres/config/PostgresDemoConfig.kt @@ -0,0 +1,26 @@ +package co.nilin.opex.port.api.postgres.config + +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories +import org.springframework.r2dbc.core.DatabaseClient + +@Configuration +@Profile("demo") +class PostgresDemoConfig(db: DatabaseClient) { + + init { + val sql = + """ + INSERT INTO symbol_maps(symbol, value) VALUES('btc_usdt', 'BTCUSDT') ON CONFLICT DO NOTHING; + INSERT INTO symbol_maps(symbol, value) VALUES('eth_usdt', 'ETHUSDT') ON CONFLICT DO NOTHING; + INSERT INTO symbol_maps(symbol, value) VALUES('eth_btc', 'ETHBTC') ON CONFLICT DO NOTHING; + INSERT INTO symbol_maps(symbol, value) VALUES('nln_usdt', 'NLNUSDT') ON CONFLICT DO NOTHING; + INSERT INTO symbol_maps(symbol, value) VALUES('nln_btc', 'NLNBTC') ON CONFLICT DO NOTHING; + """ + val initDb = db.sql { sql } + initDb // initialize the database + .then() + .subscribe() // execute + } +} diff --git a/Deployment/docker-compose.yml b/Deployment/docker-compose.yml index e869b6240..d6995de69 100644 --- a/Deployment/docker-compose.yml +++ b/Deployment/docker-compose.yml @@ -152,7 +152,7 @@ services: - 127.0.0.1:1045:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_ACTIVE=docker,demo,scheduled - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -174,7 +174,7 @@ services: - 127.0.0.1:8090:8090 environment: - JAVA_OPTS=-Xmx256m - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_ACTIVE=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -197,7 +197,7 @@ services: - 127.0.0.1:1046:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_ACTIVE=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis networks: @@ -216,7 +216,7 @@ services: - 127.0.0.1:1047:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_DEFAULT=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -236,7 +236,7 @@ services: - 127.0.0.1:1048:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_ACTIVE=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -264,7 +264,7 @@ services: - 127.0.0.1:1049:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_DEFAULT=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -290,7 +290,7 @@ services: - 127.0.0.1:1050:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_DEFAULT=docker,demo - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul @@ -331,7 +331,7 @@ services: - 127.0.0.1:1051:1044 environment: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044 - - SPRING_PROFILES_ACTIVE=docker + - SPRING_PROFILES_DEFAULT=docker,demo,scheduled - KAFKA_IP_PORT=kafka:9092 - REDIS_HOST=redis - CONSUL_HOST=consul diff --git a/Wallet/wallet-app/src/main/resources/application-docker.yml b/Wallet/wallet-app/src/main/resources/application-docker.yml index ead9d6314..4c9921286 100644 --- a/Wallet/wallet-app/src/main/resources/application-docker.yml +++ b/Wallet/wallet-app/src/main/resources/application-docker.yml @@ -16,6 +16,8 @@ spring: consul: host: ${CONSUL_HOST} port: 8500 + main: + allow-bean-definition-overriding: true app: auth: diff --git a/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresConfig.kt b/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresConfig.kt index 2d8433420..2abec8c14 100644 --- a/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresConfig.kt +++ b/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresConfig.kt @@ -85,18 +85,6 @@ class PostgresConfig(db: DatabaseClient) { ); insert into wallet_owner(id, uuid, title, level) values(1, '1', 'system', 'basic') ON CONFLICT DO NOTHING; - insert into currency(name, symbol, precision) values('btc', 'btc', 0.000001) ON CONFLICT DO NOTHING;; - insert into currency(name, symbol, precision) values('usdt', 'usdt', 0.01) ON CONFLICT DO NOTHING;; - insert into currency(name, symbol, precision) values('nln', 'nln', 1) ON CONFLICT DO NOTHING;; - insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'btc', 'nln', 5500000) ON CONFLICT DO NOTHING; - insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'usdt', 'nln', 100) ON CONFLICT DO NOTHING; - insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'btc', 'usdt', 55000) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(1, 1, 'main', 'btc', 10) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(2, 1, 'exchange', 'btc', 0) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(3, 1, 'main', 'usdt', 550000) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(4, 1, 'exchange', 'usdt', 0) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(5, 1, 'main', 'nln', 100000000) ON CONFLICT DO NOTHING; - insert into wallet(id, owner, wallet_type, currency, balance) values(6, 1, 'exchange', 'nln', 0) ON CONFLICT DO NOTHING; insert into user_limits (id, level, owner, action, wallet_type, daily_total, daily_count, monthly_total, monthly_count)values(1, null, 1, 'withdraw', 'main', 1000, 100, 10000, 1000) ON CONFLICT DO NOTHING; """ } diff --git a/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresDemoConfig.kt b/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresDemoConfig.kt new file mode 100644 index 000000000..1515a8aa3 --- /dev/null +++ b/Wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/port/wallet/postgres/config/PostgresDemoConfig.kt @@ -0,0 +1,35 @@ +package co.nilin.opex.port.wallet.postgres.config + +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories +import org.springframework.r2dbc.core.DatabaseClient + +@Configuration +@Profile("demo") +class PostgresDemoConfig(db: DatabaseClient) { + + init { + val initDb = db.sql { + """ + insert into wallet_owner(id, uuid, title, level) values(1, '1', 'system', 'basic') ON CONFLICT DO NOTHING; + insert into currency(name, symbol, precision) values('btc', 'btc', 0.000001) ON CONFLICT DO NOTHING;; + insert into currency(name, symbol, precision) values('usdt', 'usdt', 0.01) ON CONFLICT DO NOTHING;; + insert into currency(name, symbol, precision) values('nln', 'nln', 1) ON CONFLICT DO NOTHING;; + insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'btc', 'nln', 5500000) ON CONFLICT DO NOTHING; + insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'usdt', 'nln', 100) ON CONFLICT DO NOTHING; + insert into currency_rate(id, source_currency, dest_currency, rate) values(1, 'btc', 'usdt', 55000) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(1, 1, 'main', 'btc', 10) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(2, 1, 'exchange', 'btc', 0) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(3, 1, 'main', 'usdt', 550000) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(4, 1, 'exchange', 'usdt', 0) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(5, 1, 'main', 'nln', 100000000) ON CONFLICT DO NOTHING; + insert into wallet(id, owner, wallet_type, currency, balance) values(6, 1, 'exchange', 'nln', 0) ON CONFLICT DO NOTHING; + insert into user_limits (id, level, owner, action, wallet_type, daily_total, daily_count, monthly_total, monthly_count)values(1, null, 1, 'withdraw', 'main', 1000, 100, 10000, 1000) ON CONFLICT DO NOTHING; + """ + } + initDb // initialize the database + .then() + .subscribe() // execute + } +}