order_action.go 545 B

1234567891011121314151617181920212223242526272829303132333435
  1. package sentio
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type OrderAction string
  7. func (oa OrderAction) String() string {
  8. return string(oa)
  9. }
  10. const (
  11. OrderBuy OrderAction = "BUY"
  12. OrderSell OrderAction = "SELL"
  13. )
  14. func ParseOrderAction(s string) (OrderAction, error) {
  15. s = strings.TrimSpace(s)
  16. s = strings.ToUpper(s)
  17. switch s {
  18. case "BUY":
  19. return OrderBuy, nil
  20. case "B":
  21. return OrderBuy, nil
  22. case "SELL":
  23. return OrderSell, nil
  24. case "S":
  25. return OrderSell, nil
  26. }
  27. return "undefined", fmt.Errorf("ParseOrderAction: undefined `%s`", s)
  28. }