Merge pull request #1080 from c9s/narumi/marketcap/order-type

strategy: marketcap: add orderType parameter
This commit is contained in:
なるみ 2023-03-06 21:46:25 +08:00 committed by GitHub
commit f064f5fbe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 6 deletions

View File

@ -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

View File

@ -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"`
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,
}

View File

@ -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
}