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 @@ -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
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ spring:
cloud:
consul:
host: ${CONSUL_HOST}
main:
allow-bean-definition-overriding: true
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}

}
2 changes: 2 additions & 0 deletions Api/api-app/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ spring:
consul:
host: ${CONSUL_HOST}
port: 8500
main:
allow-bean-definition-overriding: true

app:
cors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 $$
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
16 changes: 8 additions & 8 deletions Deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Wallet/wallet-app/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spring:
consul:
host: ${CONSUL_HOST}
port: 8500
main:
allow-bean-definition-overriding: true

app:
auth:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
"""
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}