receive trade in value instead of pointer

This commit is contained in:
c9s 2020-10-19 22:06:43 +08:00
parent 292dd2492a
commit 822e4c2703
4 changed files with 11 additions and 9 deletions

View File

@ -149,12 +149,12 @@ func (environ *Environment) Connect(ctx context.Context) error {
session.marketDataStores[kline.Symbol].AddKLine(kline)
})
session.Stream.OnTrade(func(trade *types.Trade) {
session.Stream.OnTrade(func(trade types.Trade) {
// append trades
session.Trades[trade.Symbol] = append(session.Trades[trade.Symbol], *trade)
session.Trades[trade.Symbol] = append(session.Trades[trade.Symbol], trade)
if err := environ.TradeService.Insert(*trade); err != nil {
log.WithError(err).Errorf("trade insert error: %+v", *trade)
if err := environ.TradeService.Insert(trade); err != nil {
log.WithError(err).Errorf("trade insert error: %+v", trade)
}
})

View File

@ -134,7 +134,7 @@ func NewStream(client *binance.Client) *Stream {
break
}
stream.EmitTrade(trade)
stream.EmitTrade(*trade)
}
})

View File

@ -2,11 +2,13 @@
package types
func (stream *StandardStream) OnTrade(cb func(trade *Trade)) {
import ()
func (stream *StandardStream) OnTrade(cb func(trade Trade)) {
stream.tradeCallbacks = append(stream.tradeCallbacks, cb)
}
func (stream *StandardStream) EmitTrade(trade *Trade) {
func (stream *StandardStream) EmitTrade(trade Trade) {
for _, cb := range stream.tradeCallbacks {
cb(trade)
}
@ -63,7 +65,7 @@ func (stream *StandardStream) EmitBookSnapshot(book OrderBook) {
}
type StandardStreamEventHub interface {
OnTrade(cb func(trade *Trade))
OnTrade(cb func(trade Trade))
OnBalanceSnapshot(cb func(balances map[string]Balance))

View File

@ -23,7 +23,7 @@ type StandardStream struct {
Subscriptions []Subscription
// private trade callbacks
tradeCallbacks []func(trade *Trade)
tradeCallbacks []func(trade Trade)
// balance snapshot callbacks
balanceSnapshotCallbacks []func(balances map[string]Balance)