tif.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package sentio
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // TimeInForce Specifies how long the order remains in effect. Absence of this field is interpreted as DAY.
  7. // See more at https://www.onixs.biz/fix-dictionary/4.2/tagNum_59.html
  8. type TimeInForce int
  9. var tifs = map[TimeInForce]string{
  10. TIFDay: "DAY",
  11. TIFGoodTillCancel: "GTC",
  12. TIFOpenPriceGuarantee: "OPG",
  13. TIFImmediateOrCancel: "IOC",
  14. TIFFillOrKill: "FOK",
  15. TIFGoodTillCrossing: "GTX",
  16. TIFGoodTillDate: "GTD",
  17. }
  18. func (tif TimeInForce) String() string {
  19. t, ok := tifs[tif]
  20. if !ok {
  21. return "undefined"
  22. }
  23. return t
  24. }
  25. func ParseTimeInForce(s string) (TimeInForce, error) {
  26. s = strings.TrimSpace(s)
  27. s = strings.ToUpper(s)
  28. for t, l := range tifs {
  29. if s == l {
  30. return t, nil
  31. }
  32. }
  33. return -1, fmt.Errorf("`tif.Parse`: undefined TimeInForce `%s`", s)
  34. }
  35. const (
  36. TIFDay TimeInForce = 0
  37. TIFGoodTillCancel TimeInForce = 1
  38. TIFOpenPriceGuarantee TimeInForce = 2
  39. TIFImmediateOrCancel TimeInForce = 3
  40. TIFFillOrKill TimeInForce = 4
  41. TIFGoodTillCrossing TimeInForce = 5
  42. TIFGoodTillDate TimeInForce = 6
  43. )