@@ -28,17 +28,17 @@ const (
28
28
var supportedAccountTypes = []WalletAccountType {Funding , Uta , Spot , Contract , Inverse }
29
29
30
30
var (
31
- errUnsupportedAccountType = errors .New ("unsupported account type" )
32
- errCurrencyCodesEqual = errors .New ("from and to currency codes cannot be equal" )
33
- errRequestCoinInvalid = errors .New ("request coin must match from coin if provided" )
34
- errQuoteTxIDEmpty = errors .New ("quoteTxID cannot be empty" )
31
+ errUnsupportedAccountType = errors .New ("unsupported account type" )
32
+ errCurrencyCodesEqual = errors .New ("from and to currency codes cannot be equal" )
33
+ errRequestCoinInvalid = errors .New ("request coin must match from coin if provided" )
34
+ errQuoteTransactionIDEmpty = errors .New ("quoteTransactionID cannot be empty" )
35
35
)
36
36
37
37
// WalletAccountType represents the different types of wallet accounts
38
38
type WalletAccountType string
39
39
40
- // Coin represents a coin that can be converted
41
- type Coin struct {
40
+ // CoinResponse represents a coin that can be converted
41
+ type CoinResponse struct {
42
42
Coin currency.Code `json:"coin"`
43
43
FullName string `json:"fullName"`
44
44
Icon string `json:"icon"`
@@ -62,7 +62,7 @@ type Coin struct {
62
62
}
63
63
64
64
// GetConvertCoinList returns a list of coins you can convert to/from
65
- func (e * Exchange ) GetConvertCoinList (ctx context.Context , accountType WalletAccountType , coin currency.Code , isCoinToBuy bool ) ([]Coin , error ) {
65
+ func (e * Exchange ) GetConvertCoinList (ctx context.Context , accountType WalletAccountType , coin currency.Code , isCoinToBuy bool ) ([]CoinResponse , error ) {
66
66
if ! slices .Contains (supportedAccountTypes , accountType ) {
67
67
return nil , fmt .Errorf ("%w: %q" , errUnsupportedAccountType , accountType )
68
68
}
@@ -81,14 +81,14 @@ func (e *Exchange) GetConvertCoinList(ctx context.Context, accountType WalletAcc
81
81
}
82
82
83
83
var resp struct {
84
- List []Coin `json:"coins"`
84
+ List []CoinResponse `json:"coins"`
85
85
}
86
86
87
87
return resp .List , e .SendAuthHTTPRequestV5 (ctx , exchange .RestSpot , http .MethodGet , "/v5/asset/exchange/query-coin-list" , params , nil , & resp , defaultEPL )
88
88
}
89
89
90
- // RequestAQuoteParams holds the parameters for requesting a quote
91
- type RequestAQuoteParams struct {
90
+ // RequestAQuoteRequest holds the parameters for requesting a quote
91
+ type RequestAQuoteRequest struct {
92
92
// Required fields
93
93
AccountType WalletAccountType
94
94
From currency.Code // Convert from coin (coin to sell)
@@ -105,21 +105,21 @@ type RequestAQuoteParams struct {
105
105
106
106
// RequestAQuoteResponse represents a response for a request a quote
107
107
type RequestAQuoteResponse struct {
108
- QuoteTxID string `json:"quoteTxId"` // Quote transaction ID. It is system generated, and it is used to confirm quote and query the result of transaction
109
- ExchangeRate types.Number `json:"exchangeRate"`
110
- FromCoin currency.Code `json:"fromCoin"`
111
- FromCoinType string `json:"fromCoinType"`
112
- ToCoin currency.Code `json:"toCoin"`
113
- ToCoinType string `json:"toCoinType"`
114
- FromAmount types.Number `json:"fromAmount"`
115
- ToAmount types.Number `json:"toAmount"`
116
- ExpiredTime types.Time `json:"expiredTime"` // The expiry time for this quote (15 seconds)
117
- RequestID string `json:"requestId"`
118
- ExtTaxAndFee json.RawMessage `json:"extTaxAndFee"` // Compliance-related field. Currently returns an empty array, which may be used in the future
108
+ QuoteTransactionID string `json:"quoteTxId"` // Quote transaction ID. It is system generated, and it is used to confirm quote and query the result of transaction
109
+ ExchangeRate types.Number `json:"exchangeRate"`
110
+ FromCoin currency.Code `json:"fromCoin"`
111
+ FromCoinType string `json:"fromCoinType"`
112
+ ToCoin currency.Code `json:"toCoin"`
113
+ ToCoinType string `json:"toCoinType"`
114
+ FromAmount types.Number `json:"fromAmount"`
115
+ ToAmount types.Number `json:"toAmount"`
116
+ ExpiredTime types.Time `json:"expiredTime"` // The expiry time for this quote (15 seconds)
117
+ RequestID string `json:"requestId"`
118
+ ExtTaxAndFee json.RawMessage `json:"extTaxAndFee"` // Compliance-related field. Currently returns an empty array, which may be used in the future
119
119
}
120
120
121
121
// RequestAQuote requests a conversion quote between two coins with the specified parameters.
122
- func (e * Exchange ) RequestAQuote (ctx context.Context , params * RequestAQuoteParams ) (* RequestAQuoteResponse , error ) {
122
+ func (e * Exchange ) RequestAQuote (ctx context.Context , params * RequestAQuoteRequest ) (* RequestAQuoteResponse , error ) {
123
123
if ! slices .Contains (supportedAccountTypes , params .AccountType ) {
124
124
return nil , fmt .Errorf ("%w: %q" , errUnsupportedAccountType , params .AccountType )
125
125
}
@@ -147,50 +147,30 @@ func (e *Exchange) RequestAQuote(ctx context.Context, params *RequestAQuoteParam
147
147
return nil , fmt .Errorf ("amount %w" , order .ErrAmountIsInvalid )
148
148
}
149
149
150
- payload := & struct {
151
- AccountType string `json:"accountType"`
152
- From string `json:"fromCoin"`
153
- To string `json:"toCoin"`
154
- Amount string `json:"requestAmount"`
155
- RequestCoin string `json:"requestCoin"`
156
- FromCoinType string `json:"fromCoinType,omitempty"`
157
- ToCoinType string `json:"toCoinType,omitempty"`
158
- ParamType string `json:"paramType,omitempty"`
159
- ParamValue string `json:"paramValue,omitempty"`
160
- RequestID string `json:"requestId,omitempty"`
161
- }{
162
- AccountType : string (params .AccountType ),
163
- From : params .From .Upper ().String (),
164
- To : params .To .Upper ().String (),
165
- Amount : strconv .FormatFloat (params .Amount , 'f' , - 1 , 64 ),
166
- RequestCoin : params .RequestCoin .Upper ().String (),
167
- FromCoinType : params .FromCoinType ,
168
- ToCoinType : params .ToCoinType ,
169
- ParamType : params .ParamType ,
170
- ParamValue : params .ParamValue ,
171
- RequestID : params .RequestID ,
172
- }
150
+ params .From = params .From .Upper ()
151
+ params .To = params .To .Upper ()
152
+ params .RequestCoin = params .RequestCoin .Upper ()
173
153
174
154
var resp * RequestAQuoteResponse
175
- return resp , e .SendAuthHTTPRequestV5 (ctx , exchange .RestSpot , http .MethodPost , "/v5/asset/exchange/quote-apply" , nil , payload , & resp , defaultEPL )
155
+ return resp , e .SendAuthHTTPRequestV5 (ctx , exchange .RestSpot , http .MethodPost , "/v5/asset/exchange/quote-apply" , nil , params , & resp , defaultEPL )
176
156
}
177
157
178
158
// ConfirmAQuoteResponse represents a response for confirming a quote
179
159
type ConfirmAQuoteResponse struct {
180
- ExchangeStatus string `json:"exchangeStatus"`
181
- QuoteTxID string `json:"quoteTxId"`
160
+ ExchangeStatus string `json:"exchangeStatus"`
161
+ QuoteTransactionID string `json:"quoteTxId"`
182
162
}
183
163
184
164
// ConfirmAQuote confirms a quote transaction and executes the conversion
185
- func (e * Exchange ) ConfirmAQuote (ctx context.Context , quoteTxID string ) (* ConfirmAQuoteResponse , error ) {
186
- if quoteTxID == "" {
187
- return nil , errQuoteTxIDEmpty
165
+ func (e * Exchange ) ConfirmAQuote (ctx context.Context , quoteTransactionID string ) (* ConfirmAQuoteResponse , error ) {
166
+ if quoteTransactionID == "" {
167
+ return nil , errQuoteTransactionIDEmpty
188
168
}
189
169
190
170
payload := struct {
191
- QuoteTxID string `json:"quoteTxId"`
171
+ QuoteTransactionID string `json:"quoteTxId"`
192
172
}{
193
- QuoteTxID : quoteTxID ,
173
+ QuoteTransactionID : quoteTransactionID ,
194
174
}
195
175
196
176
var resp * ConfirmAQuoteResponse
@@ -200,33 +180,33 @@ func (e *Exchange) ConfirmAQuote(ctx context.Context, quoteTxID string) (*Confir
200
180
201
181
// ConvertStatusResponse represents the response for a conversion status query
202
182
type ConvertStatusResponse struct {
203
- AccountType WalletAccountType `json:"accountType"`
204
- ExchangeTxID string `json:"exchangeTxId"`
205
- UserID string `json:"userId"`
206
- FromCoin currency.Code `json:"fromCoin"`
207
- FromCoinType string `json:"fromCoinType"`
208
- FromAmount types.Number `json:"fromAmount"`
209
- ToCoin currency.Code `json:"toCoin"`
210
- ToCoinType string `json:"toCoinType"`
211
- ToAmount types.Number `json:"toAmount"`
212
- ExchangeStatus string `json:"exchangeStatus"`
213
- ExtInfo json.RawMessage `json:"extInfo"` // Reserved field, ignored for now
214
- ConvertRate types.Number `json:"convertRate"`
215
- CreatedAt types.Time `json:"createdAt"`
183
+ AccountType WalletAccountType `json:"accountType"`
184
+ ExchangeTransactionID string `json:"exchangeTxId"`
185
+ UserID string `json:"userId"`
186
+ FromCoin currency.Code `json:"fromCoin"`
187
+ FromCoinType string `json:"fromCoinType"`
188
+ FromAmount types.Number `json:"fromAmount"`
189
+ ToCoin currency.Code `json:"toCoin"`
190
+ ToCoinType string `json:"toCoinType"`
191
+ ToAmount types.Number `json:"toAmount"`
192
+ ExchangeStatus string `json:"exchangeStatus"`
193
+ ExtInfo json.RawMessage `json:"extInfo"` // Reserved field, ignored for now
194
+ ConvertRate types.Number `json:"convertRate"`
195
+ CreatedAt types.Time `json:"createdAt"`
216
196
}
217
197
218
198
// GetConvertStatus retrieves the status of a conversion transaction
219
- func (e * Exchange ) GetConvertStatus (ctx context.Context , accountType WalletAccountType , quoteTxID string ) (* ConvertStatusResponse , error ) {
199
+ func (e * Exchange ) GetConvertStatus (ctx context.Context , accountType WalletAccountType , quoteTransactionID string ) (* ConvertStatusResponse , error ) {
220
200
if ! slices .Contains (supportedAccountTypes , accountType ) {
221
201
return nil , fmt .Errorf ("%w: %q" , errUnsupportedAccountType , accountType )
222
202
}
223
203
224
- if quoteTxID == "" {
225
- return nil , errQuoteTxIDEmpty
204
+ if quoteTransactionID == "" {
205
+ return nil , errQuoteTransactionIDEmpty
226
206
}
227
207
228
208
params := url.Values {}
229
- params .Set ("quoteTxId" , quoteTxID )
209
+ params .Set ("quoteTxId" , quoteTransactionID )
230
210
params .Set ("accountType" , string (accountType ))
231
211
232
212
var resp struct {
@@ -237,19 +217,19 @@ func (e *Exchange) GetConvertStatus(ctx context.Context, accountType WalletAccou
237
217
238
218
// ConvertHistoryResponse represents a response for conversion history
239
219
type ConvertHistoryResponse struct {
240
- AccountType WalletAccountType `json:"accountType"`
241
- ExchangeTxID string `json:"exchangeTxId"`
242
- UserID string `json:"userId"`
243
- FromCoin currency.Code `json:"fromCoin"`
244
- FromCoinType string `json:"fromCoinType"`
245
- FromAmount types.Number `json:"fromAmount"`
246
- ToCoin currency.Code `json:"toCoin"`
247
- ToCoinType string `json:"toCoinType"`
248
- ToAmount types.Number `json:"toAmount"`
249
- ExchangeStatus string `json:"exchangeStatus"`
250
- ExtInfo json.RawMessage `json:"extInfo"`
251
- ConvertRate types.Number `json:"convertRate"`
252
- CreatedAt types.Time `json:"createdAt"`
220
+ AccountType WalletAccountType `json:"accountType"`
221
+ ExchangeTransactionID string `json:"exchangeTxId"`
222
+ UserID string `json:"userId"`
223
+ FromCoin currency.Code `json:"fromCoin"`
224
+ FromCoinType string `json:"fromCoinType"`
225
+ FromAmount types.Number `json:"fromAmount"`
226
+ ToCoin currency.Code `json:"toCoin"`
227
+ ToCoinType string `json:"toCoinType"`
228
+ ToAmount types.Number `json:"toAmount"`
229
+ ExchangeStatus string `json:"exchangeStatus"`
230
+ ExtInfo json.RawMessage `json:"extInfo"`
231
+ ConvertRate types.Number `json:"convertRate"`
232
+ CreatedAt types.Time `json:"createdAt"`
253
233
}
254
234
255
235
// GetConvertHistory retrieves the conversion history for the specified account types.
0 commit comments