Skip to content

feat(perps): support partial position reduction - #6725

Open
SeniorZhai wants to merge 3 commits into
masterfrom
feat/perps-reduce-position
Open

SeniorZhai wants to merge 3 commits into
masterfrom
feat/perps-reduce-position

Conversation

@SeniorZhai

Copy link
Copy Markdown
Member

No description provided.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T08:05:21.525056Z 198e4de New commits
🔒 Security Review ✅ Completed 2026-10-08T07:56:31.188331Z 198e4de New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e534988f15

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

perpsPositionDao.deleteById(positionId)
}
Timber.d("Perps order closed: $positionId")
refreshSinglePosition(positionId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain cache cleanup for full closes

When an existing full-close caller passes quantity == null, this replaces the previous cache deletion with refreshSinglePosition(). If the detail endpoint returns null or NOT_FOUND after the position has closed—both cases are explicitly ignored by refreshSinglePosition at lines 833–838—the cached row remains in an open state, and the revised order synchronization only invokes the same refresh. Consequently, observeOpenPositions continues showing the closed position until a separate wallet-wide refresh happens; keep the deletion behavior for full closes or remove/close the row when detail confirms it is gone.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72d4e9b1d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +169 to +171
onToggleMode = {
input = (if (isPercentage) amount else percentage)?.let { formatMarginAdjustmentInput(it, !isPercentage) }.orEmpty()
isPercentage = !isPercentage

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the reduction amount when switching input modes

Switching modes rewrites the input through formatMarginAdjustmentInput, which truncates percentages to an integer and dollar amounts to two decimals. For example, a $199.90 reduction on a $200 position becomes 99% after toggling to percentage mode, silently changing the submitted quantity to $198; small positions can similarly become $0 when toggled to amount mode. Keep the calculated quantity or an unrounded canonical amount across display-mode changes.

Useful? React with 👍 / 👎.

Comment on lines +531 to +535
if (isReducePosition) {
parentFragmentManager.setFragmentResult(
RESULT_POSITION_REDUCED,
Bundle().apply { putString(RESULT_POSITION_ID, positionId) },
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Dismiss the reduction flow on every successful submission

The reduction result is emitted only from the Done button handler. Since the successful confirmation dialog remains cancelable with the system Back action, a user can dismiss it after Step.Done without notifying the parent reduction sheet; that sheet remains open and can submit another reduction against the remaining position. Emit the result when submission succeeds, or also propagate it when a completed dialog is dismissed.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 198e4de513

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (input.length > 40 || input.any { it !in '0'..'9' && it != '.' }) return null
val quantity = input.toBigDecimalOrNull() ?: return null
val current = currentQuantity.toBigDecimalOrNull()?.abs() ?: return null
return quantity.takeIf { it > BigDecimal.ZERO && it <= current }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject stale reductions that become full closes

When a user selects a partial reduction and the position subsequently shrinks to exactly that requested quantity—for example, because another order or device updated it—the authoritative pre-submit check still passes because equality is allowed here. The request then closes the entire remaining position instead of reporting perps_reduce_quantity_changed; preserve the original position size or full-close intent and only permit equality when the user explicitly selected a 100% reduction.

Useful? React with 👍 / 👎.

Comment on lines +44 to +45
@SerializedName("quantity")
val quantity: String? = null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Label partial close orders as reductions

When quantity is smaller than the open position, the resulting order is still ingested as PerpsOrder.TYPE_CLOSE, while ClosedActivityItem and PositionDetailPage unconditionally label every such order as “Closed Long” or “Closed Short.” Consequently, after a successful partial reduction the activity list and order detail claim that the position was closed even though it remains open; carry or derive partial-close metadata and render a reduction-specific label.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant