mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-17 17:34:39 +08:00
feat: add xyz dex balance calculation, market data providers, and UI improvements
- Fix xyz dex balance calculation (use marginSummary for isolated margin) - Add Alpaca provider for US stocks market data - Add TwelveData provider for forex & metals market data - Add Hyperliquid kline provider - Centralize API keys in config system - Add builder fee for order routing - Improve chart UI with compact design - Fix position history fee display precision - Add comprehensive balance calculation tests
This commit is contained in:
@@ -675,6 +675,7 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) {
|
||||
totalWalletBalance := 0.0
|
||||
totalUnrealizedProfit := 0.0
|
||||
availableBalance := 0.0
|
||||
totalEquity := 0.0
|
||||
|
||||
if wallet, ok := balance["totalWalletBalance"].(float64); ok {
|
||||
totalWalletBalance = wallet
|
||||
@@ -686,8 +687,13 @@ func (at *AutoTrader) buildTradingContext() (*decision.Context, error) {
|
||||
availableBalance = avail
|
||||
}
|
||||
|
||||
// Total Equity = Wallet balance + Unrealized profit
|
||||
totalEquity := totalWalletBalance + totalUnrealizedProfit
|
||||
// Use totalEquity directly if provided by trader (more accurate)
|
||||
if eq, ok := balance["totalEquity"].(float64); ok && eq > 0 {
|
||||
totalEquity = eq
|
||||
} else {
|
||||
// Fallback: Total Equity = Wallet balance + Unrealized profit
|
||||
totalEquity = totalWalletBalance + totalUnrealizedProfit
|
||||
}
|
||||
|
||||
// 2. Get position information
|
||||
positions, err := at.trader.GetPositions()
|
||||
@@ -1473,6 +1479,7 @@ func (at *AutoTrader) GetAccountInfo() (map[string]interface{}, error) {
|
||||
totalWalletBalance := 0.0
|
||||
totalUnrealizedProfit := 0.0
|
||||
availableBalance := 0.0
|
||||
totalEquity := 0.0
|
||||
|
||||
if wallet, ok := balance["totalWalletBalance"].(float64); ok {
|
||||
totalWalletBalance = wallet
|
||||
@@ -1484,8 +1491,13 @@ func (at *AutoTrader) GetAccountInfo() (map[string]interface{}, error) {
|
||||
availableBalance = avail
|
||||
}
|
||||
|
||||
// Total Equity = Wallet balance + Unrealized profit
|
||||
totalEquity := totalWalletBalance + totalUnrealizedProfit
|
||||
// Use totalEquity directly if provided by trader (more accurate)
|
||||
if eq, ok := balance["totalEquity"].(float64); ok && eq > 0 {
|
||||
totalEquity = eq
|
||||
} else {
|
||||
// Fallback: Total Equity = Wallet balance + Unrealized profit
|
||||
totalEquity = totalWalletBalance + totalUnrealizedProfit
|
||||
}
|
||||
|
||||
// Get positions to calculate total margin
|
||||
positions, err := at.trader.GetPositions()
|
||||
|
||||
Reference in New Issue
Block a user