mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1648 from c9s/narumi/atrpin-expected-baes-balance
FEATURE: [atrpin] take profit by expected base balance
This commit is contained in:
commit
3007fa7ed7
|
@ -33,6 +33,10 @@ type Strategy struct {
|
||||||
Multiplier float64 `json:"multiplier"`
|
Multiplier float64 `json:"multiplier"`
|
||||||
MinPriceRange fixedpoint.Value `json:"minPriceRange"`
|
MinPriceRange fixedpoint.Value `json:"minPriceRange"`
|
||||||
|
|
||||||
|
// handle missing trades, will be removed in the future
|
||||||
|
TakeProfitByExpectedBaseBalance bool `json:"takeProfitByExpectedBaseBalance"`
|
||||||
|
ExpectedBaseBalance fixedpoint.Value `json:"expectedBaseBalance"`
|
||||||
|
|
||||||
bbgo.QuantityOrAmount
|
bbgo.QuantityOrAmount
|
||||||
// bbgo.OpenPositionOptions
|
// bbgo.OpenPositionOptions
|
||||||
|
|
||||||
|
@ -50,6 +54,14 @@ func (s *Strategy) Initialize() error {
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Strategy) Validate() error {
|
||||||
|
if s.ExpectedBaseBalance.Sign() < 0 {
|
||||||
|
return fmt.Errorf("expectedBaseBalance should be non-negative")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Strategy) ID() string {
|
func (s *Strategy) ID() string {
|
||||||
return ID
|
return ID
|
||||||
}
|
}
|
||||||
|
@ -136,14 +148,19 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
position := s.Strategy.OrderExecutor.Position()
|
position := s.Strategy.OrderExecutor.Position()
|
||||||
s.logger.Infof("position: %+v", position)
|
s.logger.Infof("position: %+v", position)
|
||||||
|
|
||||||
side := types.SideTypeBuy
|
base := position.GetBase()
|
||||||
takerPrice := ticker.Sell
|
if s.TakeProfitByExpectedBaseBalance {
|
||||||
if position.IsLong() {
|
base = baseBalance.Available.Sub(s.ExpectedBaseBalance)
|
||||||
side = types.SideTypeSell
|
|
||||||
takerPrice = ticker.Buy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !position.IsDust(takerPrice) {
|
side := types.SideTypeSell
|
||||||
|
takerPrice := ticker.Buy
|
||||||
|
if base.Sign() < 0 {
|
||||||
|
side = types.SideTypeBuy
|
||||||
|
takerPrice = ticker.Sell
|
||||||
|
}
|
||||||
|
|
||||||
|
if !s.Market.IsDustQuantity(base, takerPrice) {
|
||||||
s.logger.Infof("%s position is not dust", s.Symbol)
|
s.logger.Infof("%s position is not dust", s.Symbol)
|
||||||
|
|
||||||
orderForms = append(orderForms, types.SubmitOrder{
|
orderForms = append(orderForms, types.SubmitOrder{
|
||||||
|
@ -151,7 +168,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
Type: types.OrderTypeLimit,
|
Type: types.OrderTypeLimit,
|
||||||
Side: side,
|
Side: side,
|
||||||
Price: takerPrice,
|
Price: takerPrice,
|
||||||
Quantity: position.GetQuantity(),
|
Quantity: base.Abs(),
|
||||||
Market: s.Market,
|
Market: s.Market,
|
||||||
TimeInForce: types.TimeInForceGTC,
|
TimeInForce: types.TimeInForceGTC,
|
||||||
Tag: "takeProfit",
|
Tag: "takeProfit",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user