From 4de5b0bc9b2bcdb85d17ec05a7041de636cae409 Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 5 Jul 2022 16:10:55 +0800 Subject: [PATCH 1/4] add TrailingStop2 --- pkg/bbgo/exit_trailing_stop.go | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pkg/bbgo/exit_trailing_stop.go diff --git a/pkg/bbgo/exit_trailing_stop.go b/pkg/bbgo/exit_trailing_stop.go new file mode 100644 index 000000000..769d7cda8 --- /dev/null +++ b/pkg/bbgo/exit_trailing_stop.go @@ -0,0 +1,69 @@ +package bbgo + +import ( + "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" +) + +type TrailingStop2 struct { + Symbol string + + // CallbackRate is the callback rate from the previous high price + CallbackRate fixedpoint.Value `json:"callbackRate,omitempty"` + + // ClosePosition is a percentage of the position to be closed + ClosePosition fixedpoint.Value `json:"closePosition,omitempty"` + + // MinProfit is the percentage of the minimum profit ratio. + // Stop order will be activated only when the price reaches above this threshold. + MinProfit fixedpoint.Value `json:"minProfit,omitempty"` + + // Interval is the time resolution to update the stop order + // KLine per Interval will be used for updating the stop order + Interval types.Interval `json:"interval,omitempty"` + + // private fields + session *ExchangeSession + orderExecutor *GeneralOrderExecutor +} + +func (s *TrailingStop2) Subscribe(session *ExchangeSession) { + // use 1m kline to handle roi stop + session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m}) +} + +func (s *TrailingStop2) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) { + s.session = session + s.orderExecutor = orderExecutor + + position := orderExecutor.Position() + session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) { + s.checkStopPrice(kline.Close, position) + })) + + if !IsBackTesting { + session.MarketDataStream.OnMarketTrade(func(trade types.Trade) { + if trade.Symbol != position.Symbol { + return + } + + s.checkStopPrice(trade.Price, position) + }) + } +} + +func (s *TrailingStop2) checkStopPrice(closePrice fixedpoint.Value, position *types.Position) { + if position.IsClosed() || position.IsDust(closePrice) { + return + } + + /* + roi := position.ROI(closePrice) + if roi.Compare(s.CallbackRate.Neg()) < 0 { + // stop loss + Notify("[TrailingStop2] %s stop loss triggered by ROI %s/%s, price: %f", position.Symbol, roi.Percentage(), s.Percentage.Neg().Percentage(), closePrice.Float64()) + _ = s.orderExecutor.ClosePosition(context.Background(), fixedpoint.One, "TrailingStop2") + return + } + */ +} From f329af2c6b6e2977ddea1225dd3ee547c70b5c6f Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 6 Jul 2022 01:31:12 +0800 Subject: [PATCH 2/4] generate mocks for the exchange interface Signed-off-by: c9s --- go.mod | 3 + go.sum | 7 + pkg/types/exchange.go | 1 + pkg/types/mocks/mock_exchange.go | 745 +++++++++++++++++++++++++++++++ 4 files changed, 756 insertions(+) create mode 100644 pkg/types/mocks/mock_exchange.go diff --git a/go.mod b/go.mod index d1ce9dbf6..34bd47ce8 100644 --- a/go.mod +++ b/go.mod @@ -75,6 +75,7 @@ require ( github.com/go-test/deep v1.0.6 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect + github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect @@ -116,11 +117,13 @@ require ( go.opentelemetry.io/otel/trace v0.19.0 // indirect go.uber.org/atomic v1.9.0 // indirect golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect + golang.org/x/mod v0.5.1 // indirect golang.org/x/net v0.0.0-20220403103023-749bd193bc2b // indirect golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/tools v0.1.9 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/genproto v0.0.0-20220405205423-9d709892a2bf // indirect gopkg.in/ini.v1 v1.62.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 7d562cc24..96f942c4d 100644 --- a/go.sum +++ b/go.sum @@ -194,7 +194,10 @@ github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFU github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc= github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= +github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= +github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -523,6 +526,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs= github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= @@ -599,6 +603,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -780,6 +786,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= diff --git a/pkg/types/exchange.go b/pkg/types/exchange.go index 5bff2689c..39ced8d87 100644 --- a/pkg/types/exchange.go +++ b/pkg/types/exchange.go @@ -74,6 +74,7 @@ func ValidExchangeName(a string) (ExchangeName, error) { return "", fmt.Errorf("invalid exchange name: %s", a) } +//go:generate mockgen -destination=mocks/mock_exchange.go -package=mocks -source=exchange.go Exchange type Exchange interface { Name() ExchangeName diff --git a/pkg/types/mocks/mock_exchange.go b/pkg/types/mocks/mock_exchange.go new file mode 100644 index 000000000..5c0410af7 --- /dev/null +++ b/pkg/types/mocks/mock_exchange.go @@ -0,0 +1,745 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: exchange.go + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + time "time" + + fixedpoint "github.com/c9s/bbgo/pkg/fixedpoint" + types "github.com/c9s/bbgo/pkg/types" + gomock "github.com/golang/mock/gomock" +) + +// MockExchange is a mock of Exchange interface. +type MockExchange struct { + ctrl *gomock.Controller + recorder *MockExchangeMockRecorder +} + +// MockExchangeMockRecorder is the mock recorder for MockExchange. +type MockExchangeMockRecorder struct { + mock *MockExchange +} + +// NewMockExchange creates a new mock instance. +func NewMockExchange(ctrl *gomock.Controller) *MockExchange { + mock := &MockExchange{ctrl: ctrl} + mock.recorder = &MockExchangeMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchange) EXPECT() *MockExchangeMockRecorder { + return m.recorder +} + +// CancelOrders mocks base method. +func (m *MockExchange) CancelOrders(ctx context.Context, orders ...types.Order) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range orders { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "CancelOrders", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// CancelOrders indicates an expected call of CancelOrders. +func (mr *MockExchangeMockRecorder) CancelOrders(ctx interface{}, orders ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, orders...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelOrders", reflect.TypeOf((*MockExchange)(nil).CancelOrders), varargs...) +} + +// Name mocks base method. +func (m *MockExchange) Name() types.ExchangeName { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Name") + ret0, _ := ret[0].(types.ExchangeName) + return ret0 +} + +// Name indicates an expected call of Name. +func (mr *MockExchangeMockRecorder) Name() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Name", reflect.TypeOf((*MockExchange)(nil).Name)) +} + +// NewStream mocks base method. +func (m *MockExchange) NewStream() types.Stream { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewStream") + ret0, _ := ret[0].(types.Stream) + return ret0 +} + +// NewStream indicates an expected call of NewStream. +func (mr *MockExchangeMockRecorder) NewStream() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewStream", reflect.TypeOf((*MockExchange)(nil).NewStream)) +} + +// PlatformFeeCurrency mocks base method. +func (m *MockExchange) PlatformFeeCurrency() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "PlatformFeeCurrency") + ret0, _ := ret[0].(string) + return ret0 +} + +// PlatformFeeCurrency indicates an expected call of PlatformFeeCurrency. +func (mr *MockExchangeMockRecorder) PlatformFeeCurrency() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PlatformFeeCurrency", reflect.TypeOf((*MockExchange)(nil).PlatformFeeCurrency)) +} + +// QueryAccount mocks base method. +func (m *MockExchange) QueryAccount(ctx context.Context) (*types.Account, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryAccount", ctx) + ret0, _ := ret[0].(*types.Account) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryAccount indicates an expected call of QueryAccount. +func (mr *MockExchangeMockRecorder) QueryAccount(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccount", reflect.TypeOf((*MockExchange)(nil).QueryAccount), ctx) +} + +// QueryAccountBalances mocks base method. +func (m *MockExchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryAccountBalances", ctx) + ret0, _ := ret[0].(types.BalanceMap) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryAccountBalances indicates an expected call of QueryAccountBalances. +func (mr *MockExchangeMockRecorder) QueryAccountBalances(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccountBalances", reflect.TypeOf((*MockExchange)(nil).QueryAccountBalances), ctx) +} + +// QueryKLines mocks base method. +func (m *MockExchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryKLines", ctx, symbol, interval, options) + ret0, _ := ret[0].([]types.KLine) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryKLines indicates an expected call of QueryKLines. +func (mr *MockExchangeMockRecorder) QueryKLines(ctx, symbol, interval, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryKLines", reflect.TypeOf((*MockExchange)(nil).QueryKLines), ctx, symbol, interval, options) +} + +// QueryMarkets mocks base method. +func (m *MockExchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryMarkets", ctx) + ret0, _ := ret[0].(types.MarketMap) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryMarkets indicates an expected call of QueryMarkets. +func (mr *MockExchangeMockRecorder) QueryMarkets(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMarkets", reflect.TypeOf((*MockExchange)(nil).QueryMarkets), ctx) +} + +// QueryOpenOrders mocks base method. +func (m *MockExchange) QueryOpenOrders(ctx context.Context, symbol string) ([]types.Order, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryOpenOrders", ctx, symbol) + ret0, _ := ret[0].([]types.Order) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryOpenOrders indicates an expected call of QueryOpenOrders. +func (mr *MockExchangeMockRecorder) QueryOpenOrders(ctx, symbol interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOpenOrders", reflect.TypeOf((*MockExchange)(nil).QueryOpenOrders), ctx, symbol) +} + +// QueryTicker mocks base method. +func (m *MockExchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryTicker", ctx, symbol) + ret0, _ := ret[0].(*types.Ticker) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryTicker indicates an expected call of QueryTicker. +func (mr *MockExchangeMockRecorder) QueryTicker(ctx, symbol interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTicker", reflect.TypeOf((*MockExchange)(nil).QueryTicker), ctx, symbol) +} + +// QueryTickers mocks base method. +func (m *MockExchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range symbol { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "QueryTickers", varargs...) + ret0, _ := ret[0].(map[string]types.Ticker) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryTickers indicates an expected call of QueryTickers. +func (mr *MockExchangeMockRecorder) QueryTickers(ctx interface{}, symbol ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, symbol...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTickers", reflect.TypeOf((*MockExchange)(nil).QueryTickers), varargs...) +} + +// SubmitOrders mocks base method. +func (m *MockExchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (types.OrderSlice, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range orders { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SubmitOrders", varargs...) + ret0, _ := ret[0].(types.OrderSlice) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitOrders indicates an expected call of SubmitOrders. +func (mr *MockExchangeMockRecorder) SubmitOrders(ctx interface{}, orders ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, orders...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitOrders", reflect.TypeOf((*MockExchange)(nil).SubmitOrders), varargs...) +} + +// MockExchangeOrderQueryService is a mock of ExchangeOrderQueryService interface. +type MockExchangeOrderQueryService struct { + ctrl *gomock.Controller + recorder *MockExchangeOrderQueryServiceMockRecorder +} + +// MockExchangeOrderQueryServiceMockRecorder is the mock recorder for MockExchangeOrderQueryService. +type MockExchangeOrderQueryServiceMockRecorder struct { + mock *MockExchangeOrderQueryService +} + +// NewMockExchangeOrderQueryService creates a new mock instance. +func NewMockExchangeOrderQueryService(ctrl *gomock.Controller) *MockExchangeOrderQueryService { + mock := &MockExchangeOrderQueryService{ctrl: ctrl} + mock.recorder = &MockExchangeOrderQueryServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeOrderQueryService) EXPECT() *MockExchangeOrderQueryServiceMockRecorder { + return m.recorder +} + +// QueryOrder mocks base method. +func (m *MockExchangeOrderQueryService) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryOrder", ctx, q) + ret0, _ := ret[0].(*types.Order) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryOrder indicates an expected call of QueryOrder. +func (mr *MockExchangeOrderQueryServiceMockRecorder) QueryOrder(ctx, q interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOrder", reflect.TypeOf((*MockExchangeOrderQueryService)(nil).QueryOrder), ctx, q) +} + +// MockExchangeTradeService is a mock of ExchangeTradeService interface. +type MockExchangeTradeService struct { + ctrl *gomock.Controller + recorder *MockExchangeTradeServiceMockRecorder +} + +// MockExchangeTradeServiceMockRecorder is the mock recorder for MockExchangeTradeService. +type MockExchangeTradeServiceMockRecorder struct { + mock *MockExchangeTradeService +} + +// NewMockExchangeTradeService creates a new mock instance. +func NewMockExchangeTradeService(ctrl *gomock.Controller) *MockExchangeTradeService { + mock := &MockExchangeTradeService{ctrl: ctrl} + mock.recorder = &MockExchangeTradeServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeTradeService) EXPECT() *MockExchangeTradeServiceMockRecorder { + return m.recorder +} + +// CancelOrders mocks base method. +func (m *MockExchangeTradeService) CancelOrders(ctx context.Context, orders ...types.Order) error { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range orders { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "CancelOrders", varargs...) + ret0, _ := ret[0].(error) + return ret0 +} + +// CancelOrders indicates an expected call of CancelOrders. +func (mr *MockExchangeTradeServiceMockRecorder) CancelOrders(ctx interface{}, orders ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, orders...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).CancelOrders), varargs...) +} + +// QueryAccount mocks base method. +func (m *MockExchangeTradeService) QueryAccount(ctx context.Context) (*types.Account, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryAccount", ctx) + ret0, _ := ret[0].(*types.Account) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryAccount indicates an expected call of QueryAccount. +func (mr *MockExchangeTradeServiceMockRecorder) QueryAccount(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccount", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryAccount), ctx) +} + +// QueryAccountBalances mocks base method. +func (m *MockExchangeTradeService) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryAccountBalances", ctx) + ret0, _ := ret[0].(types.BalanceMap) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryAccountBalances indicates an expected call of QueryAccountBalances. +func (mr *MockExchangeTradeServiceMockRecorder) QueryAccountBalances(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccountBalances", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryAccountBalances), ctx) +} + +// QueryOpenOrders mocks base method. +func (m *MockExchangeTradeService) QueryOpenOrders(ctx context.Context, symbol string) ([]types.Order, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryOpenOrders", ctx, symbol) + ret0, _ := ret[0].([]types.Order) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryOpenOrders indicates an expected call of QueryOpenOrders. +func (mr *MockExchangeTradeServiceMockRecorder) QueryOpenOrders(ctx, symbol interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOpenOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryOpenOrders), ctx, symbol) +} + +// SubmitOrders mocks base method. +func (m *MockExchangeTradeService) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (types.OrderSlice, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range orders { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "SubmitOrders", varargs...) + ret0, _ := ret[0].(types.OrderSlice) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SubmitOrders indicates an expected call of SubmitOrders. +func (mr *MockExchangeTradeServiceMockRecorder) SubmitOrders(ctx interface{}, orders ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, orders...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).SubmitOrders), varargs...) +} + +// MockExchangeDefaultFeeRates is a mock of ExchangeDefaultFeeRates interface. +type MockExchangeDefaultFeeRates struct { + ctrl *gomock.Controller + recorder *MockExchangeDefaultFeeRatesMockRecorder +} + +// MockExchangeDefaultFeeRatesMockRecorder is the mock recorder for MockExchangeDefaultFeeRates. +type MockExchangeDefaultFeeRatesMockRecorder struct { + mock *MockExchangeDefaultFeeRates +} + +// NewMockExchangeDefaultFeeRates creates a new mock instance. +func NewMockExchangeDefaultFeeRates(ctrl *gomock.Controller) *MockExchangeDefaultFeeRates { + mock := &MockExchangeDefaultFeeRates{ctrl: ctrl} + mock.recorder = &MockExchangeDefaultFeeRatesMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeDefaultFeeRates) EXPECT() *MockExchangeDefaultFeeRatesMockRecorder { + return m.recorder +} + +// DefaultFeeRates mocks base method. +func (m *MockExchangeDefaultFeeRates) DefaultFeeRates() types.ExchangeFee { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "DefaultFeeRates") + ret0, _ := ret[0].(types.ExchangeFee) + return ret0 +} + +// DefaultFeeRates indicates an expected call of DefaultFeeRates. +func (mr *MockExchangeDefaultFeeRatesMockRecorder) DefaultFeeRates() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultFeeRates", reflect.TypeOf((*MockExchangeDefaultFeeRates)(nil).DefaultFeeRates)) +} + +// MockExchangeTradeHistoryService is a mock of ExchangeTradeHistoryService interface. +type MockExchangeTradeHistoryService struct { + ctrl *gomock.Controller + recorder *MockExchangeTradeHistoryServiceMockRecorder +} + +// MockExchangeTradeHistoryServiceMockRecorder is the mock recorder for MockExchangeTradeHistoryService. +type MockExchangeTradeHistoryServiceMockRecorder struct { + mock *MockExchangeTradeHistoryService +} + +// NewMockExchangeTradeHistoryService creates a new mock instance. +func NewMockExchangeTradeHistoryService(ctrl *gomock.Controller) *MockExchangeTradeHistoryService { + mock := &MockExchangeTradeHistoryService{ctrl: ctrl} + mock.recorder = &MockExchangeTradeHistoryServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeTradeHistoryService) EXPECT() *MockExchangeTradeHistoryServiceMockRecorder { + return m.recorder +} + +// QueryClosedOrders mocks base method. +func (m *MockExchangeTradeHistoryService) QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) ([]types.Order, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryClosedOrders", ctx, symbol, since, until, lastOrderID) + ret0, _ := ret[0].([]types.Order) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryClosedOrders indicates an expected call of QueryClosedOrders. +func (mr *MockExchangeTradeHistoryServiceMockRecorder) QueryClosedOrders(ctx, symbol, since, until, lastOrderID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryClosedOrders", reflect.TypeOf((*MockExchangeTradeHistoryService)(nil).QueryClosedOrders), ctx, symbol, since, until, lastOrderID) +} + +// QueryTrades mocks base method. +func (m *MockExchangeTradeHistoryService) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) ([]types.Trade, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryTrades", ctx, symbol, options) + ret0, _ := ret[0].([]types.Trade) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryTrades indicates an expected call of QueryTrades. +func (mr *MockExchangeTradeHistoryServiceMockRecorder) QueryTrades(ctx, symbol, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTrades", reflect.TypeOf((*MockExchangeTradeHistoryService)(nil).QueryTrades), ctx, symbol, options) +} + +// MockExchangeMarketDataService is a mock of ExchangeMarketDataService interface. +type MockExchangeMarketDataService struct { + ctrl *gomock.Controller + recorder *MockExchangeMarketDataServiceMockRecorder +} + +// MockExchangeMarketDataServiceMockRecorder is the mock recorder for MockExchangeMarketDataService. +type MockExchangeMarketDataServiceMockRecorder struct { + mock *MockExchangeMarketDataService +} + +// NewMockExchangeMarketDataService creates a new mock instance. +func NewMockExchangeMarketDataService(ctrl *gomock.Controller) *MockExchangeMarketDataService { + mock := &MockExchangeMarketDataService{ctrl: ctrl} + mock.recorder = &MockExchangeMarketDataServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeMarketDataService) EXPECT() *MockExchangeMarketDataServiceMockRecorder { + return m.recorder +} + +// NewStream mocks base method. +func (m *MockExchangeMarketDataService) NewStream() types.Stream { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "NewStream") + ret0, _ := ret[0].(types.Stream) + return ret0 +} + +// NewStream indicates an expected call of NewStream. +func (mr *MockExchangeMarketDataServiceMockRecorder) NewStream() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewStream", reflect.TypeOf((*MockExchangeMarketDataService)(nil).NewStream)) +} + +// QueryKLines mocks base method. +func (m *MockExchangeMarketDataService) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryKLines", ctx, symbol, interval, options) + ret0, _ := ret[0].([]types.KLine) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryKLines indicates an expected call of QueryKLines. +func (mr *MockExchangeMarketDataServiceMockRecorder) QueryKLines(ctx, symbol, interval, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryKLines", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryKLines), ctx, symbol, interval, options) +} + +// QueryMarkets mocks base method. +func (m *MockExchangeMarketDataService) QueryMarkets(ctx context.Context) (types.MarketMap, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryMarkets", ctx) + ret0, _ := ret[0].(types.MarketMap) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryMarkets indicates an expected call of QueryMarkets. +func (mr *MockExchangeMarketDataServiceMockRecorder) QueryMarkets(ctx interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMarkets", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryMarkets), ctx) +} + +// QueryTicker mocks base method. +func (m *MockExchangeMarketDataService) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryTicker", ctx, symbol) + ret0, _ := ret[0].(*types.Ticker) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryTicker indicates an expected call of QueryTicker. +func (mr *MockExchangeMarketDataServiceMockRecorder) QueryTicker(ctx, symbol interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTicker", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryTicker), ctx, symbol) +} + +// QueryTickers mocks base method. +func (m *MockExchangeMarketDataService) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) { + m.ctrl.T.Helper() + varargs := []interface{}{ctx} + for _, a := range symbol { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "QueryTickers", varargs...) + ret0, _ := ret[0].(map[string]types.Ticker) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryTickers indicates an expected call of QueryTickers. +func (mr *MockExchangeMarketDataServiceMockRecorder) QueryTickers(ctx interface{}, symbol ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{ctx}, symbol...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTickers", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryTickers), varargs...) +} + +// MockCustomIntervalProvider is a mock of CustomIntervalProvider interface. +type MockCustomIntervalProvider struct { + ctrl *gomock.Controller + recorder *MockCustomIntervalProviderMockRecorder +} + +// MockCustomIntervalProviderMockRecorder is the mock recorder for MockCustomIntervalProvider. +type MockCustomIntervalProviderMockRecorder struct { + mock *MockCustomIntervalProvider +} + +// NewMockCustomIntervalProvider creates a new mock instance. +func NewMockCustomIntervalProvider(ctrl *gomock.Controller) *MockCustomIntervalProvider { + mock := &MockCustomIntervalProvider{ctrl: ctrl} + mock.recorder = &MockCustomIntervalProviderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockCustomIntervalProvider) EXPECT() *MockCustomIntervalProviderMockRecorder { + return m.recorder +} + +// IsSupportedInterval mocks base method. +func (m *MockCustomIntervalProvider) IsSupportedInterval(interval types.Interval) bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsSupportedInterval", interval) + ret0, _ := ret[0].(bool) + return ret0 +} + +// IsSupportedInterval indicates an expected call of IsSupportedInterval. +func (mr *MockCustomIntervalProviderMockRecorder) IsSupportedInterval(interval interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSupportedInterval", reflect.TypeOf((*MockCustomIntervalProvider)(nil).IsSupportedInterval), interval) +} + +// SupportedInterval mocks base method. +func (m *MockCustomIntervalProvider) SupportedInterval() map[types.Interval]int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SupportedInterval") + ret0, _ := ret[0].(map[types.Interval]int) + return ret0 +} + +// SupportedInterval indicates an expected call of SupportedInterval. +func (mr *MockCustomIntervalProviderMockRecorder) SupportedInterval() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupportedInterval", reflect.TypeOf((*MockCustomIntervalProvider)(nil).SupportedInterval)) +} + +// MockExchangeTransferService is a mock of ExchangeTransferService interface. +type MockExchangeTransferService struct { + ctrl *gomock.Controller + recorder *MockExchangeTransferServiceMockRecorder +} + +// MockExchangeTransferServiceMockRecorder is the mock recorder for MockExchangeTransferService. +type MockExchangeTransferServiceMockRecorder struct { + mock *MockExchangeTransferService +} + +// NewMockExchangeTransferService creates a new mock instance. +func NewMockExchangeTransferService(ctrl *gomock.Controller) *MockExchangeTransferService { + mock := &MockExchangeTransferService{ctrl: ctrl} + mock.recorder = &MockExchangeTransferServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeTransferService) EXPECT() *MockExchangeTransferServiceMockRecorder { + return m.recorder +} + +// QueryDepositHistory mocks base method. +func (m *MockExchangeTransferService) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) ([]types.Deposit, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryDepositHistory", ctx, asset, since, until) + ret0, _ := ret[0].([]types.Deposit) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryDepositHistory indicates an expected call of QueryDepositHistory. +func (mr *MockExchangeTransferServiceMockRecorder) QueryDepositHistory(ctx, asset, since, until interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryDepositHistory", reflect.TypeOf((*MockExchangeTransferService)(nil).QueryDepositHistory), ctx, asset, since, until) +} + +// QueryWithdrawHistory mocks base method. +func (m *MockExchangeTransferService) QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) ([]types.Withdraw, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryWithdrawHistory", ctx, asset, since, until) + ret0, _ := ret[0].([]types.Withdraw) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryWithdrawHistory indicates an expected call of QueryWithdrawHistory. +func (mr *MockExchangeTransferServiceMockRecorder) QueryWithdrawHistory(ctx, asset, since, until interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryWithdrawHistory", reflect.TypeOf((*MockExchangeTransferService)(nil).QueryWithdrawHistory), ctx, asset, since, until) +} + +// MockExchangeWithdrawalService is a mock of ExchangeWithdrawalService interface. +type MockExchangeWithdrawalService struct { + ctrl *gomock.Controller + recorder *MockExchangeWithdrawalServiceMockRecorder +} + +// MockExchangeWithdrawalServiceMockRecorder is the mock recorder for MockExchangeWithdrawalService. +type MockExchangeWithdrawalServiceMockRecorder struct { + mock *MockExchangeWithdrawalService +} + +// NewMockExchangeWithdrawalService creates a new mock instance. +func NewMockExchangeWithdrawalService(ctrl *gomock.Controller) *MockExchangeWithdrawalService { + mock := &MockExchangeWithdrawalService{ctrl: ctrl} + mock.recorder = &MockExchangeWithdrawalServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeWithdrawalService) EXPECT() *MockExchangeWithdrawalServiceMockRecorder { + return m.recorder +} + +// Withdraw mocks base method. +func (m *MockExchangeWithdrawalService) Withdraw(ctx context.Context, asset string, amount fixedpoint.Value, address string, options *types.WithdrawalOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Withdraw", ctx, asset, amount, address, options) + ret0, _ := ret[0].(error) + return ret0 +} + +// Withdraw indicates an expected call of Withdraw. +func (mr *MockExchangeWithdrawalServiceMockRecorder) Withdraw(ctx, asset, amount, address, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Withdraw", reflect.TypeOf((*MockExchangeWithdrawalService)(nil).Withdraw), ctx, asset, amount, address, options) +} + +// MockExchangeRewardService is a mock of ExchangeRewardService interface. +type MockExchangeRewardService struct { + ctrl *gomock.Controller + recorder *MockExchangeRewardServiceMockRecorder +} + +// MockExchangeRewardServiceMockRecorder is the mock recorder for MockExchangeRewardService. +type MockExchangeRewardServiceMockRecorder struct { + mock *MockExchangeRewardService +} + +// NewMockExchangeRewardService creates a new mock instance. +func NewMockExchangeRewardService(ctrl *gomock.Controller) *MockExchangeRewardService { + mock := &MockExchangeRewardService{ctrl: ctrl} + mock.recorder = &MockExchangeRewardServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExchangeRewardService) EXPECT() *MockExchangeRewardServiceMockRecorder { + return m.recorder +} + +// QueryRewards mocks base method. +func (m *MockExchangeRewardService) QueryRewards(ctx context.Context, startTime time.Time) ([]types.Reward, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "QueryRewards", ctx, startTime) + ret0, _ := ret[0].([]types.Reward) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// QueryRewards indicates an expected call of QueryRewards. +func (mr *MockExchangeRewardServiceMockRecorder) QueryRewards(ctx, startTime interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRewards", reflect.TypeOf((*MockExchangeRewardService)(nil).QueryRewards), ctx, startTime) +} From d140012fd5af99d470d99f3cb8334b66d8dd07b2 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 6 Jul 2022 01:32:05 +0800 Subject: [PATCH 3/4] fix mockgen command Signed-off-by: c9s --- pkg/types/exchange.go | 2 +- pkg/types/mocks/mock_exchange.go | 598 +++---------------------------- 2 files changed, 41 insertions(+), 559 deletions(-) diff --git a/pkg/types/exchange.go b/pkg/types/exchange.go index 39ced8d87..e026decb4 100644 --- a/pkg/types/exchange.go +++ b/pkg/types/exchange.go @@ -74,7 +74,7 @@ func ValidExchangeName(a string) (ExchangeName, error) { return "", fmt.Errorf("invalid exchange name: %s", a) } -//go:generate mockgen -destination=mocks/mock_exchange.go -package=mocks -source=exchange.go Exchange +//go:generate mockgen -destination=mocks/mock_exchange.go -package=mocks . Exchange type Exchange interface { Name() ExchangeName diff --git a/pkg/types/mocks/mock_exchange.go b/pkg/types/mocks/mock_exchange.go index 5c0410af7..731ab94de 100644 --- a/pkg/types/mocks/mock_exchange.go +++ b/pkg/types/mocks/mock_exchange.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: exchange.go +// Source: github.com/c9s/bbgo/pkg/types (interfaces: Exchange) // Package mocks is a generated GoMock package. package mocks @@ -7,9 +7,7 @@ package mocks import ( context "context" reflect "reflect" - time "time" - fixedpoint "github.com/c9s/bbgo/pkg/fixedpoint" types "github.com/c9s/bbgo/pkg/types" gomock "github.com/golang/mock/gomock" ) @@ -38,10 +36,10 @@ func (m *MockExchange) EXPECT() *MockExchangeMockRecorder { } // CancelOrders mocks base method. -func (m *MockExchange) CancelOrders(ctx context.Context, orders ...types.Order) error { +func (m *MockExchange) CancelOrders(arg0 context.Context, arg1 ...types.Order) error { m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range orders { + varargs := []interface{}{arg0} + for _, a := range arg1 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "CancelOrders", varargs...) @@ -50,9 +48,9 @@ func (m *MockExchange) CancelOrders(ctx context.Context, orders ...types.Order) } // CancelOrders indicates an expected call of CancelOrders. -func (mr *MockExchangeMockRecorder) CancelOrders(ctx interface{}, orders ...interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) CancelOrders(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, orders...) + varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelOrders", reflect.TypeOf((*MockExchange)(nil).CancelOrders), varargs...) } @@ -99,100 +97,100 @@ func (mr *MockExchangeMockRecorder) PlatformFeeCurrency() *gomock.Call { } // QueryAccount mocks base method. -func (m *MockExchange) QueryAccount(ctx context.Context) (*types.Account, error) { +func (m *MockExchange) QueryAccount(arg0 context.Context) (*types.Account, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryAccount", ctx) + ret := m.ctrl.Call(m, "QueryAccount", arg0) ret0, _ := ret[0].(*types.Account) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryAccount indicates an expected call of QueryAccount. -func (mr *MockExchangeMockRecorder) QueryAccount(ctx interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryAccount(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccount", reflect.TypeOf((*MockExchange)(nil).QueryAccount), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccount", reflect.TypeOf((*MockExchange)(nil).QueryAccount), arg0) } // QueryAccountBalances mocks base method. -func (m *MockExchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { +func (m *MockExchange) QueryAccountBalances(arg0 context.Context) (types.BalanceMap, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryAccountBalances", ctx) + ret := m.ctrl.Call(m, "QueryAccountBalances", arg0) ret0, _ := ret[0].(types.BalanceMap) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryAccountBalances indicates an expected call of QueryAccountBalances. -func (mr *MockExchangeMockRecorder) QueryAccountBalances(ctx interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryAccountBalances(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccountBalances", reflect.TypeOf((*MockExchange)(nil).QueryAccountBalances), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccountBalances", reflect.TypeOf((*MockExchange)(nil).QueryAccountBalances), arg0) } // QueryKLines mocks base method. -func (m *MockExchange) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { +func (m *MockExchange) QueryKLines(arg0 context.Context, arg1 string, arg2 types.Interval, arg3 types.KLineQueryOptions) ([]types.KLine, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryKLines", ctx, symbol, interval, options) + ret := m.ctrl.Call(m, "QueryKLines", arg0, arg1, arg2, arg3) ret0, _ := ret[0].([]types.KLine) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryKLines indicates an expected call of QueryKLines. -func (mr *MockExchangeMockRecorder) QueryKLines(ctx, symbol, interval, options interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryKLines(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryKLines", reflect.TypeOf((*MockExchange)(nil).QueryKLines), ctx, symbol, interval, options) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryKLines", reflect.TypeOf((*MockExchange)(nil).QueryKLines), arg0, arg1, arg2, arg3) } // QueryMarkets mocks base method. -func (m *MockExchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) { +func (m *MockExchange) QueryMarkets(arg0 context.Context) (types.MarketMap, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryMarkets", ctx) + ret := m.ctrl.Call(m, "QueryMarkets", arg0) ret0, _ := ret[0].(types.MarketMap) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryMarkets indicates an expected call of QueryMarkets. -func (mr *MockExchangeMockRecorder) QueryMarkets(ctx interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryMarkets(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMarkets", reflect.TypeOf((*MockExchange)(nil).QueryMarkets), ctx) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMarkets", reflect.TypeOf((*MockExchange)(nil).QueryMarkets), arg0) } // QueryOpenOrders mocks base method. -func (m *MockExchange) QueryOpenOrders(ctx context.Context, symbol string) ([]types.Order, error) { +func (m *MockExchange) QueryOpenOrders(arg0 context.Context, arg1 string) ([]types.Order, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryOpenOrders", ctx, symbol) + ret := m.ctrl.Call(m, "QueryOpenOrders", arg0, arg1) ret0, _ := ret[0].([]types.Order) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryOpenOrders indicates an expected call of QueryOpenOrders. -func (mr *MockExchangeMockRecorder) QueryOpenOrders(ctx, symbol interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryOpenOrders(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOpenOrders", reflect.TypeOf((*MockExchange)(nil).QueryOpenOrders), ctx, symbol) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOpenOrders", reflect.TypeOf((*MockExchange)(nil).QueryOpenOrders), arg0, arg1) } // QueryTicker mocks base method. -func (m *MockExchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { +func (m *MockExchange) QueryTicker(arg0 context.Context, arg1 string) (*types.Ticker, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryTicker", ctx, symbol) + ret := m.ctrl.Call(m, "QueryTicker", arg0, arg1) ret0, _ := ret[0].(*types.Ticker) ret1, _ := ret[1].(error) return ret0, ret1 } // QueryTicker indicates an expected call of QueryTicker. -func (mr *MockExchangeMockRecorder) QueryTicker(ctx, symbol interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryTicker(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTicker", reflect.TypeOf((*MockExchange)(nil).QueryTicker), ctx, symbol) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTicker", reflect.TypeOf((*MockExchange)(nil).QueryTicker), arg0, arg1) } // QueryTickers mocks base method. -func (m *MockExchange) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) { +func (m *MockExchange) QueryTickers(arg0 context.Context, arg1 ...string) (map[string]types.Ticker, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range symbol { + varargs := []interface{}{arg0} + for _, a := range arg1 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "QueryTickers", varargs...) @@ -202,17 +200,17 @@ func (m *MockExchange) QueryTickers(ctx context.Context, symbol ...string) (map[ } // QueryTickers indicates an expected call of QueryTickers. -func (mr *MockExchangeMockRecorder) QueryTickers(ctx interface{}, symbol ...interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) QueryTickers(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, symbol...) + varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTickers", reflect.TypeOf((*MockExchange)(nil).QueryTickers), varargs...) } // SubmitOrders mocks base method. -func (m *MockExchange) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (types.OrderSlice, error) { +func (m *MockExchange) SubmitOrders(arg0 context.Context, arg1 ...types.SubmitOrder) (types.OrderSlice, error) { m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range orders { + varargs := []interface{}{arg0} + for _, a := range arg1 { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "SubmitOrders", varargs...) @@ -222,524 +220,8 @@ func (m *MockExchange) SubmitOrders(ctx context.Context, orders ...types.SubmitO } // SubmitOrders indicates an expected call of SubmitOrders. -func (mr *MockExchangeMockRecorder) SubmitOrders(ctx interface{}, orders ...interface{}) *gomock.Call { +func (mr *MockExchangeMockRecorder) SubmitOrders(arg0 interface{}, arg1 ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, orders...) + varargs := append([]interface{}{arg0}, arg1...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitOrders", reflect.TypeOf((*MockExchange)(nil).SubmitOrders), varargs...) } - -// MockExchangeOrderQueryService is a mock of ExchangeOrderQueryService interface. -type MockExchangeOrderQueryService struct { - ctrl *gomock.Controller - recorder *MockExchangeOrderQueryServiceMockRecorder -} - -// MockExchangeOrderQueryServiceMockRecorder is the mock recorder for MockExchangeOrderQueryService. -type MockExchangeOrderQueryServiceMockRecorder struct { - mock *MockExchangeOrderQueryService -} - -// NewMockExchangeOrderQueryService creates a new mock instance. -func NewMockExchangeOrderQueryService(ctrl *gomock.Controller) *MockExchangeOrderQueryService { - mock := &MockExchangeOrderQueryService{ctrl: ctrl} - mock.recorder = &MockExchangeOrderQueryServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeOrderQueryService) EXPECT() *MockExchangeOrderQueryServiceMockRecorder { - return m.recorder -} - -// QueryOrder mocks base method. -func (m *MockExchangeOrderQueryService) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.Order, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryOrder", ctx, q) - ret0, _ := ret[0].(*types.Order) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryOrder indicates an expected call of QueryOrder. -func (mr *MockExchangeOrderQueryServiceMockRecorder) QueryOrder(ctx, q interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOrder", reflect.TypeOf((*MockExchangeOrderQueryService)(nil).QueryOrder), ctx, q) -} - -// MockExchangeTradeService is a mock of ExchangeTradeService interface. -type MockExchangeTradeService struct { - ctrl *gomock.Controller - recorder *MockExchangeTradeServiceMockRecorder -} - -// MockExchangeTradeServiceMockRecorder is the mock recorder for MockExchangeTradeService. -type MockExchangeTradeServiceMockRecorder struct { - mock *MockExchangeTradeService -} - -// NewMockExchangeTradeService creates a new mock instance. -func NewMockExchangeTradeService(ctrl *gomock.Controller) *MockExchangeTradeService { - mock := &MockExchangeTradeService{ctrl: ctrl} - mock.recorder = &MockExchangeTradeServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeTradeService) EXPECT() *MockExchangeTradeServiceMockRecorder { - return m.recorder -} - -// CancelOrders mocks base method. -func (m *MockExchangeTradeService) CancelOrders(ctx context.Context, orders ...types.Order) error { - m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range orders { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "CancelOrders", varargs...) - ret0, _ := ret[0].(error) - return ret0 -} - -// CancelOrders indicates an expected call of CancelOrders. -func (mr *MockExchangeTradeServiceMockRecorder) CancelOrders(ctx interface{}, orders ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, orders...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CancelOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).CancelOrders), varargs...) -} - -// QueryAccount mocks base method. -func (m *MockExchangeTradeService) QueryAccount(ctx context.Context) (*types.Account, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryAccount", ctx) - ret0, _ := ret[0].(*types.Account) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryAccount indicates an expected call of QueryAccount. -func (mr *MockExchangeTradeServiceMockRecorder) QueryAccount(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccount", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryAccount), ctx) -} - -// QueryAccountBalances mocks base method. -func (m *MockExchangeTradeService) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryAccountBalances", ctx) - ret0, _ := ret[0].(types.BalanceMap) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryAccountBalances indicates an expected call of QueryAccountBalances. -func (mr *MockExchangeTradeServiceMockRecorder) QueryAccountBalances(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryAccountBalances", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryAccountBalances), ctx) -} - -// QueryOpenOrders mocks base method. -func (m *MockExchangeTradeService) QueryOpenOrders(ctx context.Context, symbol string) ([]types.Order, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryOpenOrders", ctx, symbol) - ret0, _ := ret[0].([]types.Order) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryOpenOrders indicates an expected call of QueryOpenOrders. -func (mr *MockExchangeTradeServiceMockRecorder) QueryOpenOrders(ctx, symbol interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryOpenOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).QueryOpenOrders), ctx, symbol) -} - -// SubmitOrders mocks base method. -func (m *MockExchangeTradeService) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (types.OrderSlice, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range orders { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "SubmitOrders", varargs...) - ret0, _ := ret[0].(types.OrderSlice) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// SubmitOrders indicates an expected call of SubmitOrders. -func (mr *MockExchangeTradeServiceMockRecorder) SubmitOrders(ctx interface{}, orders ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, orders...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SubmitOrders", reflect.TypeOf((*MockExchangeTradeService)(nil).SubmitOrders), varargs...) -} - -// MockExchangeDefaultFeeRates is a mock of ExchangeDefaultFeeRates interface. -type MockExchangeDefaultFeeRates struct { - ctrl *gomock.Controller - recorder *MockExchangeDefaultFeeRatesMockRecorder -} - -// MockExchangeDefaultFeeRatesMockRecorder is the mock recorder for MockExchangeDefaultFeeRates. -type MockExchangeDefaultFeeRatesMockRecorder struct { - mock *MockExchangeDefaultFeeRates -} - -// NewMockExchangeDefaultFeeRates creates a new mock instance. -func NewMockExchangeDefaultFeeRates(ctrl *gomock.Controller) *MockExchangeDefaultFeeRates { - mock := &MockExchangeDefaultFeeRates{ctrl: ctrl} - mock.recorder = &MockExchangeDefaultFeeRatesMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeDefaultFeeRates) EXPECT() *MockExchangeDefaultFeeRatesMockRecorder { - return m.recorder -} - -// DefaultFeeRates mocks base method. -func (m *MockExchangeDefaultFeeRates) DefaultFeeRates() types.ExchangeFee { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DefaultFeeRates") - ret0, _ := ret[0].(types.ExchangeFee) - return ret0 -} - -// DefaultFeeRates indicates an expected call of DefaultFeeRates. -func (mr *MockExchangeDefaultFeeRatesMockRecorder) DefaultFeeRates() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DefaultFeeRates", reflect.TypeOf((*MockExchangeDefaultFeeRates)(nil).DefaultFeeRates)) -} - -// MockExchangeTradeHistoryService is a mock of ExchangeTradeHistoryService interface. -type MockExchangeTradeHistoryService struct { - ctrl *gomock.Controller - recorder *MockExchangeTradeHistoryServiceMockRecorder -} - -// MockExchangeTradeHistoryServiceMockRecorder is the mock recorder for MockExchangeTradeHistoryService. -type MockExchangeTradeHistoryServiceMockRecorder struct { - mock *MockExchangeTradeHistoryService -} - -// NewMockExchangeTradeHistoryService creates a new mock instance. -func NewMockExchangeTradeHistoryService(ctrl *gomock.Controller) *MockExchangeTradeHistoryService { - mock := &MockExchangeTradeHistoryService{ctrl: ctrl} - mock.recorder = &MockExchangeTradeHistoryServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeTradeHistoryService) EXPECT() *MockExchangeTradeHistoryServiceMockRecorder { - return m.recorder -} - -// QueryClosedOrders mocks base method. -func (m *MockExchangeTradeHistoryService) QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) ([]types.Order, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryClosedOrders", ctx, symbol, since, until, lastOrderID) - ret0, _ := ret[0].([]types.Order) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryClosedOrders indicates an expected call of QueryClosedOrders. -func (mr *MockExchangeTradeHistoryServiceMockRecorder) QueryClosedOrders(ctx, symbol, since, until, lastOrderID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryClosedOrders", reflect.TypeOf((*MockExchangeTradeHistoryService)(nil).QueryClosedOrders), ctx, symbol, since, until, lastOrderID) -} - -// QueryTrades mocks base method. -func (m *MockExchangeTradeHistoryService) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) ([]types.Trade, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryTrades", ctx, symbol, options) - ret0, _ := ret[0].([]types.Trade) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryTrades indicates an expected call of QueryTrades. -func (mr *MockExchangeTradeHistoryServiceMockRecorder) QueryTrades(ctx, symbol, options interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTrades", reflect.TypeOf((*MockExchangeTradeHistoryService)(nil).QueryTrades), ctx, symbol, options) -} - -// MockExchangeMarketDataService is a mock of ExchangeMarketDataService interface. -type MockExchangeMarketDataService struct { - ctrl *gomock.Controller - recorder *MockExchangeMarketDataServiceMockRecorder -} - -// MockExchangeMarketDataServiceMockRecorder is the mock recorder for MockExchangeMarketDataService. -type MockExchangeMarketDataServiceMockRecorder struct { - mock *MockExchangeMarketDataService -} - -// NewMockExchangeMarketDataService creates a new mock instance. -func NewMockExchangeMarketDataService(ctrl *gomock.Controller) *MockExchangeMarketDataService { - mock := &MockExchangeMarketDataService{ctrl: ctrl} - mock.recorder = &MockExchangeMarketDataServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeMarketDataService) EXPECT() *MockExchangeMarketDataServiceMockRecorder { - return m.recorder -} - -// NewStream mocks base method. -func (m *MockExchangeMarketDataService) NewStream() types.Stream { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "NewStream") - ret0, _ := ret[0].(types.Stream) - return ret0 -} - -// NewStream indicates an expected call of NewStream. -func (mr *MockExchangeMarketDataServiceMockRecorder) NewStream() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewStream", reflect.TypeOf((*MockExchangeMarketDataService)(nil).NewStream)) -} - -// QueryKLines mocks base method. -func (m *MockExchangeMarketDataService) QueryKLines(ctx context.Context, symbol string, interval types.Interval, options types.KLineQueryOptions) ([]types.KLine, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryKLines", ctx, symbol, interval, options) - ret0, _ := ret[0].([]types.KLine) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryKLines indicates an expected call of QueryKLines. -func (mr *MockExchangeMarketDataServiceMockRecorder) QueryKLines(ctx, symbol, interval, options interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryKLines", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryKLines), ctx, symbol, interval, options) -} - -// QueryMarkets mocks base method. -func (m *MockExchangeMarketDataService) QueryMarkets(ctx context.Context) (types.MarketMap, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryMarkets", ctx) - ret0, _ := ret[0].(types.MarketMap) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryMarkets indicates an expected call of QueryMarkets. -func (mr *MockExchangeMarketDataServiceMockRecorder) QueryMarkets(ctx interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryMarkets", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryMarkets), ctx) -} - -// QueryTicker mocks base method. -func (m *MockExchangeMarketDataService) QueryTicker(ctx context.Context, symbol string) (*types.Ticker, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryTicker", ctx, symbol) - ret0, _ := ret[0].(*types.Ticker) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryTicker indicates an expected call of QueryTicker. -func (mr *MockExchangeMarketDataServiceMockRecorder) QueryTicker(ctx, symbol interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTicker", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryTicker), ctx, symbol) -} - -// QueryTickers mocks base method. -func (m *MockExchangeMarketDataService) QueryTickers(ctx context.Context, symbol ...string) (map[string]types.Ticker, error) { - m.ctrl.T.Helper() - varargs := []interface{}{ctx} - for _, a := range symbol { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "QueryTickers", varargs...) - ret0, _ := ret[0].(map[string]types.Ticker) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryTickers indicates an expected call of QueryTickers. -func (mr *MockExchangeMarketDataServiceMockRecorder) QueryTickers(ctx interface{}, symbol ...interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{ctx}, symbol...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryTickers", reflect.TypeOf((*MockExchangeMarketDataService)(nil).QueryTickers), varargs...) -} - -// MockCustomIntervalProvider is a mock of CustomIntervalProvider interface. -type MockCustomIntervalProvider struct { - ctrl *gomock.Controller - recorder *MockCustomIntervalProviderMockRecorder -} - -// MockCustomIntervalProviderMockRecorder is the mock recorder for MockCustomIntervalProvider. -type MockCustomIntervalProviderMockRecorder struct { - mock *MockCustomIntervalProvider -} - -// NewMockCustomIntervalProvider creates a new mock instance. -func NewMockCustomIntervalProvider(ctrl *gomock.Controller) *MockCustomIntervalProvider { - mock := &MockCustomIntervalProvider{ctrl: ctrl} - mock.recorder = &MockCustomIntervalProviderMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockCustomIntervalProvider) EXPECT() *MockCustomIntervalProviderMockRecorder { - return m.recorder -} - -// IsSupportedInterval mocks base method. -func (m *MockCustomIntervalProvider) IsSupportedInterval(interval types.Interval) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsSupportedInterval", interval) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsSupportedInterval indicates an expected call of IsSupportedInterval. -func (mr *MockCustomIntervalProviderMockRecorder) IsSupportedInterval(interval interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsSupportedInterval", reflect.TypeOf((*MockCustomIntervalProvider)(nil).IsSupportedInterval), interval) -} - -// SupportedInterval mocks base method. -func (m *MockCustomIntervalProvider) SupportedInterval() map[types.Interval]int { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "SupportedInterval") - ret0, _ := ret[0].(map[types.Interval]int) - return ret0 -} - -// SupportedInterval indicates an expected call of SupportedInterval. -func (mr *MockCustomIntervalProviderMockRecorder) SupportedInterval() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SupportedInterval", reflect.TypeOf((*MockCustomIntervalProvider)(nil).SupportedInterval)) -} - -// MockExchangeTransferService is a mock of ExchangeTransferService interface. -type MockExchangeTransferService struct { - ctrl *gomock.Controller - recorder *MockExchangeTransferServiceMockRecorder -} - -// MockExchangeTransferServiceMockRecorder is the mock recorder for MockExchangeTransferService. -type MockExchangeTransferServiceMockRecorder struct { - mock *MockExchangeTransferService -} - -// NewMockExchangeTransferService creates a new mock instance. -func NewMockExchangeTransferService(ctrl *gomock.Controller) *MockExchangeTransferService { - mock := &MockExchangeTransferService{ctrl: ctrl} - mock.recorder = &MockExchangeTransferServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeTransferService) EXPECT() *MockExchangeTransferServiceMockRecorder { - return m.recorder -} - -// QueryDepositHistory mocks base method. -func (m *MockExchangeTransferService) QueryDepositHistory(ctx context.Context, asset string, since, until time.Time) ([]types.Deposit, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryDepositHistory", ctx, asset, since, until) - ret0, _ := ret[0].([]types.Deposit) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryDepositHistory indicates an expected call of QueryDepositHistory. -func (mr *MockExchangeTransferServiceMockRecorder) QueryDepositHistory(ctx, asset, since, until interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryDepositHistory", reflect.TypeOf((*MockExchangeTransferService)(nil).QueryDepositHistory), ctx, asset, since, until) -} - -// QueryWithdrawHistory mocks base method. -func (m *MockExchangeTransferService) QueryWithdrawHistory(ctx context.Context, asset string, since, until time.Time) ([]types.Withdraw, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryWithdrawHistory", ctx, asset, since, until) - ret0, _ := ret[0].([]types.Withdraw) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryWithdrawHistory indicates an expected call of QueryWithdrawHistory. -func (mr *MockExchangeTransferServiceMockRecorder) QueryWithdrawHistory(ctx, asset, since, until interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryWithdrawHistory", reflect.TypeOf((*MockExchangeTransferService)(nil).QueryWithdrawHistory), ctx, asset, since, until) -} - -// MockExchangeWithdrawalService is a mock of ExchangeWithdrawalService interface. -type MockExchangeWithdrawalService struct { - ctrl *gomock.Controller - recorder *MockExchangeWithdrawalServiceMockRecorder -} - -// MockExchangeWithdrawalServiceMockRecorder is the mock recorder for MockExchangeWithdrawalService. -type MockExchangeWithdrawalServiceMockRecorder struct { - mock *MockExchangeWithdrawalService -} - -// NewMockExchangeWithdrawalService creates a new mock instance. -func NewMockExchangeWithdrawalService(ctrl *gomock.Controller) *MockExchangeWithdrawalService { - mock := &MockExchangeWithdrawalService{ctrl: ctrl} - mock.recorder = &MockExchangeWithdrawalServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeWithdrawalService) EXPECT() *MockExchangeWithdrawalServiceMockRecorder { - return m.recorder -} - -// Withdraw mocks base method. -func (m *MockExchangeWithdrawalService) Withdraw(ctx context.Context, asset string, amount fixedpoint.Value, address string, options *types.WithdrawalOptions) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Withdraw", ctx, asset, amount, address, options) - ret0, _ := ret[0].(error) - return ret0 -} - -// Withdraw indicates an expected call of Withdraw. -func (mr *MockExchangeWithdrawalServiceMockRecorder) Withdraw(ctx, asset, amount, address, options interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Withdraw", reflect.TypeOf((*MockExchangeWithdrawalService)(nil).Withdraw), ctx, asset, amount, address, options) -} - -// MockExchangeRewardService is a mock of ExchangeRewardService interface. -type MockExchangeRewardService struct { - ctrl *gomock.Controller - recorder *MockExchangeRewardServiceMockRecorder -} - -// MockExchangeRewardServiceMockRecorder is the mock recorder for MockExchangeRewardService. -type MockExchangeRewardServiceMockRecorder struct { - mock *MockExchangeRewardService -} - -// NewMockExchangeRewardService creates a new mock instance. -func NewMockExchangeRewardService(ctrl *gomock.Controller) *MockExchangeRewardService { - mock := &MockExchangeRewardService{ctrl: ctrl} - mock.recorder = &MockExchangeRewardServiceMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExchangeRewardService) EXPECT() *MockExchangeRewardServiceMockRecorder { - return m.recorder -} - -// QueryRewards mocks base method. -func (m *MockExchangeRewardService) QueryRewards(ctx context.Context, startTime time.Time) ([]types.Reward, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "QueryRewards", ctx, startTime) - ret0, _ := ret[0].([]types.Reward) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// QueryRewards indicates an expected call of QueryRewards. -func (mr *MockExchangeRewardServiceMockRecorder) QueryRewards(ctx, startTime interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueryRewards", reflect.TypeOf((*MockExchangeRewardService)(nil).QueryRewards), ctx, startTime) -} From 2bc12c0522e27ead0b213342b9c47de3c6c6ccb5 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 6 Jul 2022 03:04:01 +0800 Subject: [PATCH 4/4] add trailing stop and it's test cases with gomock Signed-off-by: c9s --- pkg/bbgo/exit_trailing_stop.go | 104 ++++++++++++++++++++++++---- pkg/bbgo/exit_trailing_stop_test.go | 102 +++++++++++++++++++++++++++ pkg/bbgo/session.go | 21 +----- pkg/strategy/pivotshort/strategy.go | 3 - 4 files changed, 194 insertions(+), 36 deletions(-) create mode 100644 pkg/bbgo/exit_trailing_stop_test.go diff --git a/pkg/bbgo/exit_trailing_stop.go b/pkg/bbgo/exit_trailing_stop.go index 769d7cda8..fc953037b 100644 --- a/pkg/bbgo/exit_trailing_stop.go +++ b/pkg/bbgo/exit_trailing_stop.go @@ -1,6 +1,9 @@ package bbgo import ( + "context" + "fmt" + "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" ) @@ -11,6 +14,8 @@ type TrailingStop2 struct { // CallbackRate is the callback rate from the previous high price CallbackRate fixedpoint.Value `json:"callbackRate,omitempty"` + ActivationRatio fixedpoint.Value `json:"activationRatio,omitempty"` + // ClosePosition is a percentage of the position to be closed ClosePosition fixedpoint.Value `json:"closePosition,omitempty"` @@ -22,6 +27,13 @@ type TrailingStop2 struct { // KLine per Interval will be used for updating the stop order Interval types.Interval `json:"interval,omitempty"` + Side types.SideType `json:"side,omitempty"` + + latestHigh fixedpoint.Value + + // activated: when the price reaches the min profit price, we set the activated to true to enable trailing stop + activated bool + // private fields session *ExchangeSession orderExecutor *GeneralOrderExecutor @@ -29,7 +41,7 @@ type TrailingStop2 struct { func (s *TrailingStop2) Subscribe(session *ExchangeSession) { // use 1m kline to handle roi stop - session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: types.Interval1m}) + session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) } func (s *TrailingStop2) Bind(session *ExchangeSession, orderExecutor *GeneralOrderExecutor) { @@ -37,7 +49,7 @@ func (s *TrailingStop2) Bind(session *ExchangeSession, orderExecutor *GeneralOrd s.orderExecutor = orderExecutor position := orderExecutor.Position() - session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, types.Interval1m, func(kline types.KLine) { + session.MarketDataStream.OnKLineClosed(types.KLineWith(s.Symbol, s.Interval, func(kline types.KLine) { s.checkStopPrice(kline.Close, position) })) @@ -52,18 +64,82 @@ func (s *TrailingStop2) Bind(session *ExchangeSession, orderExecutor *GeneralOrd } } -func (s *TrailingStop2) checkStopPrice(closePrice fixedpoint.Value, position *types.Position) { - if position.IsClosed() || position.IsDust(closePrice) { - return +func (s *TrailingStop2) getRatio(price fixedpoint.Value, position *types.Position) (fixedpoint.Value, error) { + switch s.Side { + case types.SideTypeBuy: + // for short position + return position.AverageCost.Sub(price).Div(price), nil + case types.SideTypeSell: + return price.Sub(position.AverageCost).Div(position.AverageCost), nil } - /* - roi := position.ROI(closePrice) - if roi.Compare(s.CallbackRate.Neg()) < 0 { - // stop loss - Notify("[TrailingStop2] %s stop loss triggered by ROI %s/%s, price: %f", position.Symbol, roi.Percentage(), s.Percentage.Neg().Percentage(), closePrice.Float64()) - _ = s.orderExecutor.ClosePosition(context.Background(), fixedpoint.One, "TrailingStop2") - return - } - */ + return fixedpoint.Zero, fmt.Errorf("unexpected side type: %v", s.Side) +} + +func (s *TrailingStop2) checkStopPrice(price fixedpoint.Value, position *types.Position) error { + if position.IsClosed() || position.IsDust(price) { + return nil + } + + if !s.MinProfit.IsZero() { + // check if we have the minimal profit + roi := position.ROI(price) + if roi.Compare(s.MinProfit) >= 0 { + Notify("[trailingStop] activated: ROI %f > minimal profit ratio %f", roi.Float64(), s.MinProfit.Float64()) + s.activated = true + } + } else if !s.ActivationRatio.IsZero() { + ratio, err := s.getRatio(price, position) + if err != nil { + return err + } + + if ratio.Compare(s.ActivationRatio) >= 0 { + s.activated = true + } + } + + // update the latest high for the sell order, or the latest low for the buy order + if s.latestHigh.IsZero() { + s.latestHigh = price + } else { + switch s.Side { + case types.SideTypeBuy: + s.latestHigh = fixedpoint.Min(price, s.latestHigh) + case types.SideTypeSell: + s.latestHigh = fixedpoint.Max(price, s.latestHigh) + } + } + + if !s.activated { + return nil + } + + switch s.Side { + case types.SideTypeBuy: + s.latestHigh = fixedpoint.Min(price, s.latestHigh) + + change := price.Sub(s.latestHigh).Div(s.latestHigh) + if change.Compare(s.CallbackRate) >= 0 { + // submit order + return s.triggerStop(price) + } + + case types.SideTypeSell: + s.latestHigh = fixedpoint.Max(price, s.latestHigh) + + change := price.Sub(s.latestHigh).Div(s.latestHigh) + if change.Compare(s.CallbackRate) >= 0 { + // submit order + return s.triggerStop(price) + } + } + + return nil +} + +func (s *TrailingStop2) triggerStop(price fixedpoint.Value) error { + Notify("[TrailingStop] %s stop loss triggered. price: %f callback rate: %f", s.Symbol, price.Float64(), s.CallbackRate.Float64()) + ctx := context.Background() + return s.orderExecutor.ClosePosition(ctx, fixedpoint.One, "trailingStop") } diff --git a/pkg/bbgo/exit_trailing_stop_test.go b/pkg/bbgo/exit_trailing_stop_test.go new file mode 100644 index 000000000..d1285a1a3 --- /dev/null +++ b/pkg/bbgo/exit_trailing_stop_test.go @@ -0,0 +1,102 @@ +package bbgo + +import ( + "testing" + + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" + + "github.com/c9s/bbgo/pkg/fixedpoint" + "github.com/c9s/bbgo/pkg/types" + "github.com/c9s/bbgo/pkg/types/mocks" +) + +// getTestMarket returns the BTCUSDT market information +// for tests, we always use BTCUSDT +func getTestMarket() types.Market { + market := types.Market{ + Symbol: "BTCUSDT", + PricePrecision: 8, + VolumePrecision: 8, + QuoteCurrency: "USDT", + BaseCurrency: "BTC", + MinNotional: fixedpoint.MustNewFromString("0.001"), + MinAmount: fixedpoint.MustNewFromString("10.0"), + MinQuantity: fixedpoint.MustNewFromString("0.001"), + } + return market +} + +func TestTrailingStop(t *testing.T) { + market := getTestMarket() + + mockCtrl := gomock.NewController(t) + defer mockCtrl.Finish() + + mockEx := mocks.NewMockExchange(mockCtrl) + mockEx.EXPECT().NewStream().Return(&types.StandardStream{}).Times(2) + mockEx.EXPECT().SubmitOrders(gomock.Any(), types.SubmitOrder{ + Symbol: "BTCUSDT", + Side: types.SideTypeBuy, + Type: types.OrderTypeMarket, + Market: market, + Quantity: fixedpoint.NewFromFloat(1.0), + Tag: "trailingStop", + }) + + session := NewExchangeSession("test", mockEx) + assert.NotNil(t, session) + + session.markets[market.Symbol] = market + + position := types.NewPositionFromMarket(market) + position.AverageCost = fixedpoint.NewFromFloat(20000.0) + position.Base = fixedpoint.NewFromFloat(-1.0) + + orderExecutor := NewGeneralOrderExecutor(session, "BTCUSDT", "test", "test-01", position) + + activationRatio := fixedpoint.NewFromFloat(0.01) + callbackRatio := fixedpoint.NewFromFloat(0.01) + stop := &TrailingStop2{ + Symbol: "BTCUSDT", + Interval: types.Interval1m, + Side: types.SideTypeBuy, + CallbackRate: callbackRatio, + ActivationRatio: activationRatio, + } + stop.Bind(session, orderExecutor) + + // the same price + currentPrice := fixedpoint.NewFromFloat(20000.0) + err := stop.checkStopPrice(currentPrice, position) + if assert.NoError(t, err) { + assert.False(t, stop.activated) + } + + // 20000 - 1% = 19800 + currentPrice = currentPrice.Mul(one.Sub(activationRatio)) + err = stop.checkStopPrice(currentPrice, position) + if assert.NoError(t, err) { + assert.True(t, stop.activated) + assert.Equal(t, fixedpoint.NewFromFloat(19800.0), currentPrice) + assert.Equal(t, fixedpoint.NewFromFloat(19800.0), stop.latestHigh) + } + + // 19800 - 1% = 19602 + currentPrice = currentPrice.Mul(one.Sub(callbackRatio)) + err = stop.checkStopPrice(currentPrice, position) + if assert.NoError(t, err) { + assert.Equal(t, fixedpoint.NewFromFloat(19602.0), currentPrice) + assert.Equal(t, fixedpoint.NewFromFloat(19602.0), stop.latestHigh) + assert.True(t, stop.activated) + } + + // 19602 + 1% = 19798.02 + currentPrice = currentPrice.Mul(one.Add(callbackRatio)) + err = stop.checkStopPrice(currentPrice, position) + if assert.NoError(t, err) { + assert.Equal(t, fixedpoint.NewFromFloat(19798.02), currentPrice) + assert.Equal(t, fixedpoint.NewFromFloat(19602.0), stop.latestHigh) + assert.True(t, stop.activated) + } +} diff --git a/pkg/bbgo/session.go b/pkg/bbgo/session.go index c6796c8f1..87bea4fe1 100644 --- a/pkg/bbgo/session.go +++ b/pkg/bbgo/session.go @@ -160,10 +160,6 @@ func (set *StandardIndicatorSet) VOLATILITY(iw types.IntervalWindow) *indicator. // ExchangeSession presents the exchange connection Session // It also maintains and collects the data returned from the stream. type ExchangeSession struct { - // exchange Session based notification system - // we make it as a value field so that we can configure it separately - Notifiability `json:"-" yaml:"-"` - // --------------------------- // Session config fields // --------------------------- @@ -253,12 +249,6 @@ func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession { marketDataStream.SetPublicOnly() session := &ExchangeSession{ - Notifiability: Notifiability{ - SymbolChannelRouter: NewPatternChannelRouter(nil), - SessionChannelRouter: NewPatternChannelRouter(nil), - ObjectChannelRouter: NewObjectChannelRouter(), - }, - Name: name, Exchange: exchange, UserDataStream: userDataStream, @@ -282,8 +272,7 @@ func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession { session.OrderExecutor = &ExchangeOrderExecutor{ // copy the notification system so that we can route - Notifiability: session.Notifiability, - Session: session, + Session: session, } return session @@ -805,11 +794,6 @@ func (session *ExchangeSession) InitExchange(name string, ex types.Exchange) err } session.Name = name - session.Notifiability = Notifiability{ - SymbolChannelRouter: NewPatternChannelRouter(nil), - SessionChannelRouter: NewPatternChannelRouter(nil), - ObjectChannelRouter: NewObjectChannelRouter(), - } session.Exchange = ex session.UserDataStream = ex.NewStream() session.MarketDataStream = ex.NewStream() @@ -830,8 +814,7 @@ func (session *ExchangeSession) InitExchange(name string, ex types.Exchange) err session.orderStores = make(map[string]*OrderStore) session.OrderExecutor = &ExchangeOrderExecutor{ // copy the notification system so that we can route - Notifiability: session.Notifiability, - Session: session, + Session: session, } session.usedSymbols = make(map[string]struct{}) diff --git a/pkg/strategy/pivotshort/strategy.go b/pkg/strategy/pivotshort/strategy.go index 3e011a75a..1d9acf8b6 100644 --- a/pkg/strategy/pivotshort/strategy.go +++ b/pkg/strategy/pivotshort/strategy.go @@ -46,13 +46,10 @@ type SupportTakeProfit struct { } func (s *SupportTakeProfit) Subscribe(session *bbgo.ExchangeSession) { - log.Infof("[supportTakeProfit] Subscribe(%s, %s)", s.Symbol, s.Interval) session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval}) } func (s *SupportTakeProfit) Bind(session *bbgo.ExchangeSession, orderExecutor *bbgo.GeneralOrderExecutor) { - log.Infof("[supportTakeProfit] Bind(%s, %s)", s.Symbol, s.Interval) - s.session = session s.orderExecutor = orderExecutor s.activeOrders = bbgo.NewActiveOrderBook(s.Symbol)