money.rave.common.backend.expression.position.ProfitRate.kt Maven / Gradle / Ivy
package money.rave.common.backend.expression
import money.rave.common.backend.expression.EvaluationContext
import money.rave.common.backend.expression.Expression
import money.rave.common.backend.scaledBigDecimal
import java.math.BigDecimal
class ProfitRate(
private val price: Expression,
private val defaultCandleIndex: Int = 0,
) : Position() {
override fun evaluate(context: EvaluationContext, candleIndex: Int): BigDecimal {
val openPositionOrder = context.openPositionOrder ?: return BigDecimal.ZERO
val value = openPositionOrder.executedQuoteAssetVolume ?: return BigDecimal.ZERO
val newValue = openPositionOrder.executedBaseAssetVolume?.multiply(price.evaluate(context, defaultCandleIndex + candleIndex)) ?: return BigDecimal.ZERO
return (newValue / value).scaledBigDecimal()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy