Skip to content

Conversation

@gemdev111
Copy link
Contributor

@gemdev111 gemdev111 commented Dec 17, 2025

  • Handle zero position size gracefully when setting up TP/SL before entering an amount
  • Add new OpenPositionItemViewModel to display position info during order setup
  • Remove currency swap action from deposit, withdraw, and perpetual amount inputs

closes #1493

Added assetId and symbol to AutocloseOpenData and updated its initializer and usage throughout the codebase. Introduced OpenPositionItemViewModel for displaying open position data in the UI. Refactored AutocloseScene and AutocloseSceneViewModel to use the new view model and improved handling of entry price display. Adjusted test kit and transfer logic to support the new data structure.
@gemdev111 gemdev111 self-assigned this Dec 17, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gemdev111, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant upgrade to the autoclose feature, empowering users with the choice between market and limit order execution for their autoclose strategies. The changes encompass the integration of this new preference into user settings, a refined user interface for displaying position information, and more resilient backend logic for profit/loss calculations. These updates provide a more flexible and informative autoclose experience, ensuring better control and transparency for users.

Highlights

  • User-Configurable Autoclose Order Type: Users can now choose between "Market" and "Limit" order types for autoclose functionality, with this preference being saved in settings. This is facilitated by new UI components in the preferences scene and updates to the underlying data models.
  • Enhanced Autoclose UI and Logic: The autoclose scene's display of position details has been refactored for clarity, and the underlying profit/loss calculation now robustly handles zero position sizes and uses Return on Equity (ROE) for visual feedback on PnL color.
  • Expanded Data Models: Key data structures (AutocloseOpenData, PerpetualConfirmData, TPSLOrderData) have been updated to support new fields like assetId, symbol, and the chosen autocloseOrderType, ensuring comprehensive data handling throughout the system, from UI to service layers.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature allowing users to select between 'limit' and 'market' for autoclose orders. This is achieved by adding a new user preference, which is then integrated throughout the relevant view models, services, and data structures. The settings screen has been updated with UI for this new preference, and the autoclose scene has been refactored for better support of both opening and modifying positions. The changes are well-structured and demonstrate a good separation of concerns. I have identified a couple of minor issues that should be addressed.

Comment on lines 61 to 65
public var pnlColor: Color {
guard let price else { return Colors.secondaryText }
let pnl = estimator.calculatePnL(price: price)
return PriceChangeColor.color(for: pnl)
let roe = estimator.calculateROE(price: price)
return PriceChangeColor.color(for: roe)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic for determining pnlColor has been changed to use calculateROE instead of calculatePnL. While the sign of ROE and PnL should be the same, making this functionally equivalent for color determination, it's worth noting that expectedPnL also calculates ROE. This change is good for consistency, but you could consider calculating roe once and using it for both expectedPnL and pnlColor to avoid redundant calculations, especially if these properties are accessed frequently.

Comment on lines 9 to 21
private let title: String
private let options: [PerpetualOrderTypeViewModel]
@Binding var selection: PerpetualOrderType

public init(
title: String,
options: [PerpetualOrderTypeViewModel],
selection: Binding<PerpetualOrderType>
) {
self.title = title
self.options = options
_selection = selection
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The title property and initializer parameter are unused within this view, as the navigation title is hardcoded to Localized.Perpetual.autoClose. To avoid confusion and remove dead code, you can remove the title property and the corresponding parameter from the initializer. The call site in PreferencesScene will also need to be updated accordingly.

    private let options: [PerpetualOrderTypeViewModel]
    @Binding var selection: PerpetualOrderType

    public init(
        options: [PerpetualOrderTypeViewModel],
        selection: Binding<PerpetualOrderType>
    ) {
        self.options = options
        _selection = selection
    }

Comment on lines 15 to 21
// TODO: - Localize?
public var title: String {
switch type {
case .market: "Market"
case .limit: "Limit"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

As pointed out by the TODO comment, the strings for order types are currently hardcoded. It's important to move these to your localization files to ensure the app can be fully translated. I've suggested using a Localized enum, assuming a structure similar to other parts of the app.

    public var title: String {
        switch type {
        case .market: Localized.Perpetual.OrderType.market
        case .limit: Localized.Perpetual.OrderType.limit
        }
    }

Eliminated the ability to set a default autoclose order type in user preferences and removed related UI components and view models. All autoclose operations now default to the 'market' order type. Cleaned up associated code in Perpetuals, Settings, Preferences, and PrimitivesComponents modules.
OpenPositionItemViewModel now displays an empty string for zero size values instead of formatting them. In AmountInputConfig, the .perpetual scene type no longer uses the swap action style, aligning its behavior with other staking-related types.
Refines the actionStyle property to only return a CurrencyInputActionStyle for the .transfer sceneType. All other scene types, including .deposit and .withdraw, now return nil.
@gemdev111 gemdev111 marked this pull request as ready for review December 18, 2025 16:24
Simplified the logic for entryPriceTitle by making it always return the localized entry price string, removing the conditional based on type. Updated AutocloseScene to match the new non-optional entryPriceTitle usage.
@gemdev111 gemdev111 requested a review from gemcoder21 December 19, 2025 17:36
Eliminated the autocloseOrderType property and related parameters from PerpetualConfirmData, TPSLOrderData, and associated builders, factories, and extension methods. This simplifies the data structures and function signatures, reflecting that autocloseOrderType is no longer required for these operations.
@gemdev111 gemdev111 merged commit f9128e7 into main Dec 19, 2025
1 check passed
@gemdev111 gemdev111 deleted the 1493-autoclose-limit-market branch December 19, 2025 17:45
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.

Add ability to change auto close order type (market / limit)

3 participants