marginRatio(OKX) · Issue #30610 · ccxt/ccxt · GitHub
Skip to content

marginRatio(OKX) #30610

Open
Open

Description

@GUO-RUI-China

Operating System

windows

Programming Language

No response

CCXT Version

​4.5.78

Description

ccxt_okx_marginRatio_issue.md

Activity

  1. carlotestor commented on Sep 24, 2026

    @carlotestor
    Collaborator

    Thanks for the detailed write-up — confirmed on current master.

    In ts/src/okx.ts parsePosition, the cross branch uses imr + upl as collateral, but the isolated branch uses only margin (collateralString = this.safeString (position, 'margin')). So for isolated positions collateral ignores unrealized PnL, and marginRatio = mmr / collateral stays around mmr / margin instead of rising toward liquidation. The unified position structure defines collateral as affected by PnL, so the isolated branch should be margin + upl, matching cross. With your numbers that gives 2.697 / 60.634 ≈ 0.0445.

    OKX's native mgnRatio is a different metric (equity / (mmr + fee), higher is safer), with the inverse direction of ccxt's marginRatio, so it stays available as position['info']['mgnRatio'] and isn't mapped into the unified field.

    I'll open a minimal fix for the isolated branch shortly.

  2. carlotestor commented on Sep 24, 2026

    @carlotestor
    Collaborator

    Opened #30611 with a minimal fix.

  3. GUO-RUI-China commented on Sep 24, 2026

    @GUO-RUI-China
    Author

    if you have any question,feel free to connect with me

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions