2021-02-06 03:34:53 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-02-07 03:40:30 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
2022-02-15 05:55:19 +00:00
|
|
|
"github.com/c9s/bbgo/pkg/types"
|
2024-10-02 15:40:28 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
2021-02-06 03:34:53 +00:00
|
|
|
)
|
|
|
|
|
2022-03-03 08:34:32 +00:00
|
|
|
func cobraInitRequired(required []string) func(cmd *cobra.Command, args []string) error {
|
|
|
|
return func(cmd *cobra.Command, args []string) error {
|
|
|
|
for _, key := range required {
|
|
|
|
if err := cmd.MarkFlagRequired(key); err != nil {
|
|
|
|
log.WithError(err).Errorf("cannot mark --%s option required", key)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-17 10:45:06 +00:00
|
|
|
// inQuoteAsset converts all balances in quote asset
|
2022-02-07 03:40:30 +00:00
|
|
|
func inQuoteAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
|
2022-01-31 16:54:55 +00:00
|
|
|
quote := balances[market.QuoteCurrency]
|
|
|
|
base := balances[market.BaseCurrency]
|
2022-02-07 03:40:30 +00:00
|
|
|
return base.Total().Mul(price).Add(quote.Total())
|
2022-01-31 16:54:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 03:40:30 +00:00
|
|
|
func inBaseAsset(balances types.BalanceMap, market types.Market, price fixedpoint.Value) fixedpoint.Value {
|
2021-02-06 03:34:53 +00:00
|
|
|
quote := balances[market.QuoteCurrency]
|
|
|
|
base := balances[market.BaseCurrency]
|
2022-02-07 03:40:30 +00:00
|
|
|
return quote.Total().Div(price).Add(base.Total())
|
2021-02-06 03:34:53 +00:00
|
|
|
}
|