2020-10-18 04:24:21 +00:00
|
|
|
package backtest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-05-07 16:14:25 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-11-06 18:57:50 +00:00
|
|
|
|
2020-10-18 04:24:21 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
|
|
|
)
|
|
|
|
|
2021-05-07 16:14:25 +00:00
|
|
|
var log = logrus.WithField("cmd", "backtest")
|
|
|
|
|
2020-10-18 04:24:21 +00:00
|
|
|
type Stream struct {
|
|
|
|
types.StandardStream
|
2020-11-06 18:57:50 +00:00
|
|
|
|
|
|
|
exchange *Exchange
|
2020-10-18 04:24:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Stream) Connect(ctx context.Context) error {
|
2021-12-25 14:57:28 +00:00
|
|
|
if s.PublicOnly {
|
|
|
|
if s.exchange.marketDataStream != nil {
|
|
|
|
panic("you should not set up more than 1 market data stream in back-test")
|
2021-05-30 07:08:11 +00:00
|
|
|
}
|
2021-12-25 14:57:28 +00:00
|
|
|
s.exchange.marketDataStream = s
|
|
|
|
} else {
|
2021-05-30 07:08:11 +00:00
|
|
|
|
|
|
|
// assign user data stream back
|
2021-12-25 14:57:28 +00:00
|
|
|
if s.exchange.userDataStream != nil {
|
|
|
|
panic("you should not set up more than 1 user data stream in back-test")
|
|
|
|
}
|
2021-05-30 07:08:11 +00:00
|
|
|
s.exchange.userDataStream = s
|
|
|
|
}
|
|
|
|
|
2021-12-25 14:37:38 +00:00
|
|
|
s.EmitConnect()
|
|
|
|
s.EmitStart()
|
|
|
|
return nil
|
|
|
|
}
|
2020-11-07 12:11:07 +00:00
|
|
|
|
2020-10-18 04:24:21 +00:00
|
|
|
func (s *Stream) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|