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
@@ -1,6 +1,8 @@
package co.nilin.opex.market.ports.postgres.dao

import co.nilin.opex.market.core.inout.*
import co.nilin.opex.market.ports.postgres.data.MarketTradeProjection
import co.nilin.opex.market.ports.postgres.data.TradeUserContextProjection
import co.nilin.opex.market.ports.postgres.model.*
import org.springframework.data.r2dbc.repository.Query
import org.springframework.data.repository.query.Param
Expand Down Expand Up @@ -32,9 +34,8 @@ interface TradeRepository : ReactiveCrudRepository<TradeModel, Long> {
"""
SELECT
t.symbol AS symbol,
t.base_asset AS baseAsset,
t.quote_asset AS quoteAsset,

t.base_asset AS base_asset,
t.quote_asset AS quote_asset,
t.trade_id AS id,
t.matched_price AS price,
t.matched_quantity AS quantity,
Expand All @@ -46,24 +47,15 @@ interface TradeRepository : ReactiveCrudRepository<TradeModel, Long> {
ELSE to2.quote_quantity
END,
0
) AS quoteQuantity,
) AS quote_quantity,

t.create_date AS createDate,
t.create_date AS create_date,

COALESCE(
CASE
WHEN mo.side = 'BID'
THEN TRUE
ELSE FALSE
END,
FALSE
) AS isMakerBuyer,

NULL AS ouid,
NULL AS commission,
NULL AS commissionAsset,
NULL AS isBuyer,
NULL AS isMaker
CASE
WHEN mo.side = 'BID'
THEN TRUE
ELSE FALSE
END AS is_maker_buyer

FROM trades t

Expand All @@ -80,12 +72,9 @@ interface TradeRepository : ReactiveCrudRepository<TradeModel, Long> {
"""
)
fun findRecentMarketTrades(
@Param("symbol")
symbol: String?,

@Param("limit")
limit: Int
): Flux<TradeUserContextProjection>
@Param("symbol") symbol: String?,
@Param("limit") limit: Int
): Flux<MarketTradeProjection>


@Query("""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package co.nilin.opex.market.ports.postgres.data

import java.math.BigDecimal
import java.time.LocalDateTime

data class MarketTradeProjection(
val symbol: String,
val baseAsset: String,
val quoteAsset: String,
val id: Long,
val price: BigDecimal,
val quantity: BigDecimal,
val quoteQuantity: BigDecimal,
val createDate: LocalDateTime,
val isMakerBuyer: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package co.nilin.opex.market.core.inout
package co.nilin.opex.market.ports.postgres.data

import java.math.BigDecimal
import java.time.LocalDateTime
Expand All @@ -18,5 +18,4 @@ data class TradeUserContextProjection(
val commissionAsset: String? = null,
val isBuyer: Boolean? = null,
val isMaker: Boolean? = null
)

)
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class MarketQueryHandlerImpl(
.map {
MarketTrade(
symbol = it.symbol,
baseAsset = it.baseAsset!!,
quoteAsset = it.quoteAsset!!,
baseAsset = it.baseAsset,
quoteAsset = it.quoteAsset,
id = it.id,
price = it.price,
quantity = it.quantity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class MarketQueryHandlerTest {
} returns Flux.just(VALID.TRADE_MODEL)
every {
tradeRepository.findRecentMarketTrades(VALID.ETH_USDT, 1)
} returns Flux.just(VALID.TRADE_USER_CONTEXT)
} returns Flux.just(VALID.MARKET_TRADE)
every {
orderRepository.findByOuid(VALID.TRADE_MODEL.makerOuid)
} returns Mono.just(VALID.MAKER_ORDER_MODEL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import co.nilin.opex.market.core.event.RichOrder
import co.nilin.opex.market.core.event.RichOrderUpdate
import co.nilin.opex.market.core.event.RichTrade
import co.nilin.opex.market.core.inout.*
import co.nilin.opex.market.ports.postgres.data.MarketTradeProjection
import co.nilin.opex.market.ports.postgres.data.TradeUserContextProjection
import co.nilin.opex.market.ports.postgres.model.LastPrice
import co.nilin.opex.market.ports.postgres.model.OrderModel
import co.nilin.opex.market.ports.postgres.model.OrderStatusModel
Expand Down Expand Up @@ -126,6 +128,19 @@ object VALID {
true
)

val MARKET_TRADE = MarketTradeProjection(
ETH_USDT,
"ETH",
"USDT",
1,
BigDecimal.valueOf(100000),
BigDecimal.valueOf(0.001), // Minimum of orders quantities
BigDecimal.valueOf(100).stripTrailingZeros(),
UPDATE_DATE,
false,

)

val LAST_PRICE_MODEL = LastPrice("ETH_USDT", BigDecimal.valueOf(100000))

val AGGREGATED_ORDER_PRICE_MODEL = AggregatedOrderPriceModel(
Expand Down
Loading