diff --git a/config/marketcap.yaml b/config/marketcap.yaml index d1f8b41bf..7f4caa615 100644 --- a/config/marketcap.yaml +++ b/config/marketcap.yaml @@ -22,5 +22,6 @@ exchangeStrategies: threshold: 1% # max amount to buy or sell per order maxAmount: 1_000 - dryRun: true queryInterval: 1h + orderType: LIMIT_MAKER # LIMIT_MAKER, LIMIT, MARKET + dryRun: true diff --git a/pkg/strategy/marketcap/strategy.go b/pkg/strategy/marketcap/strategy.go index 83800f573..05aa8d020 100644 --- a/pkg/strategy/marketcap/strategy.go +++ b/pkg/strategy/marketcap/strategy.go @@ -31,17 +31,25 @@ type Strategy struct { QuoteCurrencyWeight fixedpoint.Value `json:"quoteCurrencyWeight"` BaseCurrencies []string `json:"baseCurrencies"` Threshold fixedpoint.Value `json:"threshold"` - DryRun bool `json:"dryRun"` // max amount to buy or sell per order MaxAmount fixedpoint.Value `json:"maxAmount"` // interval to query marketcap data from coinmarketcap - QueryInterval types.Interval `json:"queryInterval"` + QueryInterval types.Interval `json:"queryInterval"` + OrderType types.OrderType `json:"orderType"` + DryRun bool `json:"dryRun"` subscribeSymbol string activeOrderBook *bbgo.ActiveOrderBook targetWeights types.ValueMap } +func (s *Strategy) Defaults() error { + if s.OrderType == "" { + s.OrderType = types.OrderTypeLimitMaker + } + return nil +} + func (s *Strategy) Initialize() error { apiKey := os.Getenv("COINMARKETCAP_API_KEY") s.datasource = coinmarketcap.New(apiKey) @@ -76,7 +84,6 @@ func (s *Strategy) Validate() error { if s.MaxAmount.Sign() < 0 { return fmt.Errorf("maxAmount shoud not less than 0") } - return nil } @@ -178,7 +185,7 @@ func (s *Strategy) generateSubmitOrders(ctx context.Context, session *bbgo.Excha order := types.SubmitOrder{ Symbol: symbol, Side: side, - Type: types.OrderTypeLimit, + Type: s.OrderType, Quantity: quantity, Price: currentPrice, } diff --git a/pkg/strategy/rebalance/strategy.go b/pkg/strategy/rebalance/strategy.go index 41eef02dc..681c6022c 100644 --- a/pkg/strategy/rebalance/strategy.go +++ b/pkg/strategy/rebalance/strategy.go @@ -31,6 +31,13 @@ type Strategy struct { activeOrderBook *bbgo.ActiveOrderBook } +func (s *Strategy) Defaults() error { + if s.OrderType == "" { + s.OrderType = types.OrderTypeLimitMaker + } + return nil +} + func (s *Strategy) Initialize() error { return nil } @@ -61,7 +68,6 @@ func (s *Strategy) Validate() error { if s.MaxAmount.Sign() < 0 { return fmt.Errorf("maxAmount shoud not less than 0") } - return nil }