mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #678 from andycheng123/fix/interact
interact: fix missing make()
This commit is contained in:
commit
037f2949bd
|
@ -54,6 +54,7 @@ func getStrategySignatures(exchangeStrategies map[string]SingleExchangeStrategy)
|
|||
|
||||
func filterStrategyByInterface(checkInterface interface{}, exchangeStrategies map[string]SingleExchangeStrategy) (strategies map[string]SingleExchangeStrategy, found bool) {
|
||||
found = false
|
||||
strategies = make(map[string]SingleExchangeStrategy)
|
||||
rt := reflect.TypeOf(checkInterface).Elem()
|
||||
for signature, strategy := range exchangeStrategies {
|
||||
if ok := reflect.TypeOf(strategy).Implements(rt); ok {
|
||||
|
@ -404,20 +405,21 @@ func (it *CoreInteraction) Initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// getStrategySignature returns strategy instance unique signature
|
||||
func getStrategySignature(strategy SingleExchangeStrategy) (string, error) {
|
||||
// Returns instance ID
|
||||
var signature = callID(strategy)
|
||||
if signature != "" {
|
||||
return signature, nil
|
||||
}
|
||||
|
||||
// Use reflect to build instance signature
|
||||
rv := reflect.ValueOf(strategy).Elem()
|
||||
if rv.Kind() != reflect.Struct {
|
||||
return "", fmt.Errorf("strategy %T instance is not a struct", strategy)
|
||||
}
|
||||
|
||||
var signature = path.Base(rv.Type().PkgPath())
|
||||
|
||||
var id = strategy.ID()
|
||||
|
||||
if !strings.EqualFold(id, signature) {
|
||||
signature += "." + strings.ToLower(id)
|
||||
}
|
||||
|
||||
signature = path.Base(rv.Type().PkgPath())
|
||||
for i := 0; i < rv.NumField(); i++ {
|
||||
field := rv.Field(i)
|
||||
fieldName := rv.Type().Field(i).Name
|
||||
|
|
|
@ -2,6 +2,7 @@ package bbgo
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -15,6 +16,10 @@ func (m myStrategy) ID() string {
|
|||
return "mystrategy"
|
||||
}
|
||||
|
||||
func (m myStrategy) InstanceID() string {
|
||||
return fmt.Sprintf("%s:%s", m.ID(), m.Symbol)
|
||||
}
|
||||
|
||||
func (m *myStrategy) Run(ctx context.Context, orderExecutor OrderExecutor, session *ExchangeSession) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -24,5 +29,5 @@ func Test_getStrategySignature(t *testing.T) {
|
|||
Symbol: "BTCUSDT",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "bbgo.mystrategy.BTCUSDT", signature)
|
||||
assert.Equal(t, "mystrategy:BTCUSDT", signature)
|
||||
}
|
||||
|
|
|
@ -189,6 +189,10 @@ func (s *Strategy) ID() string {
|
|||
return ID
|
||||
}
|
||||
|
||||
func (s *Strategy) InstanceID() string {
|
||||
return fmt.Sprintf("%s:%s", ID, s.Symbol)
|
||||
}
|
||||
|
||||
func (s *Strategy) Validate() error {
|
||||
if s.Quantity.IsZero() && s.ScaleQuantity == nil {
|
||||
return fmt.Errorf("quantity or scaleQuantity can not be zero")
|
||||
|
|
Loading…
Reference in New Issue
Block a user