From 41163346ea482c22da3d3d39f0d1e7a4779cc7c8 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 11 May 2021 23:42:49 +0800 Subject: [PATCH] fix withdraw state check --- examples/max-withdraw/main.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/examples/max-withdraw/main.go b/examples/max-withdraw/main.go index 21f64b64c..46449e81a 100644 --- a/examples/max-withdraw/main.go +++ b/examples/max-withdraw/main.go @@ -11,20 +11,24 @@ import ( ) func waitWithdrawalsComplete(ctx context.Context, client *maxapi.RestClient, currency string, limit int) error { - withdrawals, err := client.WithdrawalService.NewGetWithdrawalHistoryRequest(). - Currency(currency). - Limit(limit). - Do(ctx) - if err != nil { - return err - } - var lastState string for { + withdrawals, err := client.WithdrawalService.NewGetWithdrawalHistoryRequest(). + Currency(currency). + Limit(limit). + Do(ctx) + if err != nil { + return err + } + pending := false for _, withdrawal := range withdrawals { - if withdrawal.State != lastState { + if lastState == "" { + log.Printf("-> %s", withdrawal.State) + } else if withdrawal.State != lastState { log.Printf("%s -> %s", lastState, withdrawal.State) + log.Printf("withdrawal %s %s: %s", withdrawal.Amount, withdrawal.Currency, withdrawal.State) + log.Printf("\t%+v", withdrawal) } lastState = withdrawal.State @@ -32,13 +36,14 @@ func waitWithdrawalsComplete(ctx context.Context, client *maxapi.RestClient, cur case "submitting", "submitted", "pending", "processing", "approved": pending = true - log.Printf("there is a pending withdrawal request, waiting\n") - log.Printf("%+v", withdrawal) + log.Printf("there is a pending withdrawal request, waiting...") break - case "sent": + case "sent", "confirmed": continue + case "rejected": + } } @@ -84,7 +89,7 @@ func main() { maxRest := maxapi.NewRestClient(maxapi.ProductionAPIURL) maxRest.Auth(key, secret) - if err := waitWithdrawalsComplete(ctx, maxRest, currency, 1) ; err != nil { + if err := waitWithdrawalsComplete(ctx, maxRest, currency, 1); err != nil { log.Fatal(err) } log.Printf("all withdrawals are sent, sending new withdrawal request...") @@ -113,7 +118,7 @@ func main() { } } - if err := waitWithdrawalsComplete(ctx, maxRest, currency, 1) ; err != nil { + if err := waitWithdrawalsComplete(ctx, maxRest, currency, 1); err != nil { log.Fatal(err) } log.Printf("all withdrawals are sent")