mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
use types.PriceVolume
This commit is contained in:
parent
6676e1e452
commit
0faef68fbf
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user