Skip to content

Commit 640dfe9

Browse files
committed
Update
1 parent beb382a commit 640dfe9

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

strategy.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,63 @@ func (s *SpotStrategyBase) Name() string {
156156
return s.name
157157
}
158158

159+
// 组合策略,期现等
160+
// CStrategyBase Strategy base class
161+
type CStrategyBase struct {
162+
self interface{}
163+
name string
164+
tradeMode TradeMode
165+
Exchanges []Exchange
166+
SpotExchanges []SpotExchange
167+
}
168+
169+
// SetSelf 设置 self 对象
170+
func (s *CStrategyBase) SetSelf(self Strategy) error {
171+
s.self = self.(interface{})
172+
return nil
173+
}
174+
175+
// Setup Setups the exchanges
176+
func (s *CStrategyBase) Setup(mode TradeMode, exchanges ...interface{}) error { // Exchange
177+
if len(exchanges) == 0 {
178+
return fmt.Errorf("no exchanges")
179+
}
180+
s.tradeMode = mode
181+
for _, v := range exchanges {
182+
if ex, ok := v.(Exchange); ok {
183+
s.Exchanges = append(s.Exchanges, ex)
184+
continue
185+
}
186+
187+
if ex, ok := v.(SpotExchange); ok {
188+
s.SpotExchanges = append(s.SpotExchanges, ex)
189+
}
190+
}
191+
return nil
192+
}
193+
194+
// SetOptions Sets the options for the strategy
195+
func (s *CStrategyBase) SetOptions(options map[string]interface{}) error {
196+
return setOptions(s.self, options)
197+
}
198+
199+
// GetOptions Returns the options of strategy
200+
func (s *CStrategyBase) GetOptions() (optionMap map[string]*StrategyOption) {
201+
return getOptions(s.self)
202+
}
203+
204+
func (s *CStrategyBase) TradeMode() TradeMode {
205+
return s.tradeMode
206+
}
207+
208+
func (s *CStrategyBase) SetName(name string) {
209+
s.name = name
210+
}
211+
212+
func (s *CStrategyBase) Name() string {
213+
return s.name
214+
}
215+
159216
// SetOptions Sets the options for the strategy
160217
func setOptions(s interface{}, options map[string]interface{}) error {
161218
if len(options) == 0 {

0 commit comments

Comments
 (0)