Skip to content

Commit

Permalink
fix: improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Primexz committed May 10, 2024
1 parent ae46f87 commit d6929af
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions kraken/kraken_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,41 +106,39 @@ func BuyBtc(_retry_do_not_use int) {
}

order, ok := orderInfo[transactionId]
if !ok {
if ok {
orderStatus := order.Status
log.Info("current order status:", orderStatus)

if orderStatus == "closed" {
log.Info("Order successfully executed")
break // don't return to send notification and log
}

if orderStatus == "canceled" && order.Reason == "User requested" {
log.Info("Order canceled by user")
return
}

if orderStatus == "canceled" {
log.Info("Unknown reason for order cancelation.")
return
}

if orderStatus == "canceled" && order.Reason == "Post only order" {
log.Info("Order canceled by kraken due to post only order, retrying with new order")
BuyBtc(_retry_do_not_use + 1)
return
}

if orderStatus == "expired" {
log.Info("Order expired, retrying with new order")
BuyBtc(_retry_do_not_use + 1)
return
}
} else {
log.Error("Failed to query order status")
return
}

orderStatus := order.Status
log.Info("current order status:", orderStatus)

if orderStatus == "closed" {
log.Info("Order successfully executed")
break // don't return to send notification and log
}

if orderStatus == "canceled" && order.Reason == "User requested" {
log.Info("Order canceled by user")
return
}

if orderStatus == "canceled" {
log.Info("Unknown reason for order cancelation.")
return
}

if orderStatus == "canceled" && order.Reason == "Post only order" {
log.Info("Order canceled by kraken due to post only order, retrying with new order")
BuyBtc(_retry_do_not_use + 1)
return
}

if orderStatus == "expired" {
log.Info("Order expired, retrying with new order")
BuyBtc(_retry_do_not_use + 1)
return
}

//wait on pending, open
time.Sleep(5 * time.Second)
}
Expand Down

0 comments on commit d6929af

Please sign in to comment.