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:
tinkle-community
2025-12-29 22:16:48 +08:00
parent 4776fc37ce
commit 47bff87966
21 changed files with 3863 additions and 393 deletions

View File

@@ -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()