feat: improve order sync and add xyz dex trigger orders

- Add incremental sync for Binance trades using COMMISSION detection and fromId
- Add stop loss and take profit order support for xyz dex assets
- Add pagination for current positions and position history in UI
- Fix chart market type auto-selection based on exchange
This commit is contained in:
tinkle-community
2025-12-30 14:32:51 +08:00
parent 0408bf1f5f
commit ad04994d75
7 changed files with 983 additions and 283 deletions

View File

@@ -543,6 +543,33 @@ func (s *OrderStore) GetDuplicateFillsCount() (int, error) {
return count, err
}
// GetMaxTradeIDsByExchange returns max trade ID for each symbol for a given exchange
// Used for incremental sync - only fetch trades with ID > maxTradeID
func (s *OrderStore) GetMaxTradeIDsByExchange(exchangeID string) (map[string]int64, error) {
rows, err := s.db.Query(`
SELECT symbol, MAX(CAST(exchange_trade_id AS INTEGER)) as max_trade_id
FROM trader_fills
WHERE exchange_id = ? AND exchange_trade_id != ''
GROUP BY symbol
`, exchangeID)
if err != nil {
return nil, fmt.Errorf("failed to query max trade IDs: %w", err)
}
defer rows.Close()
result := make(map[string]int64)
for rows.Next() {
var symbol string
var maxID int64
if err := rows.Scan(&symbol, &maxID); err != nil {
continue
}
result[symbol] = maxID
}
return result, nil
}
// formatTimePtr formats time.Time to RFC3339 string, returns NULL for zero time
func formatTimePtr(t time.Time) interface{} {
if t.IsZero() {