@@ -24,18 +24,23 @@ type StandardIndicatorSet struct {
24
24
// Standard indicators
25
25
// interval -> window
26
26
iwbIndicators map [types.IntervalWindowBandWidth ]* indicator.BOLL
27
- iwIndicators map [types. IntervalWindow ]indicator.KLinePusher
27
+ iwIndicators map [indicatorKey ]indicator.KLinePusher
28
28
29
29
stream types.Stream
30
30
store * MarketDataStore
31
31
}
32
32
33
+ type indicatorKey struct {
34
+ iw types.IntervalWindow
35
+ id string
36
+ }
37
+
33
38
func NewStandardIndicatorSet (symbol string , stream types.Stream , store * MarketDataStore ) * StandardIndicatorSet {
34
39
return & StandardIndicatorSet {
35
40
Symbol : symbol ,
36
41
store : store ,
37
42
stream : stream ,
38
- iwIndicators : make (map [types. IntervalWindow ]indicator.KLinePusher ),
43
+ iwIndicators : make (map [indicatorKey ]indicator.KLinePusher ),
39
44
iwbIndicators : make (map [types.IntervalWindowBandWidth ]* indicator.BOLL ),
40
45
}
41
46
}
@@ -50,74 +55,77 @@ func (s *StandardIndicatorSet) initAndBind(inc indicator.KLinePusher, interval t
50
55
s .stream .OnKLineClosed (types .KLineWith (s .Symbol , interval , inc .PushK ))
51
56
}
52
57
53
- func (s * StandardIndicatorSet ) allocateSimpleIndicator (t indicator.KLinePusher , iw types.IntervalWindow ) indicator.KLinePusher {
54
- inc , ok := s .iwIndicators [iw ]
58
+ func (s * StandardIndicatorSet ) allocateSimpleIndicator (t indicator.KLinePusher , iw types.IntervalWindow , id string ) indicator.KLinePusher {
59
+ k := indicatorKey {
60
+ iw : iw ,
61
+ id : id ,
62
+ }
63
+ inc , ok := s .iwIndicators [k ]
55
64
if ok {
56
65
return inc
57
66
}
58
67
59
68
inc = t
60
69
s .initAndBind (inc , iw .Interval )
61
- s .iwIndicators [iw ] = inc
70
+ s .iwIndicators [k ] = inc
62
71
return t
63
72
}
64
73
65
74
// SMA is a helper function that returns the simple moving average indicator of the given interval and the window size.
66
75
func (s * StandardIndicatorSet ) SMA (iw types.IntervalWindow ) * indicator.SMA {
67
- inc := s .allocateSimpleIndicator (& indicator.SMA {IntervalWindow : iw }, iw )
76
+ inc := s .allocateSimpleIndicator (& indicator.SMA {IntervalWindow : iw }, iw , "sma" )
68
77
return inc .(* indicator.SMA )
69
78
}
70
79
71
80
// EWMA is a helper function that returns the exponential weighed moving average indicator of the given interval and the window size.
72
81
func (s * StandardIndicatorSet ) EWMA (iw types.IntervalWindow ) * indicator.EWMA {
73
- inc := s .allocateSimpleIndicator (& indicator.EWMA {IntervalWindow : iw }, iw )
82
+ inc := s .allocateSimpleIndicator (& indicator.EWMA {IntervalWindow : iw }, iw , "ewma" )
74
83
return inc .(* indicator.EWMA )
75
84
}
76
85
77
86
// VWMA
78
87
func (s * StandardIndicatorSet ) VWMA (iw types.IntervalWindow ) * indicator.VWMA {
79
- inc := s .allocateSimpleIndicator (& indicator.VWMA {IntervalWindow : iw }, iw )
88
+ inc := s .allocateSimpleIndicator (& indicator.VWMA {IntervalWindow : iw }, iw , "vwma" )
80
89
return inc .(* indicator.VWMA )
81
90
}
82
91
83
-
84
92
func (s * StandardIndicatorSet ) PivotHigh (iw types.IntervalWindow ) * indicator.PivotHigh {
85
- inc := s .allocateSimpleIndicator (& indicator.PivotHigh {IntervalWindow : iw }, iw )
93
+ inc := s .allocateSimpleIndicator (& indicator.PivotHigh {IntervalWindow : iw }, iw , "pivothigh" )
86
94
return inc .(* indicator.PivotHigh )
87
95
}
88
96
89
97
func (s * StandardIndicatorSet ) PivotLow (iw types.IntervalWindow ) * indicator.PivotLow {
90
- inc := s .allocateSimpleIndicator (& indicator.PivotLow {IntervalWindow : iw }, iw )
98
+ inc := s .allocateSimpleIndicator (& indicator.PivotLow {IntervalWindow : iw }, iw , "pivotlow" )
91
99
return inc .(* indicator.PivotLow )
92
100
}
93
101
94
102
func (s * StandardIndicatorSet ) ATR (iw types.IntervalWindow ) * indicator.ATR {
95
- inc := s .allocateSimpleIndicator (& indicator.ATR {IntervalWindow : iw }, iw )
103
+ inc := s .allocateSimpleIndicator (& indicator.ATR {IntervalWindow : iw }, iw , "atr" )
96
104
return inc .(* indicator.ATR )
97
105
}
98
106
99
107
func (s * StandardIndicatorSet ) ATRP (iw types.IntervalWindow ) * indicator.ATRP {
100
- inc := s .allocateSimpleIndicator (& indicator.ATRP {IntervalWindow : iw }, iw )
108
+ inc := s .allocateSimpleIndicator (& indicator.ATRP {IntervalWindow : iw }, iw , "atrp" )
101
109
return inc .(* indicator.ATRP )
102
110
}
103
111
104
112
func (s * StandardIndicatorSet ) EMV (iw types.IntervalWindow ) * indicator.EMV {
105
- inc := s .allocateSimpleIndicator (& indicator.EMV {IntervalWindow : iw }, iw )
113
+ inc := s .allocateSimpleIndicator (& indicator.EMV {IntervalWindow : iw }, iw , "emv" )
106
114
return inc .(* indicator.EMV )
107
115
}
108
116
109
117
func (s * StandardIndicatorSet ) CCI (iw types.IntervalWindow ) * indicator.CCI {
110
- inc := s .allocateSimpleIndicator (& indicator.CCI {IntervalWindow : iw }, iw )
118
+ inc := s .allocateSimpleIndicator (& indicator.CCI {IntervalWindow : iw }, iw , "cci" )
111
119
return inc .(* indicator.CCI )
112
120
}
113
121
114
122
func (s * StandardIndicatorSet ) HULL (iw types.IntervalWindow ) * indicator.HULL {
115
- inc := s .allocateSimpleIndicator (& indicator.HULL {IntervalWindow : iw }, iw )
123
+ inc := s .allocateSimpleIndicator (& indicator.HULL {IntervalWindow : iw }, iw , "hull" )
116
124
return inc .(* indicator.HULL )
117
125
}
118
126
119
127
func (s * StandardIndicatorSet ) STOCH (iw types.IntervalWindow ) * indicator.STOCH {
120
- inc := s .allocateSimpleIndicator (& indicator.STOCH {IntervalWindow : iw }, iw )
128
+ inc := s .allocateSimpleIndicator (& indicator.STOCH {IntervalWindow : iw }, iw , "stoch" )
121
129
return inc .(* indicator.STOCH )
122
130
}
123
131
0 commit comments