mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
xmaker: add back profit function
This commit is contained in:
parent
a31e2743ee
commit
1fa03cdfd6
|
@ -6,8 +6,9 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/util"
|
||||
)
|
||||
|
||||
// ApiClient defines the request builder method and request method for the API service
|
||||
|
@ -16,7 +17,7 @@ type ApiClient interface {
|
|||
NewAuthenticatedRequest(method, refURL string, params url.Values, payload interface{}) (*http.Request, error)
|
||||
|
||||
// NewRequest builds up the http request for public endpoints
|
||||
NewRequest(method, refURL string, params url.Values, body []byte) (*http.Request, error)
|
||||
NewRequest(method, refURL string, params url.Values, payload []byte) (*http.Request, error)
|
||||
|
||||
// SendRequest sends the request object to the api gateway
|
||||
SendRequest(req *http.Request) (*util.Response, error)
|
||||
|
|
|
@ -766,6 +766,21 @@ func (s *Strategy) CrossRun(ctx context.Context, orderExecutionRouter bbgo.Order
|
|||
log.WithError(err).Error("save state error")
|
||||
}
|
||||
})
|
||||
s.tradeCollector.OnProfit(func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value) {
|
||||
p := bbgo.Profit{
|
||||
Symbol: s.Symbol,
|
||||
Profit: profit,
|
||||
NetProfit: netProfit,
|
||||
TradeAmount: fixedpoint.NewFromFloat(trade.QuoteQuantity),
|
||||
ProfitMargin: profit.DivFloat64(trade.QuoteQuantity),
|
||||
NetProfitMargin: netProfit.DivFloat64(trade.QuoteQuantity),
|
||||
QuoteCurrency: s.state.Position.QuoteCurrency,
|
||||
BaseCurrency: s.state.Position.BaseCurrency,
|
||||
Time: trade.Time.Time(),
|
||||
}
|
||||
s.state.ProfitStats.AddProfit(p)
|
||||
s.Notify(&p)
|
||||
})
|
||||
s.tradeCollector.OnPositionUpdate(func(position *types.Position) {
|
||||
s.Notifiability.Notify(position)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user