mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
make inBaseAsset as private method
This commit is contained in:
parent
dd9dbee903
commit
0b657d59f9
|
@ -3,7 +3,6 @@ package cmd
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -267,8 +266,8 @@ var BacktestCmd = &cobra.Command{
|
|||
finalBalances.Print()
|
||||
|
||||
if wantBaseAssetBaseline {
|
||||
initBaseAsset := InBaseAsset(initBalances, market, startPrice)
|
||||
finalBaseAsset := InBaseAsset(finalBalances, market, lastPrice)
|
||||
initBaseAsset := inBaseAsset(initBalances, market, startPrice)
|
||||
finalBaseAsset := inBaseAsset(finalBalances, market, lastPrice)
|
||||
log.Infof("INITIAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(initBaseAsset), market.BaseCurrency, market.BaseCurrency, startPrice)
|
||||
log.Infof("FINAL ASSET ~= %s %s (1 %s = %f)", market.FormatQuantity(finalBaseAsset), market.BaseCurrency, market.BaseCurrency, lastPrice)
|
||||
|
||||
|
@ -282,29 +281,3 @@ var BacktestCmd = &cobra.Command{
|
|||
},
|
||||
}
|
||||
|
||||
func InBaseAsset(balances types.BalanceMap, market types.Market, price float64) float64 {
|
||||
quote := balances[market.QuoteCurrency]
|
||||
base := balances[market.BaseCurrency]
|
||||
return (base.Locked.Float64() + base.Available.Float64()) + ((quote.Locked.Float64() + quote.Available.Float64()) / price)
|
||||
}
|
||||
|
||||
// configureDB configures the database service based on the environment variable
|
||||
func configureDB(ctx context.Context, environ *bbgo.Environment) error {
|
||||
if driver, ok := os.LookupEnv("DB_DRIVER") ; ok {
|
||||
|
||||
if dsn, ok := os.LookupEnv("DB_DSN") ; ok {
|
||||
return environ.ConfigureDatabase(ctx, driver, dsn)
|
||||
}
|
||||
|
||||
} else if dsn, ok := os.LookupEnv("SQLITE3_DSN"); ok {
|
||||
|
||||
return environ.ConfigureDatabase(ctx, "sqlite3", dsn)
|
||||
|
||||
} else if dsn, ok := os.LookupEnv("MYSQL_URL"); ok {
|
||||
|
||||
return environ.ConfigureDatabase(ctx, "mysql", dsn)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
36
pkg/cmd/utils.go
Normal file
36
pkg/cmd/utils.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
||||
func inBaseAsset(balances types.BalanceMap, market types.Market, price float64) float64 {
|
||||
quote := balances[market.QuoteCurrency]
|
||||
base := balances[market.BaseCurrency]
|
||||
return (base.Locked.Float64() + base.Available.Float64()) + ((quote.Locked.Float64() + quote.Available.Float64()) / price)
|
||||
}
|
||||
|
||||
// configureDB configures the database service based on the environment variable
|
||||
func configureDB(ctx context.Context, environ *bbgo.Environment) error {
|
||||
if driver, ok := os.LookupEnv("DB_DRIVER"); ok {
|
||||
|
||||
if dsn, ok := os.LookupEnv("DB_DSN"); ok {
|
||||
return environ.ConfigureDatabase(ctx, driver, dsn)
|
||||
}
|
||||
|
||||
} else if dsn, ok := os.LookupEnv("SQLITE3_DSN"); ok {
|
||||
|
||||
return environ.ConfigureDatabase(ctx, "sqlite3", dsn)
|
||||
|
||||
} else if dsn, ok := os.LookupEnv("MYSQL_URL"); ok {
|
||||
|
||||
return environ.ConfigureDatabase(ctx, "mysql", dsn)
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user