mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
strategy: margin side effect
This commit is contained in:
parent
3421423cd6
commit
6285e145a7
|
@ -9,6 +9,9 @@ sessions:
|
||||||
binance:
|
binance:
|
||||||
exchange: binance
|
exchange: binance
|
||||||
envVarPrefix: binance
|
envVarPrefix: binance
|
||||||
|
margin: true
|
||||||
|
isolatedMargin: true
|
||||||
|
isolatedMarginSymbol: BTCUSDT
|
||||||
|
|
||||||
backtest:
|
backtest:
|
||||||
sessions: [binance]
|
sessions: [binance]
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
* [Grid](strategy/grid.md) - Grid Strategy Explanation
|
* [Grid](strategy/grid.md) - Grid Strategy Explanation
|
||||||
* [Interaction](strategy/interaction.md) - Interaction registration for strategies
|
* [Interaction](strategy/interaction.md) - Interaction registration for strategies
|
||||||
* [Price Alert](strategy/pricealert.md) - Send price alert notification on price changes
|
* [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
|
* [Support](strategy/support.md) - Support strategy that buys on high volume support
|
||||||
|
|
||||||
### Development
|
### Development
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
### Supertrend Strategy
|
### Supertrend Strategy
|
||||||
|
|
||||||
This strategy uses Supertrend indicator as trend, and DEMA indicator as noise filter.
|
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
|
#### Parameters
|
||||||
|
|
|
@ -13,8 +13,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Margin side effect
|
|
||||||
|
|
||||||
const ID = "supertrend"
|
const ID = "supertrend"
|
||||||
|
|
||||||
const stateKey = "state-v1"
|
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)
|
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)
|
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{
|
orderForm := types.SubmitOrder{
|
||||||
Symbol: s.Symbol,
|
Symbol: s.Symbol,
|
||||||
Market: s.Market,
|
Market: s.Market,
|
||||||
Side: side,
|
Side: side,
|
||||||
Type: types.OrderTypeMarket,
|
Type: types.OrderTypeMarket,
|
||||||
Quantity: quantity,
|
Quantity: quantity,
|
||||||
|
MarginSideEffect: marginOrderSideEffect,
|
||||||
}
|
}
|
||||||
|
|
||||||
return orderForm
|
return orderForm
|
||||||
|
@ -432,7 +431,7 @@ func (s *Strategy) Run(ctx context.Context, orderExecutor bbgo.OrderExecutor, se
|
||||||
s.session.GetAccount().UpdateBalances(balances)
|
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)
|
log.Infof("submit open position order %v", orderForm)
|
||||||
order, err := orderExecutor.SubmitOrders(ctx, orderForm)
|
order, err := orderExecutor.SubmitOrders(ctx, orderForm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user