order_list_criteria.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. Nested *bool
  15. }
  16. func (criteria OrderListCriteria) Values() map[string]string {
  17. var values = make(map[string]string)
  18. if criteria.Limit < 1 {
  19. criteria.Limit = 500
  20. }
  21. if criteria.Symbols != nil && len(criteria.Symbols) > 0 {
  22. values["symbols"] = strings.Join(criteria.Symbols, ",")
  23. }
  24. if criteria.After == nil {
  25. t := time.Now().Add(-time.Hour * 24).Round(time.Hour * 24)
  26. criteria.After = &t
  27. }
  28. if criteria.Until != nil && !criteria.Until.IsZero() {
  29. values["until"] = criteria.Until.In(time.UTC).Format(time.RFC3339)
  30. }
  31. if criteria.Side != nil {
  32. values["side"] = *criteria.Side
  33. }
  34. if criteria.Nested != nil {
  35. values["nested"] = fmt.Sprintf("%v", *criteria.Nested)
  36. } else {
  37. values["nested"] = "true"
  38. }
  39. values["status"] = "all"
  40. values["limit"] = fmt.Sprintf("%d", criteria.Limit)
  41. values["after"] = criteria.After.In(time.UTC).Format(time.RFC3339)
  42. values["direction"] = "asc"
  43. return values
  44. }