backtest: rename BackTest to Backtest

This commit is contained in:
c9s 2022-09-01 19:17:41 +08:00
parent 30742bcf0b
commit 5c8d2a019a
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
6 changed files with 68 additions and 68 deletions

View File

@ -56,7 +56,7 @@ type Exchange struct {
currentTime time.Time
account *types.Account
config *bbgo.BackTest
config *bbgo.Backtest
MarketDataStream types.StandardStreamEmitter
@ -74,7 +74,7 @@ type Exchange struct {
Src *ExchangeDataSource
}
func NewExchange(sourceName types.ExchangeName, sourceExchange types.Exchange, srv *service.BacktestService, config *bbgo.BackTest) (*Exchange, error) {
func NewExchange(sourceName types.ExchangeName, sourceExchange types.Exchange, srv *service.BacktestService, config *bbgo.Backtest) (*Exchange, error) {
ex := sourceExchange
markets, err := cache.LoadExchangeMarketsWithCache(context.Background(), ex)

View File

@ -39,16 +39,16 @@ func feeModeFunctionQuote(order *types.Order, market *types.Market, feeRate fixe
return fee, feeCurrency
}
func getFeeModeFunction(feeMode bbgo.BackTestFeeMode) FeeModeFunction {
func getFeeModeFunction(feeMode bbgo.BacktestFeeMode) FeeModeFunction {
switch feeMode {
case bbgo.BackTestFeeModeNative:
case bbgo.BacktestFeeModeNative:
return feeModeFunctionNative
case bbgo.BackTestFeeModeQuote:
case bbgo.BacktestFeeModeQuote:
return feeModeFunctionQuote
case bbgo.BackTestFeeModeToken:
case bbgo.BacktestFeeModeToken:
return feeModeFunctionToken
default:

View File

@ -1,4 +1,4 @@
// Code generated by "enumer -type=BackTestFeeMode -transform=snake -trimprefix BackTestFeeMode -yaml -json"; DO NOT EDIT.
// Code generated by "enumer -type=BacktestFeeMode -transform=snake -trimprefix BacktestFeeMode -yaml -json"; DO NOT EDIT.
package bbgo
@ -8,73 +8,73 @@ import (
"strings"
)
const _BackTestFeeModeName = "quotenativetoken"
const _BacktestFeeModeName = "quotenativetoken"
var _BackTestFeeModeIndex = [...]uint8{0, 5, 11, 16}
var _BacktestFeeModeIndex = [...]uint8{0, 5, 11, 16}
const _BackTestFeeModeLowerName = "quotenativetoken"
const _BacktestFeeModeLowerName = "quotenativetoken"
func (i BackTestFeeMode) String() string {
if i < 0 || i >= BackTestFeeMode(len(_BackTestFeeModeIndex)-1) {
return fmt.Sprintf("BackTestFeeMode(%d)", i)
func (i BacktestFeeMode) String() string {
if i < 0 || i >= BacktestFeeMode(len(_BacktestFeeModeIndex)-1) {
return fmt.Sprintf("BacktestFeeMode(%d)", i)
}
return _BackTestFeeModeName[_BackTestFeeModeIndex[i]:_BackTestFeeModeIndex[i+1]]
return _BacktestFeeModeName[_BacktestFeeModeIndex[i]:_BacktestFeeModeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _BackTestFeeModeNoOp() {
func _BacktestFeeModeNoOp() {
var x [1]struct{}
_ = x[BackTestFeeModeQuote-(0)]
_ = x[BackTestFeeModeNative-(1)]
_ = x[BackTestFeeModeToken-(2)]
_ = x[BacktestFeeModeQuote-(0)]
_ = x[BacktestFeeModeNative-(1)]
_ = x[BacktestFeeModeToken-(2)]
}
var _BackTestFeeModeValues = []BackTestFeeMode{BackTestFeeModeQuote, BackTestFeeModeNative, BackTestFeeModeToken}
var _BacktestFeeModeValues = []BacktestFeeMode{BacktestFeeModeQuote, BacktestFeeModeNative, BacktestFeeModeToken}
var _BackTestFeeModeNameToValueMap = map[string]BackTestFeeMode{
_BackTestFeeModeName[0:5]: BackTestFeeModeQuote,
_BackTestFeeModeLowerName[0:5]: BackTestFeeModeQuote,
_BackTestFeeModeName[5:11]: BackTestFeeModeNative,
_BackTestFeeModeLowerName[5:11]: BackTestFeeModeNative,
_BackTestFeeModeName[11:16]: BackTestFeeModeToken,
_BackTestFeeModeLowerName[11:16]: BackTestFeeModeToken,
var _BacktestFeeModeNameToValueMap = map[string]BacktestFeeMode{
_BacktestFeeModeName[0:5]: BacktestFeeModeQuote,
_BacktestFeeModeLowerName[0:5]: BacktestFeeModeQuote,
_BacktestFeeModeName[5:11]: BacktestFeeModeNative,
_BacktestFeeModeLowerName[5:11]: BacktestFeeModeNative,
_BacktestFeeModeName[11:16]: BacktestFeeModeToken,
_BacktestFeeModeLowerName[11:16]: BacktestFeeModeToken,
}
var _BackTestFeeModeNames = []string{
_BackTestFeeModeName[0:5],
_BackTestFeeModeName[5:11],
_BackTestFeeModeName[11:16],
var _BacktestFeeModeNames = []string{
_BacktestFeeModeName[0:5],
_BacktestFeeModeName[5:11],
_BacktestFeeModeName[11:16],
}
// BackTestFeeModeString retrieves an enum value from the enum constants string name.
// BacktestFeeModeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func BackTestFeeModeString(s string) (BackTestFeeMode, error) {
if val, ok := _BackTestFeeModeNameToValueMap[s]; ok {
func BacktestFeeModeString(s string) (BacktestFeeMode, error) {
if val, ok := _BacktestFeeModeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _BackTestFeeModeNameToValueMap[strings.ToLower(s)]; ok {
if val, ok := _BacktestFeeModeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to BackTestFeeMode values", s)
return 0, fmt.Errorf("%s does not belong to BacktestFeeMode values", s)
}
// BackTestFeeModeValues returns all values of the enum
func BackTestFeeModeValues() []BackTestFeeMode {
return _BackTestFeeModeValues
// BacktestFeeModeValues returns all values of the enum
func BacktestFeeModeValues() []BacktestFeeMode {
return _BacktestFeeModeValues
}
// BackTestFeeModeStrings returns a slice of all String values of the enum
func BackTestFeeModeStrings() []string {
strs := make([]string, len(_BackTestFeeModeNames))
copy(strs, _BackTestFeeModeNames)
// BacktestFeeModeStrings returns a slice of all String values of the enum
func BacktestFeeModeStrings() []string {
strs := make([]string, len(_BacktestFeeModeNames))
copy(strs, _BacktestFeeModeNames)
return strs
}
// IsABackTestFeeMode returns "true" if the value is listed in the enum definition. "false" otherwise
func (i BackTestFeeMode) IsABackTestFeeMode() bool {
for _, v := range _BackTestFeeModeValues {
// IsABacktestFeeMode returns "true" if the value is listed in the enum definition. "false" otherwise
func (i BacktestFeeMode) IsABacktestFeeMode() bool {
for _, v := range _BacktestFeeModeValues {
if i == v {
return true
}
@ -82,36 +82,36 @@ func (i BackTestFeeMode) IsABackTestFeeMode() bool {
return false
}
// MarshalJSON implements the json.Marshaler interface for BackTestFeeMode
func (i BackTestFeeMode) MarshalJSON() ([]byte, error) {
// MarshalJSON implements the json.Marshaler interface for BacktestFeeMode
func (i BacktestFeeMode) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for BackTestFeeMode
func (i *BackTestFeeMode) UnmarshalJSON(data []byte) error {
// UnmarshalJSON implements the json.Unmarshaler interface for BacktestFeeMode
func (i *BacktestFeeMode) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("BackTestFeeMode should be a string, got %s", data)
return fmt.Errorf("BacktestFeeMode should be a string, got %s", data)
}
var err error
*i, err = BackTestFeeModeString(s)
*i, err = BacktestFeeModeString(s)
return err
}
// MarshalYAML implements a YAML Marshaler for BackTestFeeMode
func (i BackTestFeeMode) MarshalYAML() (interface{}, error) {
// MarshalYAML implements a YAML Marshaler for BacktestFeeMode
func (i BacktestFeeMode) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// UnmarshalYAML implements a YAML Unmarshaler for BackTestFeeMode
func (i *BackTestFeeMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
// UnmarshalYAML implements a YAML Unmarshaler for BacktestFeeMode
func (i *BacktestFeeMode) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
var err error
*i, err = BackTestFeeModeString(s)
*i, err = BacktestFeeModeString(s)
return err
}

View File

@ -101,26 +101,26 @@ type Session struct {
IsolatedMarginSymbol string `json:"isolatedMarginSymbol,omitempty" yaml:"isolatedMarginSymbol,omitempty"`
}
//go:generate go run github.com/dmarkham/enumer -type=BackTestFeeMode -transform=snake -trimprefix BackTestFeeMode -yaml -json
type BackTestFeeMode int
//go:generate go run github.com/dmarkham/enumer -type=BacktestFeeMode -transform=snake -trimprefix BacktestFeeMode -yaml -json
type BacktestFeeMode int
const (
// BackTestFeeModeQuoteFee is designed for clean position but which also counts the fee in the quote balance.
// buy order = quote currency fee
// sell order = quote currency fee
BackTestFeeModeQuote BackTestFeeMode = iota // quote
BacktestFeeModeQuote BacktestFeeMode = iota // quote
// BackTestFeeModeNativeFee is the default crypto exchange fee mode.
// buy order = base currency fee
// sell order = quote currency fee
BackTestFeeModeNative // BackTestFeeMode = "native"
BacktestFeeModeNative // BackTestFeeMode = "native"
// BackTestFeeModeFeeToken is the mode which calculates fee from the outside of the balances.
// the fee will not be included in the balances nor the profit.
BackTestFeeModeToken // BackTestFeeMode = "token"
BacktestFeeModeToken // BackTestFeeMode = "token"
)
type BackTest struct {
type Backtest struct {
StartTime types.LooseFormatTime `json:"startTime,omitempty" yaml:"startTime,omitempty"`
EndTime *types.LooseFormatTime `json:"endTime,omitempty" yaml:"endTime,omitempty"`
@ -131,14 +131,14 @@ type BackTest struct {
// Account is deprecated, use Accounts instead
Account map[string]BacktestAccount `json:"account" yaml:"account"`
FeeMode BackTestFeeMode `json:"feeMode" yaml:"feeMode"`
FeeMode BacktestFeeMode `json:"feeMode" yaml:"feeMode"`
Accounts map[string]BacktestAccount `json:"accounts" yaml:"accounts"`
Symbols []string `json:"symbols" yaml:"symbols"`
Sessions []string `json:"sessions" yaml:"sessions"`
}
func (b *BackTest) GetAccount(n string) BacktestAccount {
func (b *Backtest) GetAccount(n string) BacktestAccount {
accountConfig, ok := b.Accounts[n]
if ok {
return accountConfig
@ -309,7 +309,7 @@ type Config struct {
// Deprecated: use BuildConfig instead
Imports []string `json:"imports,omitempty" yaml:"imports,omitempty"`
Backtest *BackTest `json:"backtest,omitempty" yaml:"backtest,omitempty"`
Backtest *Backtest `json:"backtest,omitempty" yaml:"backtest,omitempty"`
Sync *SyncConfig `json:"sync,omitempty" yaml:"sync,omitempty"`

View File

@ -255,10 +255,10 @@ func TestSyncSymbol(t *testing.T) {
}
func TestBackTestFeeMode(t *testing.T) {
var mode BackTestFeeMode
var mode BacktestFeeMode
var err = yaml.Unmarshal([]byte(`quote`), &mode)
assert.NoError(t, err)
assert.Equal(t, BackTestFeeModeQuote, mode)
assert.Equal(t, BacktestFeeModeQuote, mode)
}
func Test_categorizeSyncSymbol(t *testing.T) {

View File

@ -141,7 +141,7 @@ var BacktestCmd = &cobra.Command{
startTime = userConfig.Backtest.StartTime.Time().Local()
// set default start time to the past 6 months
// userConfig.BackTest.StartTime = now.AddDate(0, -6, 0).Format("2006-01-02")
// userConfig.Backtest.StartTime = now.AddDate(0, -6, 0).Format("2006-01-02")
if userConfig.Backtest.EndTime != nil {
endTime = userConfig.Backtest.EndTime.Time().Local()
} else {