2020-10-27 05:54:39 +00:00
|
|
|
package pricealert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/c9s/bbgo/pkg/bbgo"
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
2022-02-15 05:55:19 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
2020-10-27 05:54:39 +00:00
|
|
|
)
|
|
|
|
|
2021-02-03 01:08:05 +00:00
|
|
|
const ID = "pricealert"
|
|
|
|
|
2020-10-27 05:54:39 +00:00
|
|
|
func init() {
|
2021-02-03 01:08:05 +00:00
|
|
|
bbgo.RegisterStrategy(ID, &Strategy{})
|
2020-10-27 05:54:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Strategy struct {
|
2020-10-27 07:51:36 +00:00
|
|
|
// The notification system will be injected into the strategy automatically.
|
2022-03-06 08:09:15 +00:00
|
|
|
*bbgo.Notifiability
|
2020-10-27 05:54:39 +00:00
|
|
|
|
2020-10-27 07:51:36 +00:00
|
|
|
// These fields will be filled from the config file (it translates YAML to JSON)
|
2022-02-15 05:55:19 +00:00
|
|
|
Symbol string `json:"symbol"`
|
|
|
|
Interval string `json:"interval"`
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
MinChange fixedpoint.Value `json:"minChange"`
|
2020-10-27 05:54:39 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 01:08:05 +00:00
|
|
|
func (s *Strategy) ID() string {
|
|
|
|
return ID
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:49:49 +00:00
|
|
|
func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
2020-10-27 05:54:39 +00:00
|
|
|
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.Interval})
|
2020-10-28 09:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
2021-05-27 19:15:29 +00:00
|
|
|
session.MarketDataStream.OnKLine(func(kline types.KLine) {
|
2020-10-27 05:54:39 +00:00
|
|
|
market, ok := session.Market(kline.Symbol)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
if kline.GetChange().Abs().Compare(s.MinChange) > 0 {
|
2020-10-27 05:54:39 +00:00
|
|
|
if channel, ok := s.RouteSymbol(s.Symbol); ok {
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.NotifyTo(channel, "%s hit price %s, change %v", s.Symbol, market.FormatPrice(kline.Close), kline.GetChange())
|
2020-10-27 05:54:39 +00:00
|
|
|
} else {
|
fix bollgrid, emstop, flashcrash, funding, grid, pricealert, pricedrop, rebalance, schedule, swing, xbalance, xgap, xmaker and speedup fixedpoint
2022-02-04 11:39:23 +00:00
|
|
|
s.Notify("%s hit price %s, change %v", s.Symbol, market.FormatPrice(kline.Close), kline.GetChange())
|
2020-10-27 05:54:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|