Skip to content

Commit

Permalink
fix withdraw state check
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed May 11, 2021
1 parent 4d24a96 commit 4116334
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions examples/max-withdraw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,39 @@ 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

switch withdrawal.State {
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":

}

}
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 4116334

Please sign in to comment.