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

@@ -65,10 +65,39 @@ export function CoinSourceEditor({
{ value: 'mixed', icon: Database, color: '#60a5fa' },
] as const
// xyz dex assets (stocks, forex, commodities) - should NOT get USDT suffix
const xyzDexAssets = new Set([
// Stocks
'TSLA', 'NVDA', 'AAPL', 'MSFT', 'META', 'AMZN', 'GOOGL', 'AMD', 'COIN', 'NFLX',
'PLTR', 'HOOD', 'INTC', 'MSTR', 'TSM', 'ORCL', 'MU', 'RIVN', 'COST', 'LLY',
'CRCL', 'SKHX', 'SNDK',
// Forex
'EUR', 'JPY',
// Commodities
'GOLD', 'SILVER',
// Index
'XYZ100',
])
const isXyzDexAsset = (symbol: string): boolean => {
const base = symbol.toUpperCase().replace(/^XYZ:/, '').replace(/USDT$|USD$|-USDC$/, '')
return xyzDexAssets.has(base)
}
const handleAddCoin = () => {
if (!newCoin.trim()) return
const symbol = newCoin.toUpperCase().trim()
const formattedSymbol = symbol.endsWith('USDT') ? symbol : `${symbol}USDT`
// For xyz dex assets (stocks, forex, commodities), use xyz: prefix without USDT
let formattedSymbol: string
if (isXyzDexAsset(symbol)) {
// Remove xyz: prefix (case-insensitive) and any USD suffixes
const base = symbol.replace(/^xyz:/i, '').replace(/USDT$|USD$|-USDC$/i, '')
formattedSymbol = `xyz:${base}`
} else {
formattedSymbol = symbol.endsWith('USDT') ? symbol : `${symbol}USDT`
}
const currentCoins = config.static_coins || []
if (!currentCoins.includes(formattedSymbol)) {
onChange({