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 @@ -128,7 +128,7 @@ Security: Bearer user-token required. Requires authenticated user JWT.
return profileProxy.requestContactUpdate(securityContext.jwtAuthentication().tokenValue(), request)
}

@PatchMapping("/contact/update/otp-verification")
@PostMapping("/contact/update/otp-verification")
@Operation(
summary = "Confirm contact update",
description = """PATCH /opex/v1/profile/contact/update/otp-verification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SecurityConfig(private val webClient: WebClient) {
.authorizeExchange() {
it.pathMatchers(HttpMethod.GET, "/v1/admin/**").hasAnyAuthority("ROLE_monitoring", "ROLE_admin")
.pathMatchers("/actuator/**").permitAll()
.pathMatchers("/v1/user/*/orders/open").permitAll()
.pathMatchers("/v1/user/**").authenticated()
.anyExchange().permitAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class UserDataController(
?: throw OpexError.NotFound.exception()
}

@GetMapping("/orders/open")
//todo should be authenticated as soon as possible
@GetMapping("/{uuid}/orders/open")
suspend fun getUserOpenOrders(
@RequestParam limit: Int, @CurrentSecurityContext securityContext: SecurityContext,
@RequestParam limit: Int, @PathVariable uuid: String,
): List<Order> {
return userQueryHandler.openOrders(securityContext.authentication.name, limit)
return userQueryHandler.openOrders(uuid, limit)
}

@GetMapping("/orders/{symbol}/open")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package co.nilin.opex.market.core.inout

import java.math.BigDecimal
import java.time.LocalDateTime
import java.util.*

// User trade data
data class Trade(
val symbol: String,
val id: Long,
val ouid: String,
val ouid: String? = null,
val price: BigDecimal,
val quantity: BigDecimal,
val quoteQuantity: BigDecimal,
Expand Down
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 @@ -101,7 +101,7 @@ class UserQueryHandlerImpl(
Trade(
it.symbol,
it.id,
requireNotNull(it.ouid),
it.ouid,
it.price,
it.quantity,
it.quoteQuantity,
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ProfileController(
}
}

@PatchMapping("/contact/update/otp-verification")
@PostMapping("/contact/update/otp-verification")
suspend fun confirmContactUpdate(
@RequestBody request: ContactUpdateConfirmRequest,
@CurrentSecurityContext securityContext: SecurityContext
Expand Down
Loading