Skip to content

Commit

Permalink
Add new error type
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn committed Aug 26, 2024
1 parent 27c03f9 commit 1bfd019
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ internal class TradeOrderInputValidator(
}

private fun isolatedMarginMinSize(subaccount: Map<String, Any>?, trade: Map<String, Any>, restricted: Boolean): Map<String, Any>? {
/*
TODO: make a new error type
*/
val marginMode = parser.asString(trade.get("marginMode"))?.let {
MarginMode.invoke(it)
}
Expand All @@ -139,7 +136,7 @@ internal class TradeOrderInputValidator(
if (orderEquity < isolatedLimitOrderMinimumEquity) {
return createTradeBoxWarningOrErrorDeprecated(
errorLevel = if (restricted) "WARNING" else "ERROR",
errorCode = "MARKET_ORDER_NOT_ENOUGH_LIQUIDITY", // TODO: make a new error type
errorCode = "ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM",
fields = listOf("size.size"),
actionStringKey = "APP.TRADE.MODIFY_SIZE_FIELD",
)
Expand All @@ -152,9 +149,6 @@ internal class TradeOrderInputValidator(
}

private fun validateIsolatedMarginMinSize(subaccount: InternalSubaccountState, trade: InternalTradeInputState): ValidationError? {
/*
TODO: make a new error type
*/
return when (trade.marginMode) {
MarginMode.Isolated -> {
val currentFreeCollateral = subaccount.calculated.get(CalculationPeriod.current)?.freeCollateral ?: return null
Expand All @@ -164,7 +158,7 @@ internal class TradeOrderInputValidator(
if (orderEquity < isolatedLimitOrderMinimumEquity) {
return createTradeBoxWarningOrError(
errorLevel = if (accountRestricted()) ErrorType.warning else ErrorType.error,
errorCode = "MARKET_ORDER_NOT_ENOUGH_LIQUIDITY", // TODO: make a new error type
errorCode = "ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM",
fields = listOf("size.size"),
actionStringKey = "APP.TRADE.MODIFY_SIZE_FIELD",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ open class V4TradeInputTests : V4BaseTests() {
perp.trade("0.01", TradeInputField.size, 0)
}, null)

// TODO update with new error
test(
{
perp.trade("1500", TradeInputField.limitPrice, 0)
Expand All @@ -476,16 +475,16 @@ open class V4TradeInputTests : V4BaseTests() {
"errors": [
{
"type": "ERROR",
"code": "MARKET_ORDER_NOT_ENOUGH_LIQUIDITY",
"code": "ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM",
"fields": [
"size.size"
],
"resources": {
"title": {
"stringKey": "ERRORS.TRADE_BOX_TITLE.MARKET_ORDER_NOT_ENOUGH_LIQUIDITY"
"stringKey": "ERRORS.TRADE_BOX_TITLE.ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM"
},
"text": {
"stringKey": "ERRORS.TRADE_BOX.MARKET_ORDER_NOT_ENOUGH_LIQUIDITY"
"stringKey": "ERRORS.TRADE_BOX.ISOLATED_MARGIN_LIMIT_ORDER_BELOW_MINIMUM"
},
"action": {
"stringKey": "APP.TRADE.MODIFY_SIZE_FIELD"
Expand Down

0 comments on commit 1bfd019

Please sign in to comment.