Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e46dd96
Add preferences module to utility
ebrahimmfadae May 11, 2022
b212e1c
Add implementations field to currency
ebrahimmfadae May 11, 2022
457706c
Add preferences-schema.yml config file
ebrahimmfadae May 11, 2022
f981a88
Update preferences-schema
ebrahimmfadae May 11, 2022
3641923
Add preferences.yml
ebrahimmfadae May 11, 2022
18412e1
Remove redundant `data.sql`s
ebrahimmfadae May 11, 2022
193b19d
Add system wallet to preferences
ebrahimmfadae May 11, 2022
f4e4a8a
preferences: Improve schema
ebrahimmfadae May 12, 2022
45b45e8
preferences: Fix default values
ebrahimmfadae May 12, 2022
2f5e24a
preferences: Make preferences a dummy object
ebrahimmfadae May 12, 2022
e34dc38
preferences: Scape reserved * character in config file
ebrahimmfadae May 12, 2022
7dfc063
preferences: Add initialize logic to bc-gateway
ebrahimmfadae May 12, 2022
e1d5508
preferences: Remove retryTime
ebrahimmfadae May 12, 2022
f4dea9c
preferences: Fix schedule declaration
ebrahimmfadae May 12, 2022
4fd9266
preferences: Fix BUSD declaration
ebrahimmfadae May 12, 2022
f6210a1
bc-gateway: Fix and refactor db init method
ebrahimmfadae May 12, 2022
c0f2a80
accountant: Add preferences to accountant
ebrahimmfadae May 12, 2022
1e751c0
wallet: Add preferences
ebrahimmfadae May 13, 2022
6a3290d
postgres: Remove data.sql load script
ebrahimmfadae May 13, 2022
7d0ca9d
preferences: Decouple dev and demo environments
ebrahimmfadae May 13, 2022
bdb7c35
accountant: Change platform coin to IRT
ebrahimmfadae May 13, 2022
7a7860a
preferences: Read config file location from application.yml
ebrahimmfadae May 13, 2022
5b56d91
preferences: Update docker-compose
ebrahimmfadae May 13, 2022
d96da2f
preferences: Refactor matching-engine to read symbols from preferences
ebrahimmfadae May 13, 2022
5bfafff
wallet: Move gift to preferences
ebrahimmfadae May 13, 2022
38b18cf
wallet: Fix setup preferences
ebrahimmfadae May 13, 2022
5f588b4
preferences: Improve sql scripts
ebrahimmfadae May 13, 2022
563ba7d
preferences: Remove wallet uuid from configs
ebrahimmfadae May 13, 2022
a68d159
wallet: Fix preferences: Improve schema.sql
ebrahimmfadae May 13, 2022
bdf60b5
matching-engine: Fix symbols config
ebrahimmfadae May 13, 2022
2a62d5d
preferences: Add IRT pairs
ebrahimmfadae May 13, 2022
a0e6d4f
preferences: Fix and improve alias section
ebrahimmfadae May 13, 2022
0600724
api: Add symbol_maps constraints
ebrahimmfadae May 13, 2022
4ad4ea9
api: Fix symbol_maps schema
ebrahimmfadae May 13, 2022
2c00909
preferences: Move read file logic to preferences
ebrahimmfadae May 13, 2022
7bbeaec
preferences: Add app.preferences to application.yml of all modules
ebrahimmfadae May 13, 2022
e6bc7c5
preferences: Handle missing file
ebrahimmfadae May 13, 2022
0447abc
preferences: Rename SetupPreferences to InitializeService
ebrahimmfadae May 13, 2022
0edd857
preferences: Move config file address from application.yml to envs
ebrahimmfadae May 14, 2022
558af9e
GitHub: Update GitHub actions
ebrahimmfadae May 14, 2022
f370fd2
wallet: Fix crash in user registration service
ebrahimmfadae May 14, 2022
004fb09
preferences: Replace USDT with BUSD
ebrahimmfadae May 14, 2022
37eac98
preferences: Improve defaults
ebrahimmfadae May 14, 2022
7fd1598
preferences: Refactor config schema
ebrahimmfadae May 14, 2022
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
10 changes: 8 additions & 2 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ jobs:
- name: Build
run: mvn -B -T 1C clean install
- name: Build Docker images
run: TAG=dev docker-compose -f docker-compose.build.yml build
env:
TAG: dev
PREFERENCES_IDENTIFIER: dev
run: docker-compose -f docker-compose.build.yml build
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push images to GitHub Container Registry
run: TAG=dev docker-compose -f docker-compose.build.yml push
env:
TAG: dev
PREFERENCES_IDENTIFIER: dev
run: docker-compose -f docker-compose.build.yml push
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ jobs:
- name: Build
run: mvn -B -T 1C clean install
- name: Build Docker images
run: TAG=latest docker-compose -f docker-compose.build.yml build
env:
TAG: latest
PREFERENCES_IDENTIFIER: dev
run: docker-compose -f docker-compose.build.yml build
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push images to GitHub Container Registry
run: TAG=latest docker-compose -f docker-compose.build.yml push
env:
TAG: dev
PREFERENCES_IDENTIFIER: demo
run: docker-compose -f docker-compose.build.yml push
5 changes: 4 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ jobs:
- name: Build
run: mvn -B -T 1C clean install
- name: Build Docker images
run: TAG=latest docker-compose -f docker-compose.build.yml build
env:
TAG: dev
PREFERENCES_IDENTIFIER: dev
run: docker-compose -f docker-compose.build.yml build
4 changes: 4 additions & 0 deletions accountant/accountant-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.preferences</groupId>
<artifactId>preferences</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package co.nilin.opex.accountant.app.config

