From 4ef33541bb2130b9c77bafb01aff456aa5e1b8d3 Mon Sep 17 00:00:00 2001 From: aforaleka Date: Mon, 17 Jun 2024 13:21:18 -0400 Subject: [PATCH 1/3] remove position leverage validation --- .../validator/InputValidator.kt | 1 - .../trade/TradePositionStateValidator.kt | 111 ------------------ 2 files changed, 112 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt index 6051208e6..ff5737975 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt @@ -29,7 +29,6 @@ internal class InputValidator( "MARKET_ORDER_NOT_ENOUGH_LIQUIDITY" to 1030, "MARKET_ORDER_ERROR_INDEX_PRICE_SLIPPAGE" to 1031, "MARKET_ORDER_ERROR_ORDERBOOK_SLIPPAGE" to 1032, - "MARKET_ORDER_PRICE_IMPACT_AT_MAX_LEVERAGE" to 1033, "ORDER_WOULD_FLIP_POSITION" to 1034, "TRIGGER_MUST_ABOVE_INDEX_PRICE" to 1040, "TRIGGER_MUST_BELOW_INDEX_PRICE" to 1041, diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/validator/trade/TradePositionStateValidator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/validator/trade/TradePositionStateValidator.kt index ef43a22a1..02e445ded 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/validator/trade/TradePositionStateValidator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/validator/trade/TradePositionStateValidator.kt @@ -1,6 +1,5 @@ package exchange.dydx.abacus.validator.trade -import abs import exchange.dydx.abacus.protocols.LocalizerProtocol import exchange.dydx.abacus.protocols.ParserProtocol import exchange.dydx.abacus.state.app.helper.Formatter @@ -43,15 +42,6 @@ internal class TradePositionStateValidator( change, ) if (position != null) { - val leverageError = validatePositionLeverage( - position, - trade, - change, - restricted, - ) - if (leverageError != null) { - errors.add(leverageError) - } val positionSizeError = validatePositionSize( position, market, @@ -105,107 +95,6 @@ internal class TradePositionStateValidator( } } - private fun validatePositionLeverage( - position: Map, - trade: Map, - change: PositionChange, - restricted: Boolean, - ): Map? { - /* - MARKET_ORDER_CLOSE_TO_MAX_LEVERAGE - MARKET_ORDER_PRICE_IMPACT_AT_MAX_LEVERAGE - - INVALID_NEW_POSITION_LEVERAGE - INVALID_LARGE_POSITION_LEVERAGE - */ - return if (overMaxLeverage( - position, - ) - ) { - if (parser.asString(trade["type"]) == "MARKET") { - val increasingPosition = when (change) { - PositionChange.NEW, PositionChange.CROSSING, PositionChange.INCREASING -> true - else -> false - } - - error( - if (increasingPosition) "ERROR" else "WARNING", - "MARKET_ORDER_PRICE_IMPACT_AT_MAX_LEVERAGE", - if (increasingPosition) listOf("size.size") else null, - if (increasingPosition) "APP.TRADE.MODIFY_SIZE_FIELD" else null, - "ERRORS.TRADE_BOX_TITLE.MARKET_ORDER_PRICE_IMPACT_AT_MAX_LEVERAGE", - "ERRORS.TRADE_BOX.MARKET_ORDER_PRICE_IMPACT_AT_MAX_LEVERAGE", - ) - } else { - if (change == PositionChange.NEW) { - error( - "ERROR", - "INVALID_NEW_POSITION_LEVERAGE", - listOf("size.size"), - "APP.TRADE.MODIFY_SIZE_FIELD", - "ERRORS.TRADE_BOX_TITLE.INVALID_NEW_POSITION_LEVERAGE", - "ERRORS.TRADE_BOX.INVALID_NEW_POSITION_LEVERAGE", - ) - } else { - error( - "ERROR", - "INVALID_LARGE_POSITION_LEVERAGE", - listOf("size.size"), - "APP.TRADE.MODIFY_SIZE_FIELD", - "ERRORS.TRADE_BOX_TITLE.INVALID_LARGE_POSITION_LEVERAGE", - "ERRORS.TRADE_BOX.INVALID_LARGE_POSITION_LEVERAGE", - ) - } - } - } else { - if (parser.asString(trade["type"]) == "MARKET") { - val increasingPosition = when (change) { - PositionChange.NEW, PositionChange.CROSSING, PositionChange.INCREASING -> true - else -> false - } - - if (increasingPosition && orderOverMaxLeverage(position)) { - error( - "WARNING", - "MARKET_ORDER_CLOSE_TO_MAX_LEVERAGE", - listOf("size.size"), - "APP.TRADE.MODIFY_SIZE_FIELD", - "WARNINGS.TRADE_BOX_TITLE.MARKET_ORDER_CLOSE_TO_MAX_LEVERAGE", - "WARNINGS.TRADE_BOX.MARKET_ORDER_CLOSE_TO_MAX_LEVERAGE", - ) - } else { - null - } - } else { - null - } - } - } - - private fun overMaxLeverage( - position: Map, - ): Boolean { - val leverage = parser.asDouble(parser.value(position, "leverage.postOrder"))?.abs() - val adjustedImf = parser.asDouble(parser.value(position, "adjustedImf.current")) - return overLeverage(leverage, adjustedImf) - } - - private fun overLeverage(leverage: Double?, adjustedImf: Double?): Boolean { - return if (leverage != null && adjustedImf != null && adjustedImf > Numeric.double.ZERO) { - leverage > (Numeric.double.ONE / adjustedImf) || leverage < Numeric.double.ZERO - } else { - false - } - } - - private fun orderOverMaxLeverage( - position: Map, - ): Boolean { - val leverage = parser.asDouble(parser.value(position, "leverage.postOrder"))?.abs() - val adjustedImf = parser.asDouble(parser.value(position, "adjustedImf.postOrder")) - return overLeverage(leverage, adjustedImf) - } - private fun validatePositionSize( position: Map?, market: Map?, From 9ba2032ede7715cf30181d65ecb72b28dfdd49e5 Mon Sep 17 00:00:00 2001 From: aforaleka Date: Mon, 17 Jun 2024 15:10:01 -0400 Subject: [PATCH 2/3] remove error code lookups --- .../kotlin/exchange.dydx.abacus/validator/InputValidator.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt index ff5737975..fab57a4f8 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/validator/InputValidator.kt @@ -36,8 +36,6 @@ internal class InputValidator( "LIMIT_MUST_BELOW_TRIGGER_PRICE" to 1043, "PRICE_MUST_POSITIVE" to 1044, - "INVALID_LARGE_POSITION_LEVERAGE" to 1051, - "INVALID_NEW_POSITION_LEVERAGE" to 1052, "INVALID_NEW_ACCOUNT_MARGIN_USAGE" to 1053, "BUY_TRIGGER_TOO_CLOSE_TO_LIQUIDATION_PRICE" to 1060, @@ -57,7 +55,6 @@ internal class InputValidator( "WOULD_NOT_REDUCE_UNCHECK" to 1100, - "MARKET_ORDER_CLOSE_TO_MAX_LEVERAGE" to 1200, "MARKET_ORDER_WARNING_INDEX_PRICE_SLIPPAGE" to 1201, "MARKET_ORDER_WARNING_ORDERBOOK_SLIPPAGE" to 1202, "LIMIT_PRICE_TRIGGER_PRICE_SLIPPAGE_LOWER" to 1203, From 70f3ac6295b74f464838a85c0bc7c7b349ed65c7 Mon Sep 17 00:00:00 2001 From: mobile-build-bot-git Date: Mon, 17 Jun 2024 19:11:06 +0000 Subject: [PATCH 3/3] Bump version --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 004ad6312..af75de6de 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,7 +51,7 @@ allprojects { } group = "exchange.dydx.abacus" -version = "1.7.75" +version = "1.7.76" repositories { google()