浏览代码

Market

- add EnableLongLeverage
- add EnableShortLeverage
Alexey Kim 1 月之前
父节点
当前提交
6a4e6ff318
共有 4 个文件被更改,包括 20 次插入10 次删除
  1. 2 0
      market.go
  2. 4 4
      strategy/alpaca/ppo_20250709/strategy.go
  3. 13 1
      util/order.go
  4. 1 5
      util/strategy.go

+ 2 - 0
market.go

@@ -13,6 +13,8 @@ type Market interface {
 
 
 	Account() (MarketAccount, error)
 	Account() (MarketAccount, error)
 	MaxBudget() float64
 	MaxBudget() float64
+	EnableLongLeverage() bool
+	EnableShortLeverage() bool
 
 
 	CreateOrder(opts OrderCreateOptions) error
 	CreateOrder(opts OrderCreateOptions) error
 	UpdateOrder(orderID string, opts OrderUpdateOptions) error
 	UpdateOrder(orderID string, opts OrderUpdateOptions) error

+ 4 - 4
strategy/alpaca/ppo_20250702/strategy.go → strategy/alpaca/ppo_20250709/strategy.go

@@ -11,11 +11,11 @@ var Strategy = qqq{}
 type qqq struct{}
 type qqq struct{}
 
 
 func (strategy qqq) Name() string {
 func (strategy qqq) Name() string {
-	return "Alpaca: QQQ [TQQQ : QQQ]"
+	return "Alpaca: Hybrid [TQQQ : SQQQ]"
 }
 }
 
 
 func (strategy qqq) Model() string {
 func (strategy qqq) Model() string {
-	return "ppo_20250706"
+	return "ppo_20250709"
 }
 }
 
 
 func (strategy qqq) MarketId() string {
 func (strategy qqq) MarketId() string {
@@ -34,12 +34,12 @@ func (strategy qqq) PositionSymbols() map[sentio.Side]string {
 	return map[sentio.Side]string{
 	return map[sentio.Side]string{
 		sentio.BASE:  "QQQ",
 		sentio.BASE:  "QQQ",
 		sentio.LONG:  "TQQQ",
 		sentio.LONG:  "TQQQ",
-		sentio.SHORT: "QQQ",
+		sentio.SHORT: "SQQQ",
 	}
 	}
 }
 }
 
 
 func (strategy qqq) MaxTradeDuration() time.Duration {
 func (strategy qqq) MaxTradeDuration() time.Duration {
-	return time.Duration(strategy.Interval()) * time.Minute * 15
+	return time.Duration(strategy.Interval()) * time.Minute * 5
 }
 }
 
 
 func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.RiskManager) error {
 func (strategy qqq) Handle(turn *sentio.Turn, market sentio.Market, rs sentio.RiskManager) error {

+ 13 - 1
util/order.go

@@ -21,6 +21,7 @@ func NewOrder(
 ) (opts sentio.OrderCreateOptions, err error) {
 ) (opts sentio.OrderCreateOptions, err error) {
 	var (
 	var (
 		side sentio.Side
 		side sentio.Side
+		base string
 		bid  float64
 		bid  float64
 		ok   bool
 		ok   bool
 	)
 	)
@@ -30,8 +31,19 @@ func NewOrder(
 		return
 		return
 	}
 	}
 
 
+	if base, ok = s.PositionSymbols()[sentio.BASE]; !ok {
+		err = errors.New("`CreateOrder`: unknown `sentio.BASE`")
+		return
+	}
+
 	if opts.Symbol, ok = s.PositionSymbols()[side]; !ok {
 	if opts.Symbol, ok = s.PositionSymbols()[side]; !ok {
 		err = errors.New("`CreateOrder`: unknown Side for the current strategy")
 		err = errors.New("`CreateOrder`: unknown Side for the current strategy")
+		return
+	}
+
+	canLeverage := (side == sentio.LONG && m.EnableLongLeverage()) || (side == sentio.SHORT && m.EnableShortLeverage())
+	if !canLeverage {
+		opts.Symbol = base
 	}
 	}
 
 
 	bid = sentio.ToFixed(quotes[opts.Symbol].BidPrice, 2)
 	bid = sentio.ToFixed(quotes[opts.Symbol].BidPrice, 2)
@@ -53,7 +65,7 @@ func NewOrder(
 	}
 	}
 
 
 	// Invert OrderOptions if we will do SHORT for BASE symbol
 	// Invert OrderOptions if we will do SHORT for BASE symbol
-	if sentio.SHORT == side && s.PositionSymbols()[sentio.BASE] == opts.Symbol {
+	if sentio.SHORT == side && !canLeverage {
 		tmp := opts.StopLoss
 		tmp := opts.StopLoss
 		opts.StopLoss = opts.TakeProfit
 		opts.StopLoss = opts.TakeProfit
 		opts.TakeProfit = tmp
 		opts.TakeProfit = tmp

+ 1 - 5
util/strategy.go

@@ -11,11 +11,7 @@ func Symbols(strategy sentio.Strategy) []string {
 		return nil
 		return nil
 	}
 	}
 
 
-	for side, s := range strategy.PositionSymbols() {
-		if sentio.BASE == side {
-			continue
-		}
-
+	for _, s := range strategy.PositionSymbols() {
 		symbols = append(symbols, s)
 		symbols = append(symbols, s)
 	}
 	}