import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository
import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository
import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel
import co.nilin.opex.utility.preferences.Preferences
import kotlinx.coroutines.reactor.awaitSingleOrNull
import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.DependsOn
import org.springframework.stereotype.Component

@Component
@DependsOn("postgresConfig")
class InitializeService(
private val pairConfigRepository: PairConfigRepository,
private val pairFeeConfigRepository: PairFeeConfigRepository
) {
@Autowired
private lateinit var preferences: Preferences

@Autowired
fun init() = runBlocking {
preferences.markets.map {
val pair = it.pair ?: "${it.leftSide}_${it.rightSide}"
val leftSideCurrency = preferences.currencies.first { c -> it.leftSide == c.symbol }
val rightSideCurrency = preferences.currencies.first { c -> it.rightSide == c.symbol }
val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble()
val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble()
pairConfigRepository.insert(
pair,
it.leftSide,
it.rightSide,
leftSideFraction,
rightSideFraction,
0.0
).awaitSingleOrNull()
it.feeConfigs.forEach { f ->
runCatching {
pairFeeConfigRepository.save(
PairFeeConfigModel(
null,
pair,
f.direction,
f.userLevel,
f.makerFee.toDouble(),
f.takerFee.toDouble()
)
).awaitSingleOrNull()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spring:
config:
import: vault://secret/${spring.application.name}
app:
coin: nln
coin: IRT
address: 1
wallet:
url: lb://opex-wallet/
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import org.springframework.r2dbc.core.DatabaseClient
@EnableR2dbcRepositories(basePackages = ["co.nilin.opex"])
class PostgresConfig(
db: DatabaseClient,
@Value("classpath:schema.sql") private val schemaResource: Resource,
@Value("classpath:data.sql") private val dataResource: Resource?
@Value("classpath:schema.sql") private val schemaResource: Resource
) {
init {
val schemaReader = schemaResource.inputStream.reader()
val schema = schemaReader.readText().trim()
schemaReader.close()
val dataReader = dataResource?.inputStream?.reader()
val data = dataReader?.readText()?.trim() ?: ""
dataReader?.close()
val initDb = db.sql { schema.plus(data) }
val initDb = db.sql { schema }
initDb // initialize the database
.then()
.subscribe() // execute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package co.nilin.opex.accountant.ports.postgres.dao

import co.nilin.opex.accountant.ports.postgres.model.PairConfigModel
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.repository.reactive.ReactiveCrudRepository
import org.springframework.stereotype.Repository
import reactor.core.publisher.Mono

@Repository
interface PairConfigRepository : ReactiveCrudRepository<PairConfigModel, String>
interface PairConfigRepository : ReactiveCrudRepository<PairConfigModel, String> {
@Query("insert into pair_config values (:pair, :leftSide, :rightSide, :leftSideFraction, :rightSideFraction, :rate) on conflict do nothing")
fun insert(
pair: String,
leftSide: String,
rightSide: String,
leftSideFraction: Double,
rightSideFraction: Double,
rate: Double
): Mono<Void>
}

This file was deleted.

5 changes: 5 additions & 0 deletions accountant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
<artifactId>logging-handler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.preferences</groupId>
<artifactId>preferences</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions api/api-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-vault-config</artifactId>
</dependency>
<dependency>
<groupId>co.nilin.opex.utility.preferences</groupId>
<artifactId>preferences</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package co.nilin.opex.api.app.config

import co.nilin.opex.api.ports.postgres.dao.SymbolMapRepository
import co.nilin.opex.api.ports.postgres.model.SymbolMapModel
import co.nilin.opex.utility.preferences.Preferences
import kotlinx.coroutines.reactor.awaitSingleOrNull
import kotlinx.coroutines.runBlocking
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.DependsOn
import org.springframework.stereotype.Component

@Component
@DependsOn("postgresConfig")
class InitializeService(private val symbolMapRepository: SymbolMapRepository) {
@Autowired
private lateinit var preferences: Preferences

@Autowired
fun init() = runBlocking {
preferences.markets.map {
val pair = it.pair ?: "${it.leftSide}_${it.rightSide}"
val items = it.aliases.map { a -> SymbolMapModel(null, pair, a.key, a.alias) }
runCatching { symbolMapRepository.saveAll(items).collectList().awaitSingleOrNull() }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface SymbolMapper {

suspend fun map(symbol: String?): String?

suspend fun unmap(value: String?): String?
suspend fun unmap(alias: String?): String?

suspend fun getKeyValues(): Map<String, String>
}
suspend fun getAll(): Map<String, String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package co.nilin.opex.api.ports.binance.controller
import org.springframework.web.bind.annotation.RestController

@RestController
class FiltersController {
}
class FiltersController
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class MarketController(
@RequestParam("symbols", required = false)
symbols: String?
): ExchangeInfoResponse {
val symbolsMap = symbolMapper.getKeyValues()
val symbolsMap = symbolMapper.getAll()
val pairConfigs = accountantProxy.getPairConfigs()
.map {
ExchangeInfoSymbol(
symbolsMap[it.pair] ?: it.pair,
"TRADING",
it.leftSideWalletSymbol.toUpperCase(),
it.leftSideWalletSymbol.uppercase(),
BigDecimal.valueOf(it.leftSideFraction).scale(),
it.rightSideWalletSymbol.toUpperCase(),
it.rightSideWalletSymbol.uppercase(),
BigDecimal.valueOf(it.rightSideFraction).scale()
)
}
Expand Down Expand Up @@ -200,4 +200,4 @@ class MarketController(
return list
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import org.springframework.r2dbc.core.DatabaseClient
@EnableR2dbcRepositories(basePackages = ["co.nilin.opex"])
class PostgresConfig(
db: DatabaseClient,
@Value("classpath:schema.sql") private val schemaResource: Resource,
@Value("classpath:data.sql") private val dataResource: Resource?
@Value("classpath:schema.sql") private val schemaResource: Resource
) {
init {
val schemaReader = schemaResource.inputStream.reader()
val schema = schemaReader.readText().trim()
schemaReader.close()
val dataReader = dataResource?.inputStream?.reader()
val data = dataReader?.readText()?.trim() ?: ""
dataReader?.close()
val initDb = db.sql { schema.plus(data) }
val initDb = db.sql { schema }
initDb // initialize the database
.then()
.subscribe() // execute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import reactor.core.publisher.Mono

@Repository
interface SymbolMapRepository : ReactiveCrudRepository<SymbolMapModel, String> {
@Query("select * from symbol_maps where symbol = :symbol and aliasKey = :aliasKey")
fun findByAliasKeyAndSymbol(aliasKey: String, @Param("symbol") symbol: String): Mono<SymbolMapModel>

@Query("select * from symbol_maps where symbol = :symbol")
fun findBySymbol(@Param("symbol") symbol: String): Mono<SymbolMapModel>

@Query("select * from symbol_maps where value = :value")
fun findByValue(@Param("value") value: String): Mono<SymbolMapModel>
}
@Query("select * from symbol_maps where aliasKey = :aliasKey and alias = :alias")
fun findByAliasKeyAndAlias(aliasKey: String, @Param("alias") alias: String): Mono<SymbolMapModel>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ class SymbolMapperImpl(val symbolMapRepository: SymbolMapRepository) : SymbolMap

override suspend fun map(symbol: String?): String? {
if (symbol == null) return null
return symbolMapRepository.findBySymbol(symbol).awaitFirstOrNull()?.value
return symbolMapRepository.findByAliasKeyAndSymbol("binance", symbol).awaitFirstOrNull()?.alias
}

override suspend fun unmap(value: String?): String? {
if (value == null) return null
return symbolMapRepository.findByValue(value).awaitFirstOrNull()?.symbol
override suspend fun unmap(alias: String?): String? {
if (alias == null) return null
return symbolMapRepository.findByAliasKeyAndAlias("binance", alias).awaitFirstOrNull()?.symbol
}

override suspend fun getKeyValues(): Map<String, String> {
override suspend fun getAll(): Map<String, String> {
val map = HashMap<String, String>()
symbolMapRepository.findAll()
.collectList()
.awaitFirstOrElse { emptyList() }
.forEach { map[it.symbol] = it.value }
.filter { it.aliasKey == "binance" }
.associate { it.symbol to it.alias }
return map
}
}
}
Loading