mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
pkg/exchange: avoiding GC panic caused by a rapid creation/removal slice of pointers
This commit is contained in:
parent
f664ef2262
commit
b27395f6f4
|
@ -33,8 +33,8 @@ type Stream struct {
|
|||
types.StandardStream
|
||||
|
||||
bookEventCallbacks []func(e BookEvent)
|
||||
walletEventCallbacks []func(e []*WalletEvent)
|
||||
orderEventCallbacks []func(e []*OrderEvent)
|
||||
walletEventCallbacks []func(e []WalletEvent)
|
||||
orderEventCallbacks []func(e []OrderEvent)
|
||||
}
|
||||
|
||||
func NewStream(key, secret string) *Stream {
|
||||
|
@ -77,10 +77,10 @@ func (s *Stream) dispatchEvent(event interface{}) {
|
|||
case *BookEvent:
|
||||
s.EmitBookEvent(*e)
|
||||
|
||||
case []*WalletEvent:
|
||||
case []WalletEvent:
|
||||
s.EmitWalletEvent(e)
|
||||
|
||||
case []*OrderEvent:
|
||||
case []OrderEvent:
|
||||
s.EmitOrderEvent(e)
|
||||
}
|
||||
}
|
||||
|
@ -110,11 +110,11 @@ func (s *Stream) parseWebSocketEvent(in []byte) (interface{}, error) {
|
|||
return &book, nil
|
||||
|
||||
case TopicTypeWallet:
|
||||
var wallets []*WalletEvent
|
||||
var wallets []WalletEvent
|
||||
return wallets, json.Unmarshal(e.WebSocketTopicEvent.Data, &wallets)
|
||||
|
||||
case TopicTypeOrder:
|
||||
var orders []*OrderEvent
|
||||
var orders []OrderEvent
|
||||
return orders, json.Unmarshal(e.WebSocketTopicEvent.Data, &orders)
|
||||
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ func (s *Stream) handleBookEvent(e BookEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Stream) handleWalletEvent(events []*WalletEvent) {
|
||||
func (s *Stream) handleWalletEvent(events []WalletEvent) {
|
||||
bm := types.BalanceMap{}
|
||||
for _, event := range events {
|
||||
if event.AccountType != AccountTypeSpot {
|
||||
|
@ -258,7 +258,7 @@ func (s *Stream) handleWalletEvent(events []*WalletEvent) {
|
|||
s.StandardStream.EmitBalanceSnapshot(bm)
|
||||
}
|
||||
|
||||
func (s *Stream) handleOrderEvent(events []*OrderEvent) {
|
||||
func (s *Stream) handleOrderEvent(events []OrderEvent) {
|
||||
for _, event := range events {
|
||||
if event.Category != bybitapi.CategorySpot {
|
||||
return
|
||||
|
|
|
@ -14,21 +14,21 @@ func (s *Stream) EmitBookEvent(e BookEvent) {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Stream) OnWalletEvent(cb func(e []*WalletEvent)) {
|
||||
func (s *Stream) OnWalletEvent(cb func(e []WalletEvent)) {
|
||||
s.walletEventCallbacks = append(s.walletEventCallbacks, cb)
|
||||
}
|
||||
|
||||
func (s *Stream) EmitWalletEvent(e []*WalletEvent) {
|
||||
func (s *Stream) EmitWalletEvent(e []WalletEvent) {
|
||||
for _, cb := range s.walletEventCallbacks {
|
||||
cb(e)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Stream) OnOrderEvent(cb func(e []*OrderEvent)) {
|
||||
func (s *Stream) OnOrderEvent(cb func(e []OrderEvent)) {
|
||||
s.orderEventCallbacks = append(s.orderEventCallbacks, cb)
|
||||
}
|
||||
|
||||
func (s *Stream) EmitOrderEvent(e []*OrderEvent) {
|
||||
func (s *Stream) EmitOrderEvent(e []OrderEvent) {
|
||||
for _, cb := range s.orderEventCallbacks {
|
||||
cb(e)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user