Skip to content

Conversation

c9s
Copy link
Owner

@c9s c9s commented Jun 14, 2025

No description provided.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines the OKX margin level calculation and adds related fields and metrics for margin ratio.

  • Standardizes margin tolerance comment.
  • Introduces new notional‐USD breakdown fields in OKX API response.
  • Updates OKX exchange logic to compute margin level from borrow notional and registers margin ratio metrics.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/util/margin_tolerance.go Simplified outdated comment on liquidation formula.
pkg/types/account.go Added MarginTolerance, reintroduced MarginRatio, and updated documentation.
pkg/metrics/account.go Added AccountMarginRatioMetrics and combined registration.
pkg/exchange/okex/okexapi/get_account_balance_request.go Added detailed NotionalUsd* and BorrowFroz fields.
pkg/exchange/okex/exchange.go Reworked QueryAccount to set MarginLevel and MarginTolerance based on borrow notional.
pkg/bbgo/session.go Guarded margin level/ratio metric emission when values are positive.
Comments suppressed due to low confidence (1)

pkg/types/account.go:52

  • [nitpick] Consider expanding this comment to include units (e.g., percent) and explain how MarginRatio differs from MarginLevel to aid future readers.
// MarginRatio = Adjusted equity / (Maintenance margin + Liquidation fees)

if accounts[0].NotionalUsdForBorrow.Sign() > 0 {
account.MarginLevel = accounts[0].TotalEquityInUSD.Div(accounts[0].NotionalUsdForBorrow)
} else {
account.MarginLevel = fixedpoint.NewFromFloat(999.9)
Copy link
Preview

Copilot AI Jun 14, 2025

Choose a reason for hiding this comment

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

[nitpick] When NotionalUsdForBorrow is zero, defaulting to a high margin level may mask issues; consider setting the margin level to zero or propagating an error to avoid misleading metrics.

Suggested change
account.MarginLevel = fixedpoint.NewFromFloat(999.9)
account.MarginLevel = fixedpoint.NewFromFloat(0.0)
log.Warnf("NotionalUsdForBorrow is zero; setting MarginLevel to 0.0 to avoid misleading metrics")

Copilot uses AI. Check for mistakes.

@c9s c9s force-pushed the c9s/okx/fix-margin-level-calc branch from 132278a to 9f6cd0b Compare June 15, 2025 09:11
@c9s c9s enabled auto-merge June 15, 2025 09:12
@c9s c9s merged commit c2fd430 into main Jun 15, 2025
3 of 4 checks passed
@c9s c9s deleted the c9s/okx/fix-margin-level-calc branch June 15, 2025 09:32
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.

3 participants