FEATURE: [dca2] store price quantity pairs of the open-position orders into persistence

This commit is contained in:
kbearXD 2024-05-20 14:37:23 +08:00
parent 970c1bb8c7
commit 6676e1e452
2 changed files with 19 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/c9s/bbgo/pkg/bbgo"
"github.com/c9s/bbgo/pkg/exchange/retry"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
@ -32,6 +33,16 @@ func (s *Strategy) placeOpenPositionOrders(ctx context.Context) error {
s.debugOrders(createdOrders)
// store price quantity pairs into persistence
var pqs []PriceQuantity
for _, createdOrder := range createdOrders {
pqs = append(pqs, PriceQuantity{Price: createdOrder.Price, Quantity: createdOrder.Quantity})
}
s.ProfitStats.OpenPositionPQs = pqs
bbgo.Sync(ctx, s)
return nil
}

View File

@ -8,6 +8,11 @@ import (
"github.com/c9s/bbgo/pkg/types"
)
type PriceQuantity struct {
Price fixedpoint.Value `json:"price,omitempty"`
Quantity fixedpoint.Value `json:"quantity,omitempty"`
}
type ProfitStats struct {
Symbol string `json:"symbol"`
Market types.Market `json:"market,omitempty"`
@ -21,6 +26,9 @@ type ProfitStats struct {
TotalProfit fixedpoint.Value `json:"totalProfit,omitempty"`
TotalFee map[string]fixedpoint.Value `json:"totalFee,omitempty"`
// used to flexible recovery
OpenPositionPQs []PriceQuantity `json:"openPositionPQs,omitempty"`
types.PersistenceTTL
}