-
Notifications
You must be signed in to change notification settings - Fork 156
Description
Description
The equity calculation exhibits an issue when a trader first opens a position in an isolated market. After the initial position is created, the equity value is incorrectly calculated, appearing to follow the formula: equity = correct equity + netTransfers
. This effectively double-counts the initial deposit amount, resulting in an artificially inflated equity value.
Evidence / Analysis
The screenshot below demonstrates this issue:
{"equity":"418.555266","totalPnl":"-81.455606","netTransfers":"0","createdAt":"2025-07-15T20:01:24.676Z","blockHeight":"50154096","blockTime":"2025-07-15T20:01:23.458Z"},{"equity":"443.69946600000003","totalPnl":"-56.311406","netTransfers":"0","createdAt":"2025-07-15T19:01:13.011Z","blockHeight":"50150362","blockTime":"2025-07-15T19:01:11.936Z"},{"equity":"504.03918200000004","totalPnl":"4.02831","netTransfers":"0","createdAt":"2025-07-15T18:01:03.386Z","blockHeight":"50146700","blockTime":"2025-07-15T18:00:59.888Z"},{"equity":"485.790606","totalPnl":"-14.220266","netTransfers":"-500.007432","createdAt":"2025-07-15T17:00:12.862Z","blockHeight":"50142918","blockTime":"2025-07-15T17:00:10.306Z"},{"equity":"960.761606","totalPnl":"-39.256698","netTransfers":"500.007432","createdAt":"2025-07-15T16:10:33.550Z","blockHeight":"50139883","blockTime":"2025-07-15T16:10:32.109Z"},{"equity":"500.010872","totalPnl":"0.000000","netTransfers":"0.000000","createdAt":"2025-07-15T15:00:16.131Z","blockHeight":"50135655","blockTime":"2025-07-15T15:00:14.097Z"},
As shown in the image, the equity value is temporarily inflated beyond what it should be. The API response data confirms this behavior, with the equity value returning to normal approximately one hour after the position is opened.
Reference API endpoint:
https://indexer.dydx.trade/v4/historical-pnl/parentSubaccountNumber?address=dydx14lqzrhg5ceaz4ulex6sfdf2rc3cem9kwc7ps3k&parentSubaccountNumber=0
Expected Behavior
- The equity value should be calculated correctly after opening a position in an isolated market.
- The calculation should properly account for the deposit without double-counting it in the equity value.
Impact
- Traders receive misleading information about their account value during the critical first hour after opening a position.
- This could lead to incorrect risk assessment and potentially poor trading decisions based on inaccurate equity figures.
- Affects user trust in the platform's accounting and reporting systems.
Recommendation
- Investigate the equity calculation logic specifically for the case of first-time position opening in isolated markets.
- Fix the calculation to prevent double-counting of the initial deposit amount.
- Consider implementing a validation check to ensure equity values remain consistent across all account states.