-
Notifications
You must be signed in to change notification settings - Fork 6
/
error.go
100 lines (84 loc) · 2.35 KB
/
error.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package bybitv5
import (
"fmt"
"golang.org/x/exp/slices"
)
// Error (https://bybit-exchange.github.io/docs/v5/error)
type Error struct {
Code int
Text string
}
func (o *Error) Std() error {
if o.Empty() {
return nil
} else {
return o
}
}
func (o *Error) Empty() bool {
return o.Code == 0
}
func (o *Error) Error() string {
return fmt.Sprintf("code[%d]: %s", o.Code, o.Text)
}
func (o *Error) RequestParameterError() bool {
return o.Code == 10001
}
func (o *Error) ApiKeyInvalid() bool {
codes := []int{
10003, // API key is invalid
10004, // Error sign, please check your signature generation algorithm.
10005, // Permission denied, please check your API key permissions
}
return slices.Contains(codes, o.Code)
}
func (o *Error) ApiKeyExpired() bool {
return o.Code == 33004
}
func (o *Error) TooManyVisits() bool {
return o.Code == 10006
}
func (o *Error) UnmatchedIp() bool {
return o.Code == 10010
}
func (o *Error) SymbolIsNotWhitelisted() bool {
return o.Code == 10029
}
func (o *Error) KycNeeded() bool {
codes := []int{
10024, // Compliance rules triggered
131004, // KYC needed
}
return slices.Contains(codes, o.Code)
}
func (o *Error) Timeout() bool {
codes := []int{
10000, // Server Timeout
10016, // Request timeout
170007, // Timeout waiting for response from backend server.
170146, // Order creation timeout
170147, // Order cancellation timeout
177002, // Timeout
}
return slices.Contains(codes, o.Code)
}
func (o *Error) InsufficientBalance() bool {
codes := []int{
110004, // Wallet balance is insufficient
110007, // Available balance is insufficient
110012, // Insufficient available balance
110045, // Wallet balance is insufficient
110051, // The user's available balance cannot cover the lowest price of the current market
110052, // Your available balance is insufficient to set the price
110053, // The user's available balance cannot cover the current market price and upper limit price
170033, // margin Insufficient account balance
170131, // Balance insufficient
175003, // Insufficient available balance. Please make a deposit and try again.
175006, // Insufficient available balance. Please make a deposit and try again.
176015, // Insufficient available balance
}
return slices.Contains(codes, o.Code)
}
func (o *Error) OrderLinkedIdIsDuplicate() bool {
return o.Code == 110072
}