mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-10 22:36:58 +08:00
fix: prevent Agent from fabricating position/balance data
- Add strict data truthfulness rules to system prompt (CN + EN) - Positions MUST come from get_positions tool only - Balance MUST come from get_balance tool only - Looking up a stock price != user owns it - Fix unused variable warnings in hyperliquid trader
This commit is contained in:
@@ -46,26 +46,20 @@ func (t *HyperliquidTrader) GetBalance() (map[string]interface{}, error) {
|
||||
var accountValue, totalMarginUsed float64
|
||||
var summaryType string
|
||||
var summary interface{}
|
||||
_, _ = summaryType, summary
|
||||
|
||||
if t.isCrossMargin {
|
||||
// Cross margin mode: use CrossMarginSummary
|
||||
accountValue, _ = strconv.ParseFloat(accountState.CrossMarginSummary.AccountValue, 64)
|
||||
totalMarginUsed, _ = strconv.ParseFloat(accountState.CrossMarginSummary.TotalMarginUsed, 64)
|
||||
summaryType = "CrossMarginSummary (cross margin)"
|
||||
summary = accountState.CrossMarginSummary
|
||||
} else {
|
||||
// Isolated margin mode: use MarginSummary
|
||||
accountValue, _ = strconv.ParseFloat(accountState.MarginSummary.AccountValue, 64)
|
||||
totalMarginUsed, _ = strconv.ParseFloat(accountState.MarginSummary.TotalMarginUsed, 64)
|
||||
summaryType = "MarginSummary (isolated margin)"
|
||||
summary = accountState.MarginSummary
|
||||
}
|
||||
|
||||
// Debug: Print complete summary structure returned by API
|
||||
summaryJSON, _ := json.MarshalIndent(summary, " ", " ")
|
||||
logger.Infof("🔍 [DEBUG] Hyperliquid API %s complete data:", summaryType)
|
||||
logger.Infof("%s", string(summaryJSON))
|
||||
|
||||
// Critical fix: Accumulate actual unrealized PnL from all positions
|
||||
totalUnrealizedPnl := 0.0
|
||||
for _, assetPos := range accountState.AssetPositions {
|
||||
@@ -159,7 +153,7 @@ func (t *HyperliquidTrader) GetBalance() (map[string]interface{}, error) {
|
||||
walletBalanceWithoutUnrealized,
|
||||
totalUnrealizedPnl)
|
||||
logger.Infof(" • Perpetuals available balance: %.2f USDC", availableBalance)
|
||||
logger.Infof(" • Margin used: %.2f USDC", totalMarginUsed)
|
||||
logger.Infof(" • Margin used: %.2f USDC (source: %s)", totalMarginUsed, summaryType)
|
||||
logger.Infof(" • xyz dex equity: %.2f USDC (wallet %.2f + unrealized %.2f)",
|
||||
xyzAccountValue,
|
||||
xyzWalletBalance,
|
||||
|
||||
Reference in New Issue
Block a user