Skip to content

Commit

Permalink
Merge pull request #1839 from c9s/kbearXD/max/make-subscription-filte…
Browse files Browse the repository at this point in the history
…rs-not-empty

FEATURE: [max] subscription filters not empty
  • Loading branch information
c9s authored Nov 27, 2024
2 parents 8dbf6d5 + aa21d89 commit 1a8820d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/exchange/max/maxapi/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func ParseUserEvent(v *fastjson.Value) (interface{}, error) {
case "trade_snapshot", "mwallet_trade_snapshot":
return parseTradeSnapshotEvent(v)

case "trade_update", "mwallet_trade_update":
case "trade_update", "trade_fast_update", "mwallet_trade_update":
return parseTradeUpdateEvent(v)

case "ad_ratio_snapshot", "ad_ratio_update":
Expand Down
22 changes: 15 additions & 7 deletions pkg/exchange/max/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,21 @@ func (s *Stream) handleConnect() {
if len(s.privateChannels) > 0 {
// TODO: maybe check the valid private channels
filters = s.privateChannels
} else if s.MarginSettings.IsMargin {
filters = []string{
"mwallet_order",
"mwallet_trade",
"mwallet_account",
"ad_ratio",
"borrowing",
} else {
if s.MarginSettings.IsMargin {
filters = []string{
"mwallet_order",
"mwallet_trade",
"mwallet_account",
"ad_ratio",
"borrowing",
}
} else {
filters = []string{
"order",
"trade",
"account",
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/strategy/xalign/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
// bind on trade to update price
session.UserDataStream.OnTradeUpdate(s.priceResolver.UpdateFromTrade)
}
log.Infof("large amount alert: %+v", s.LargeAmountAlert)

bbgo.OnShutdown(ctx, func(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
Expand Down Expand Up @@ -597,6 +598,7 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange
if price, ok := s.priceResolver.ResolvePrice(currency, s.LargeAmountAlert.QuoteCurrency); ok {
quantity := q.Abs()
amount := price.Mul(quantity)
log.Infof("resolved price for currency: %s, price: %f, quantity: %f, amount: %f", currency, price.Float64(), quantity.Float64(), amount.Float64())
if amount.Compare(s.LargeAmountAlert.Amount) > 0 {
alert := &LargeAmountAlert{
QuoteCurrency: s.LargeAmountAlert.QuoteCurrency,
Expand All @@ -616,6 +618,8 @@ func (s *Strategy) align(ctx context.Context, sessions map[string]*bbgo.Exchange

bbgo.Notify(alert)
}
} else {
log.Info("price resolver can not resolve price, skip alert checking")
}
}

Expand Down

0 comments on commit 1a8820d

Please sign in to comment.