strategy: margin side effect

This commit is contained in:
Andy Cheng 2022-05-31 15:46:55 +08:00
parent 3421423cd6
commit 6285e145a7
4 changed files with 15 additions and 11 deletions

View File

@ -9,6 +9,9 @@ sessions:
binance:
exchange: binance
envVarPrefix: binance
margin: true
isolatedMargin: true
isolatedMarginSymbol: BTCUSDT
backtest:
sessions: [binance]

View File

@ -22,6 +22,7 @@
* [Grid](strategy/grid.md) - Grid Strategy Explanation
* [Interaction](strategy/interaction.md) - Interaction registration for strategies
* [Price Alert](strategy/pricealert.md) - Send price alert notification on price changes
* [Supertrend](strategy/supertrend.md) - Supertrend strategy uses Supertrend indicator as trend, and DEMA indicator as noise filter
* [Support](strategy/support.md) - Support strategy that buys on high volume support
### Development

View File

@ -1,7 +1,8 @@
### Supertrend Strategy
This strategy uses Supertrend indicator as trend, and DEMA indicator as noise filter.
This strategy needs margin enabled in order to submit short orders, but you can use `leverage` parameter to limit your risk.
Supertrend strategy needs margin enabled in order to submit short orders, and you can use `leverage` parameter to limit your risk.
**Please note, using leverage higher than 1 is highly risky.**
#### Parameters

View File

@ -13,8 +13,6 @@ import (
"sync"
)
// TODO: Margin side effect
const ID = "supertrend"
const stateKey = "state-v1"
@ -210,7 +208,7 @@ func (s *Strategy) ClosePosition(ctx context.Context, percentage fixedpoint.Valu
return fmt.Errorf("order quantity %v is too small, less than %v", quantity, s.Market.MinQuantity)
}
orderForm := s.GenerateOrderForm(side, quantity)
orderForm := s.GenerateOrderForm(side, quantity, types.SideEffectTypeAutoRepay)
s.Notify("Submitting %s %s order to close position by %v", s.Symbol, side.String(), percentage, orderForm)
@ -264,13 +262,14 @@ func (s *Strategy) UpdateIndicators(kline types.KLine) {
}
}
func (s *Strategy) GenerateOrderForm(side types.SideType, quantity fixedpoint.Value) types.SubmitOrder {
func (s *Strategy) GenerateOrderForm(side types.SideType, quantity fixedpoint.Value, marginOrderSideEffect types.MarginOrderSideEffectType) types.SubmitOrder {
orderForm := types.SubmitOrder{
Symbol: s.Symbol,
Market: s.Market,
Side: side,
Type: types.OrderTypeMarket,
Quantity: quantity,
MarginSideEffect: marginOrderSideEffect,
}
return orderForm
@ -432,7 +431,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
s.session.GetAccount().UpdateBalances(balances)
}
orderForm := s.GenerateOrderForm(side, s.CalculateQuantity(kline.GetClose()))
orderForm := s.GenerateOrderForm(side, s.CalculateQuantity(kline.GetClose()), types.SideEffectTypeMarginBuy)
log.Infof("submit open position order %v", orderForm)
order, err := orderExecutor.SubmitOrders(ctx, orderForm)
if err != nil {