strategy.go 583 B

123456789101112131415161718192021222324252627282930313233343536
  1. package sentio
  2. import (
  3. "cmp"
  4. "time"
  5. )
  6. type Strategy interface {
  7. Name() string
  8. Model() string
  9. MarketId() string
  10. PositionSymbols() map[Side]string
  11. Interval() uint8
  12. Cooldown() time.Duration
  13. Handle(market Market, proba float64) ([]StrategyOrder, error)
  14. }
  15. type StrategyOrder struct {
  16. Symbol string `yaml:"symbol"`
  17. Action OrderAction `yaml:"action"`
  18. Ratio float64 `yaml:"ratio"`
  19. }
  20. func CompareStrategyOrders(a, b StrategyOrder) int {
  21. if a.Action == b.Action {
  22. return cmp.Compare(b.Ratio, a.Ratio)
  23. }
  24. if OrderSell == a.Action {
  25. return -1
  26. }
  27. return 1
  28. }