withdraw.go 606 B

123456789101112131415161718192021222324252627282930
  1. package asset
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/shopspring/decimal"
  5. )
  6. func (s *Server) Withdraw(ctx *gin.Context) {
  7. c := s.FromContext(ctx)
  8. type request struct {
  9. Amount decimal.Decimal `json:"amount"`
  10. Symbol string `json:"symbol"`
  11. }
  12. req := new(request)
  13. if err := c.ShouldBindJSON(&req); err != nil {
  14. c.Resp(err.Error())
  15. return
  16. }
  17. user, err := s.WithdrawCheck(c.UserId(), req.Symbol, req.Amount)
  18. if err != nil {
  19. c.Resp(err.Error())
  20. return
  21. }
  22. err = s.WithdrawApply(user, req.Symbol, req.Amount)
  23. if err != nil {
  24. c.Resp(err.Error())
  25. return
  26. }
  27. c.Resp(nil)
  28. }