-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
53 lines (46 loc) · 1.72 KB
/
errors.go
File metadata and controls
53 lines (46 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package exchanges
import (
"errors"
"fmt"
)
// ============================================================================
// Sentinel Errors — structured error handling for trading operations
// ============================================================================
var (
ErrInsufficientBalance = errors.New("insufficient balance")
ErrRateLimited = errors.New("rate limited")
ErrInvalidPrecision = errors.New("invalid precision")
ErrOrderNotFound = errors.New("order not found")
ErrSymbolNotFound = errors.New("symbol not found")
ErrMinNotional = errors.New("below minimum notional")
ErrMinQuantity = errors.New("below minimum quantity")
ErrAuthFailed = errors.New("authentication failed")
ErrNetworkTimeout = errors.New("network timeout")
ErrNotSupported = errors.New("not supported")
)
// ExchangeError wraps an exchange-specific error with a sentinel cause.
// Use errors.Is(err, adapter.ErrInsufficientBalance) for structured handling.
type ExchangeError struct {
Exchange string // Exchange name, e.g. "BINANCE"
Code string // Exchange-specific error code
Message string // Original error message from exchange
Err error // Sentinel error for errors.Is matching
}
func (e *ExchangeError) Error() string {
if e.Code != "" {
return fmt.Sprintf("[%s] %s: %s", e.Exchange, e.Code, e.Message)
}
return fmt.Sprintf("[%s] %s", e.Exchange, e.Message)
}
func (e *ExchangeError) Unwrap() error {
return e.Err
}
// NewExchangeError creates a new ExchangeError.
func NewExchangeError(exchange, code, message string, sentinel error) *ExchangeError {
return &ExchangeError{
Exchange: exchange,
Code: code,
Message: message,
Err: sentinel,
}
}