mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
add per-session-based trade reporter
This commit is contained in:
parent
678e4ef4ab
commit
ea3e9e7d05
|
@ -1,10 +1,30 @@
|
||||||
---
|
---
|
||||||
notifier:
|
notifications:
|
||||||
slack:
|
slack:
|
||||||
|
defaultChannel: "bbgo"
|
||||||
errorChannel: "bbgo-error"
|
errorChannel: "bbgo-error"
|
||||||
|
|
||||||
exchange:
|
reportTrades:
|
||||||
binance:
|
channelBySymbol:
|
||||||
target: binance
|
"btcusdt": "bbgo-btcusdt"
|
||||||
|
"ethusdt": "bbgo-ethusdt"
|
||||||
|
"bnbusdt": "bbgo-bnbusdt"
|
||||||
|
"sxpusdt": "bbgo-sxpusdt"
|
||||||
|
|
||||||
|
sessions:
|
||||||
max:
|
max:
|
||||||
target: max
|
exchange: max
|
||||||
|
keyVar: MAX_API_KEY
|
||||||
|
secretVar: MAX_API_SECRET
|
||||||
|
binance:
|
||||||
|
exchange: binance
|
||||||
|
keyVar: BINANCE_API_KEY
|
||||||
|
secretVar: BINANCE_API_SECRET
|
||||||
|
|
||||||
|
exchangeStrategies:
|
||||||
|
- on: binance
|
||||||
|
buyandhold:
|
||||||
|
symbol: "BTCUSDT"
|
||||||
|
interval: "1m"
|
||||||
|
baseQuantity: 0.1
|
||||||
|
minDropPercentage: -0.05
|
||||||
|
|
|
@ -146,7 +146,11 @@ func (environ *Environment) Init(ctx context.Context) (err error) {
|
||||||
|
|
||||||
session.markets = markets
|
session.markets = markets
|
||||||
|
|
||||||
if environ.tradeReporter != nil {
|
if session.tradeReporter != nil {
|
||||||
|
session.Stream.OnTrade(func(trade types.Trade) {
|
||||||
|
session.tradeReporter.Report(trade)
|
||||||
|
})
|
||||||
|
} else if environ.tradeReporter != nil {
|
||||||
session.Stream.OnTrade(func(trade types.Trade) {
|
session.Stream.OnTrade(func(trade types.Trade) {
|
||||||
environ.tradeReporter.Report(trade)
|
environ.tradeReporter.Report(trade)
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,3 +14,17 @@ func (n *NullNotifier) NotifyTo(channel, format string, args ...interface{}) err
|
||||||
func (n *NullNotifier) Notify(format string, args ...interface{}) error {
|
func (n *NullNotifier) Notify(format string, args ...interface{}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Notifiability struct {
|
||||||
|
notifiers []Notifier
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Notifiability) AddNotifier(notifier Notifier) {
|
||||||
|
m.notifiers = append(m.notifiers, notifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Notifiability) Notify(msg string, args ...interface{}) {
|
||||||
|
for _, n := range m.notifiers {
|
||||||
|
n.NotifyTo("", msg, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ type ExchangeSession struct {
|
||||||
Trades map[string][]types.Trade
|
Trades map[string][]types.Trade
|
||||||
|
|
||||||
marketDataStores map[string]*store.MarketDataStore
|
marketDataStores map[string]*store.MarketDataStore
|
||||||
|
|
||||||
|
tradeReporter *TradeReporter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
|
func NewExchangeSession(name string, exchange types.Exchange) *ExchangeSession {
|
||||||
|
@ -63,6 +65,11 @@ func (session *ExchangeSession) Market(symbol string) (market types.Market, ok b
|
||||||
return market, ok
|
return market, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (session *ExchangeSession) ReportTrade(notifier Notifier) *TradeReporter {
|
||||||
|
session.tradeReporter = NewTradeReporter(notifier)
|
||||||
|
return session.tradeReporter
|
||||||
|
}
|
||||||
|
|
||||||
// Subscribe save the subscription info, later it will be assigned to the stream
|
// Subscribe save the subscription info, later it will be assigned to the stream
|
||||||
func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession {
|
func (session *ExchangeSession) Subscribe(channel types.Channel, symbol string, options types.SubscribeOptions) *ExchangeSession {
|
||||||
sub := types.Subscription{
|
sub := types.Subscription{
|
||||||
|
|
|
@ -31,22 +31,9 @@ type CrossExchangeStrategy interface {
|
||||||
Run(ctx context.Context, orderExecutionRouter types.OrderExecutionRouter, sessions map[string]*ExchangeSession) error
|
Run(ctx context.Context, orderExecutionRouter types.OrderExecutionRouter, sessions map[string]*ExchangeSession) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Notifiability struct {
|
|
||||||
notifiers []Notifier
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Notifiability) AddNotifier(notifier Notifier) {
|
|
||||||
m.notifiers = append(m.notifiers, notifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Notifiability) Notify(msg string, args ...interface{}) {
|
|
||||||
for _, n := range m.notifiers {
|
|
||||||
n.NotifyTo("", msg, args...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Trader struct {
|
type Trader struct {
|
||||||
Notifiability
|
Notifiability
|
||||||
|
|
||||||
environment *Environment
|
environment *Environment
|
||||||
|
|
||||||
crossExchangeStrategies []CrossExchangeStrategy
|
crossExchangeStrategies []CrossExchangeStrategy
|
||||||
|
|
Loading…
Reference in New Issue
Block a user