Skip to content

Commit e9ab58d

Browse files
committed
🔧 fix(max): update withdrawal handling to use v3 API
1 parent 0beccc0 commit e9ab58d

File tree

9 files changed

+910
-41
lines changed

9 files changed

+910
-41
lines changed

pkg/exchange/max/convert.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,24 +341,24 @@ func convertWebSocketOrderUpdate(u max.OrderUpdate) (*types.Order, error) {
341341
}, nil
342342
}
343343

344-
func convertWithdrawStatusV3(status max.WithdrawStatus) types.WithdrawStatus {
345-
switch status {
344+
func convertWithdrawStatusV3(state v3.WithdrawState) types.WithdrawStatus {
345+
switch state {
346346

347-
case max.WithdrawStatusPending:
347+
case v3.WithdrawStateProcessing:
348348
return types.WithdrawStatusSent
349349

350-
case max.WithdrawStatusOK:
350+
case v3.WithdrawStateDone:
351351
return types.WithdrawStatusCompleted
352352

353-
case max.WithdrawStatusFailed:
353+
case v3.WithdrawStateFailed:
354354
return types.WithdrawStatusFailed
355355

356-
case max.WithdrawStatusCancelled:
356+
case v3.WithdrawStateCanceled:
357357
return types.WithdrawStatusCancelled
358358

359359
}
360360

361-
return types.WithdrawStatus(status)
361+
return types.WithdrawStatus(state)
362362
}
363363

364364
func convertWithdrawStatusV2(state max.WithdrawState) types.WithdrawStatus {

pkg/exchange/max/exchange.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,15 @@ func (e *Exchange) Withdraw(
530530
) error {
531531
asset = toLocalCurrency(asset)
532532

533-
addresses, err := e.client.WithdrawalService.NewGetWithdrawalAddressesRequest().
533+
addresses, err := e.v3client.NewGetWithdrawalAddressesRequest().
534534
Currency(asset).
535535
Do(ctx)
536536

537537
if err != nil {
538538
return err
539539
}
540540

541-
var whitelistAddress maxapi.WithdrawalAddress
541+
var whitelistAddress v3.WithdrawalAddress
542542
for _, a := range addresses {
543543
if a.Address == address {
544544
whitelistAddress = a
@@ -554,7 +554,7 @@ func (e *Exchange) Withdraw(
554554
return errors.New("address UUID can not be empty")
555555
}
556556

557-
response, err := e.client.WithdrawalService.NewWithdrawalRequest().
557+
response, err := e.v3client.NewWithdrawalRequest().
558558
Currency(asset).
559559
Amount(amount.Float64()).
560560
AddressUUID(whitelistAddress.UUID).
@@ -892,7 +892,7 @@ func (e *Exchange) QueryWithdrawHistory(
892892
}
893893

894894
log.Infof("querying withdraw %s: %s <=> %s", asset, startTime, endTime)
895-
req := e.client.NewGetWithdrawalHistoryRequest()
895+
req := e.v3client.NewGetWithdrawalHistoryRequest()
896896
if len(asset) > 0 {
897897
req.Currency(toLocalCurrency(asset))
898898
}
@@ -917,7 +917,7 @@ func (e *Exchange) QueryWithdrawHistory(
917917
continue
918918
}
919919

920-
status := convertWithdrawStatusV2(d.State)
920+
status := convertWithdrawStatusV3(d.State)
921921

922922
txIDs[d.TxID] = struct{}{}
923923
withdraw := types.Withdraw{

pkg/exchange/max/maxapi/account.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,3 @@ type GetWithdrawHistoryRequest struct {
122122
// limit's default = 50
123123
limit *int `param:"limit"`
124124
}
125-
126-
func (c *RestClient) NewGetWithdrawalHistoryRequest() *GetWithdrawHistoryRequest {
127-
return &GetWithdrawHistoryRequest{
128-
client: c,
129-
}
130-
}

pkg/exchange/max/maxapi/restapi.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ type RestClient struct {
120120

121121
SubAccount string
122122

123-
RewardService *RewardService
124-
WithdrawalService *WithdrawalService
123+
RewardService *RewardService
125124

126125
ApiKeyRotator *apikey.RoundTripBalancer
127126

@@ -155,7 +154,6 @@ func NewRestClient(baseURL string) *RestClient {
155154
}
156155

157156
client.RewardService = &RewardService{client}
158-
client.WithdrawalService = &WithdrawalService{client}
159157

160158
if v, ok := envvar.Bool("MAX_ENABLE_API_KEY_ROTATION"); v && ok {
161159
loader := apikey.NewEnvKeyLoader("MAX_API_", "", "KEY", "SECRET")

pkg/exchange/max/maxapi/v3/get_withdrawal_addresses_request_requestgen.go

Lines changed: 250 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)