Merge pull request #742 from c9s/improve/notify-api

refactor: clean up bbgo.Notifiability
This commit is contained in:
Yo-An Lin 2022-06-19 13:11:10 +08:00 committed by GitHub
commit bce64df7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 4 additions and 45 deletions

View File

@ -68,18 +68,18 @@ func (e *GeneralOrderExecutor) BindProfitStats(profitStats *types.ProfitStats) {
})
}
func (e *GeneralOrderExecutor) Bind(notify NotifyFunc) {
func (e *GeneralOrderExecutor) Bind() {
e.activeMakerOrders.BindStream(e.session.UserDataStream)
e.orderStore.BindStream(e.session.UserDataStream)
// trade notify
e.tradeCollector.OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
notify(trade)
Notify(trade)
})
e.tradeCollector.OnPositionUpdate(func(position *types.Position) {
log.Infof("position changed: %s", position)
notify(position)
Notify(position)
})
e.tradeCollector.BindStream(e.session.UserDataStream)

View File

@ -50,8 +50,6 @@ type MarginAsset struct {
}
type Strategy struct {
*bbgo.Notifiability
Interval types.Interval `json:"interval"`
MinMarginLevel fixedpoint.Value `json:"minMarginLevel"`
MaxMarginLevel fixedpoint.Value `json:"maxMarginLevel"`

View File

@ -25,10 +25,6 @@ func init() {
}
type Strategy struct {
// The notification system will be injected into the strategy automatically.
// This field will be injected automatically since it's a single exchange strategy.
*bbgo.Notifiability
// OrderExecutor is an interface for submitting order.
// This field will be injected automatically since it's a single exchange strategy.
bbgo.OrderExecutor

View File

@ -51,7 +51,6 @@ type BollingerSetting struct {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -48,7 +48,6 @@ func (b BudgetPeriod) Duration() time.Duration {
// Strategy is the Dollar-Cost-Average strategy
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -27,10 +27,6 @@ func init() {
type Strategy struct {
*bbgo.Graceful
// The notification system will be injected into the strategy automatically.
// This field will be injected automatically since it's a single exchange strategy.
*bbgo.Notifiability
SourceExchangeName string `json:"sourceExchange"`
TargetExchangeName string `json:"targetExchange"`

View File

@ -22,8 +22,6 @@ func init() {
type Strategy struct {
Market types.Market
Notifiability *bbgo.Notifiability
TotalAmount fixedpoint.Value `json:"totalAmount,omitempty"`
// Interval is the period that you want to submit order

View File

@ -32,7 +32,6 @@ type IntervalWindowSetting struct {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -27,7 +27,6 @@ func init() {
}
type Strategy struct {
*bbgo.Notifiability
// These fields will be filled from the config file (it translates YAML to JSON)
Symbol string `json:"symbol"`
Market types.Market `json:"-"`

View File

@ -45,10 +45,6 @@ type State struct {
}
type Strategy struct {
// The notification system will be injected into the strategy automatically.
// This field will be injected automatically since it's a single exchange strategy.
*bbgo.Notifiability `json:"-" yaml:"-"`
*bbgo.Graceful `json:"-" yaml:"-"`
*bbgo.Persistence

View File

@ -78,7 +78,6 @@ type Exit struct {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment
@ -204,7 +203,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.orderExecutor.BindEnvironment(s.Environment)
s.orderExecutor.BindProfitStats(s.ProfitStats)
s.orderExecutor.BindTradeStats(s.TradeStats)
s.orderExecutor.Bind(s.Notifiability.Notify)
s.orderExecutor.Bind()
store, _ := session.MarketDataStore(s.Symbol)

View File

@ -15,9 +15,6 @@ func init() {
}
type Strategy struct {
// The notification system will be injected into the strategy automatically.
*bbgo.Notifiability
// These fields will be filled from the config file (it translates YAML to JSON)
Symbol string `json:"symbol"`
Interval types.Interval `json:"interval"`

View File

@ -20,8 +20,6 @@ func init() {
}
type Strategy struct {
Notifiability *bbgo.Notifiability
Interval types.Interval `json:"interval"`
BaseCurrency string `json:"baseCurrency"`
TargetWeights types.ValueMap `json:"targetWeights"`

View File

@ -19,8 +19,6 @@ func init() {
type Strategy struct {
Market types.Market
Notifiability *bbgo.Notifiability
// StandardIndicatorSet contains the standard indicators of a market (symbol)
// This field will be injected automatically since we defined the Symbol field.
*bbgo.StandardIndicatorSet

View File

@ -29,7 +29,6 @@ func init() {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -130,7 +130,6 @@ func (control *TrailingStopControl) GenerateStopOrder(quantity fixedpoint.Value)
// }
type Strategy struct {
*bbgo.Notifiability `json:"-"`
*bbgo.Persistence
*bbgo.Graceful `json:"-"`

View File

@ -26,10 +26,6 @@ func init() {
}
type Strategy struct {
// The notification system will be injected into the strategy automatically.
// This field will be injected automatically since it's a single exchange strategy.
*bbgo.Notifiability
// OrderExecutor is an interface for submitting order.
// This field will be injected automatically since it's a single exchange strategy.
bbgo.OrderExecutor

View File

@ -28,8 +28,6 @@ func init() {
}
type Strategy struct {
*bbgo.Notifiability
// These fields will be filled from the config file (it translates YAML to JSON)
Symbol string `json:"symbol"`
Market types.Market `json:"-"`

View File

@ -31,7 +31,6 @@ func init() {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -136,7 +136,6 @@ func (a *Address) UnmarshalJSON(body []byte) error {
}
type Strategy struct {
Notifiability *bbgo.Notifiability
*bbgo.Graceful
*bbgo.Persistence

View File

@ -58,7 +58,6 @@ func (s *State) Reset() {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Symbol string `json:"symbol"`

View File

@ -34,7 +34,6 @@ func init() {
type Strategy struct {
*bbgo.Graceful
*bbgo.Notifiability
*bbgo.Persistence
Environment *bbgo.Environment

View File

@ -58,7 +58,6 @@ func (s *State) Reset() {
}
type Strategy struct {
Notifiability *bbgo.Notifiability
*bbgo.Graceful
*bbgo.Persistence
*bbgo.Environment