Skip to content

Commit

Permalink
Fixed few more sonarcloud findings
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dekkers committed May 15, 2023
1 parent 58fa24e commit 7b890f4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ class ExecutionEngine(private val pricingEngine: PricingEngine) {
return factory.getExecutor(order) as OrderExecutor<T>
}

/**
* Return the order executor for the provided [order]. This will throw an exception if no [OrderExecutorFactory]
* is registered for the order::class.
*/
internal fun <T : CreateOrder> getCreateOrderExecutor(order: T): OrderExecutor<T> {
val factory = factories.getValue(order::class)

@Suppress("UNCHECKED_CAST")
return factory.getExecutor(order) as OrderExecutor<T>
}

/**
* Unregister the order executor factory for order type [T]
*/
Expand Down Expand Up @@ -195,6 +184,7 @@ class ExecutionEngine(private val pricingEngine: PricingEngine) {
*/
fun clear() {
executors.clear()
modifiers.clear()
pricingEngine.clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import java.time.Instant

internal class OCOOrderExecutor(override val order: OCOOrder) : OrderExecutor<OCOOrder> {

private val first = ExecutionEngine.getCreateOrderExecutor(order.first)
private val second = ExecutionEngine.getCreateOrderExecutor(order.second)
private val first = ExecutionEngine.getExecutor(order.first)
private val second = ExecutionEngine.getExecutor(order.second)
private var active = 0

override var status: OrderStatus = OrderStatus.INITIAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ internal class OTOOrderExecutor(override val order: OTOOrder) : OrderExecutor<OT

override var status: OrderStatus = OrderStatus.INITIAL

private val first = ExecutionEngine.getCreateOrderExecutor(order.primary)
private val second = ExecutionEngine.getCreateOrderExecutor(order.secondary)
private val first = ExecutionEngine.getExecutor(order.primary)
private val second = ExecutionEngine.getExecutor(order.secondary)

/**
* Cancel the order, return true if successful, false otherwise
Expand Down
4 changes: 2 additions & 2 deletions roboquant/src/main/kotlin/org/roboquant/orders/OrderState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.roboquant.orders
import org.roboquant.common.Asset
import org.roboquant.common.Summary
import org.roboquant.common.summary
import org.roboquant.orders.OrderStatus.*
import org.roboquant.orders.OrderStatus.INITIAL
import java.time.Instant
import java.time.temporal.ChronoUnit

Expand Down Expand Up @@ -78,7 +78,7 @@ class OrderState private constructor(
* IllegalState Exception.
*/
fun update(newStatus: OrderStatus, time: Instant): OrderState {
if (status.closed) throw IllegalStateException("cannot update a closed order, status=$status")
check (! status.closed) { "cannot update a closed order, status=$status" }
val newOpenedAt = if (openedAt == Instant.MAX) time else openedAt
val newClosedAt = if (newStatus.closed) time else closedAt
return OrderState(order, newStatus, newOpenedAt, newClosedAt)
Expand Down

0 comments on commit 7b890f4

Please sign in to comment.