order_list_criteria.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package sentio
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. )
  7. type OrderListCriteria struct {
  8. Status string
  9. Limit uint
  10. Symbols []string
  11. After *time.Time
  12. Until *time.Time
  13. Side *string
  14. }
  15. func (criteria OrderListCriteria) Values() map[string]string {
  16. var values = make(map[string]string)
  17. if criteria.Limit < 1 {
  18. criteria.Limit = 500
  19. }
  20. if criteria.Symbols != nil && len(criteria.Symbols) > 0 {
  21. values["symbols"] = strings.Join(criteria.Symbols, ",")
  22. }
  23. if criteria.After == nil {
  24. t := time.Now().Add(-time.Hour * 24).Round(time.Hour * 24)
  25. criteria.After = &t
  26. }
  27. if criteria.Until != nil && !criteria.Until.IsZero() {
  28. values["until"] = criteria.Until.In(time.UTC).Format(time.RFC3339)
  29. }
  30. if criteria.Side != nil {
  31. values["side"] = *criteria.Side
  32. }
  33. values["status"] = "all"
  34. values["nested"] = "true"
  35. values["limit"] = fmt.Sprintf("%d", criteria.Limit)
  36. values["after"] = criteria.After.In(time.UTC).Format(time.RFC3339)
  37. values["direction"] = "asc"
  38. return values
  39. }