use types.PriceVolume

This commit is contained in:
kbearXD 2024-05-21 16:06:02 +08:00
parent 6676e1e452
commit 0faef68fbf
4 changed files with 9 additions and 53 deletions

View File

@ -11,6 +11,11 @@ import (
"github.com/sirupsen/logrus"
)
type Round struct {
OpenPositionOrders []types.Order
TakeProfitOrder types.Order
}
type Collector struct {
logger *logrus.Entry
symbol string

View File

@ -34,12 +34,12 @@ func (s *Strategy) placeOpenPositionOrders(ctx context.Context) error {
s.debugOrders(createdOrders)
// store price quantity pairs into persistence
var pqs []PriceQuantity
var pvs []types.PriceVolume
for _, createdOrder := range createdOrders {
pqs = append(pqs, PriceQuantity{Price: createdOrder.Price, Quantity: createdOrder.Quantity})
pvs = append(pvs, types.PriceVolume{Price: createdOrder.Price, Volume: createdOrder.Quantity})
}
s.ProfitStats.OpenPositionPQs = pqs
s.ProfitStats.OpenPositionPVs = pvs
bbgo.Sync(ctx, s)

View File

@ -8,11 +8,6 @@ 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"`
@ -27,7 +22,7 @@ type ProfitStats struct {
TotalFee map[string]fixedpoint.Value `json:"totalFee,omitempty"`
// used to flexible recovery
OpenPositionPQs []PriceQuantity `json:"openPositionPQs,omitempty"`
OpenPositionPVs []types.PriceVolume `json:"openPositionPVs,omitempty"`
types.PersistenceTTL
}

View File

@ -194,47 +194,3 @@ func recoverStartTimeOfNextRound(ctx context.Context, currentRound Round, coolDo
return time.Time{}
}
type Round struct {
OpenPositionOrders []types.Order
TakeProfitOrder types.Order
}
func getCurrentRoundOrders(openOrders, closedOrders []types.Order, groupID uint32) (Round, error) {
openPositionSide := types.SideTypeBuy
takeProfitSide := types.SideTypeSell
var allOrders []types.Order
allOrders = append(allOrders, openOrders...)
allOrders = append(allOrders, closedOrders...)
types.SortOrdersDescending(allOrders)
var currentRound Round
lastSide := takeProfitSide
for _, order := range allOrders {
// group id filter is used for debug when local running
if order.GroupID != groupID {
continue
}
if order.Side == takeProfitSide && lastSide == openPositionSide {
break
}
switch order.Side {
case openPositionSide:
currentRound.OpenPositionOrders = append(currentRound.OpenPositionOrders, order)
case takeProfitSide:
if currentRound.TakeProfitOrder.OrderID != 0 {
return currentRound, fmt.Errorf("there are two take-profit orders in one round, please check it")
}
currentRound.TakeProfitOrder = order
default:
}
lastSide = order.Side
}
return currentRound, nil
}