bbgo_origin/pkg/bbgo/tradecollector_callbacks.go

49 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-06-24 07:38:44 +00:00
// Code generated by "callbackgen -type TradeCollector"; DO NOT EDIT.
package bbgo
import (
"github.com/c9s/bbgo/pkg/fixedpoint"
2021-06-24 07:38:44 +00:00
"github.com/c9s/bbgo/pkg/types"
)
func (c *TradeCollector) OnRecover(cb func(trade types.Trade)) {
c.recoverCallbacks = append(c.recoverCallbacks, cb)
}
func (c *TradeCollector) EmitRecover(trade types.Trade) {
for _, cb := range c.recoverCallbacks {
cb(trade)
}
}
2022-03-11 13:27:45 +00:00
func (c *TradeCollector) OnTrade(cb func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value)) {
2021-06-24 07:38:44 +00:00
c.tradeCallbacks = append(c.tradeCallbacks, cb)
}
2022-03-11 13:27:45 +00:00
func (c *TradeCollector) EmitTrade(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
2021-06-24 07:38:44 +00:00
for _, cb := range c.tradeCallbacks {
2022-03-11 13:27:45 +00:00
cb(trade, profit, netProfit)
2021-06-24 07:38:44 +00:00
}
}
func (c *TradeCollector) OnPositionUpdate(cb func(position *types.Position)) {
2021-06-24 07:38:44 +00:00
c.positionUpdateCallbacks = append(c.positionUpdateCallbacks, cb)
}
func (c *TradeCollector) EmitPositionUpdate(position *types.Position) {
2021-06-24 07:38:44 +00:00
for _, cb := range c.positionUpdateCallbacks {
cb(position)
}
}
func (c *TradeCollector) OnProfit(cb func(trade types.Trade, profit *types.Profit)) {
c.profitCallbacks = append(c.profitCallbacks, cb)
}
func (c *TradeCollector) EmitProfit(trade types.Trade, profit *types.Profit) {
for _, cb := range c.profitCallbacks {
cb(trade, profit)
}
}