2022-01-14 18:52:46 +00:00
|
|
|
package bbgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-06-06 09:34:39 +00:00
|
|
|
"fmt"
|
2022-01-14 18:52:46 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-09-10 19:13:10 +00:00
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
2022-01-14 18:52:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type myStrategy struct {
|
2022-09-10 19:13:10 +00:00
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
Position *types.Position
|
2022-01-14 18:52:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-10 19:13:10 +00:00
|
|
|
func (m *myStrategy) ID() string {
|
2022-01-14 18:52:46 +00:00
|
|
|
return "mystrategy"
|
|
|
|
}
|
|
|
|
|
2022-09-10 19:13:10 +00:00
|
|
|
func (m *myStrategy) InstanceID() string {
|
2022-06-06 09:34:39 +00:00
|
|
|
return fmt.Sprintf("%s:%s", m.ID(), m.Symbol)
|
|
|
|
}
|
|
|
|
|
2022-09-10 19:13:10 +00:00
|
|
|
func (m *myStrategy) ClosePosition(ctx context.Context, percentage fixedpoint.Value) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-14 18:52:46 +00:00
|
|
|
func (m *myStrategy) Run(ctx context.Context, orderExecutor OrderExecutor, session *ExchangeSession) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_getStrategySignature(t *testing.T) {
|
|
|
|
signature, err := getStrategySignature(&myStrategy{
|
|
|
|
Symbol: "BTCUSDT",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2022-06-07 02:45:55 +00:00
|
|
|
assert.Equal(t, "mystrategy:BTCUSDT", signature)
|
2022-01-14 18:52:46 +00:00
|
|
|
}
|
2022-09-10 19:13:10 +00:00
|
|
|
|
|
|
|
func Test_hasTypeField(t *testing.T) {
|
|
|
|
s := &myStrategy{
|
|
|
|
Symbol: "BTCUSDT",
|
|
|
|
}
|
|
|
|
ok := hasTypeField(s, &types.Position{})
|
|
|
|
assert.True(t, ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_testInterface(t *testing.T) {
|
|
|
|
s := &myStrategy{
|
|
|
|
Symbol: "BTCUSDT",
|
|
|
|
}
|
|
|
|
|
|
|
|
ok := testInterface(s, (*PositionCloser)(nil))
|
|
|
|
assert.True(t, ok)
|
|
|
|
}
|