12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package sentio
- import (
- "cmp"
- "slices"
- )
- func CompareProbabilityStamps(a, b *Probability_Stamp) int {
- return cmp.Compare(a.Time.AsTime().Unix(), b.Time.AsTime().Unix())
- }
- func (x *Probability) First() (*Probability_Stamp, bool) {
- return x.Next(0)
- }
- func (x *Probability) Next(n int) (*Probability_Stamp, bool) {
- if x.Stamps == nil || len(x.Stamps) <= n {
- return nil, false
- }
- slices.SortFunc(x.Stamps, CompareProbabilityStamps)
- return x.Stamps[n], true
- }
- func IsAction(action Action, oneOf ...Action) bool {
- if oneOf == nil || len(oneOf) == 0 {
- return false
- }
- for i := range oneOf {
- if action == oneOf[i] {
- return true
- }
- }
- return false
- }
- func ActionToSide(action Action) Side {
- switch action {
- case Action_DOUBLE_SELL:
- return SHORT
- case Action_SELL:
- return SHORT
- case Action_BUY:
- return LONG
- case Action_DOUBLE_BUY:
- return LONG
- default:
- return BASE
- }
- }
|