bbgo_origin/pkg/bbgo/backtestfeemode_enumer.go

118 lines
3.5 KiB
Go
Raw Permalink Normal View History

2022-09-01 11:17:41 +00:00
// Code generated by "enumer -type=BacktestFeeMode -transform=snake -trimprefix BacktestFeeMode -yaml -json"; DO NOT EDIT.
package bbgo
import (
"encoding/json"
"fmt"
"strings"
)
2022-09-01 11:17:41 +00:00
const _BacktestFeeModeName = "quotenativetoken"
2022-09-01 11:17:41 +00:00
var _BacktestFeeModeIndex = [...]uint8{0, 5, 11, 16}
2022-09-01 11:17:41 +00:00
const _BacktestFeeModeLowerName = "quotenativetoken"
2022-09-01 11:17:41 +00:00
func (i BacktestFeeMode) String() string {
if i < 0 || i >= BacktestFeeMode(len(_BacktestFeeModeIndex)-1) {
return fmt.Sprintf("BacktestFeeMode(%d)", i)
}
2022-09-01 11:17:41 +00:00
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.
2022-09-01 11:17:41 +00:00
func _BacktestFeeModeNoOp() {
var x [1]struct{}
2022-09-01 11:17:41 +00:00
_ = x[BacktestFeeModeQuote-(0)]
_ = x[BacktestFeeModeNative-(1)]
_ = x[BacktestFeeModeToken-(2)]
}
2022-09-01 11:17:41 +00:00
var _BacktestFeeModeValues = []BacktestFeeMode{BacktestFeeModeQuote, BacktestFeeModeNative, BacktestFeeModeToken}
2022-09-01 11:17:41 +00:00
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,
}
2022-09-01 11:17:41 +00:00
var _BacktestFeeModeNames = []string{
_BacktestFeeModeName[0:5],
_BacktestFeeModeName[5:11],
_BacktestFeeModeName[11:16],
}
2022-09-01 11:17:41 +00:00
// BacktestFeeModeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
2022-09-01 11:17:41 +00:00
func BacktestFeeModeString(s string) (BacktestFeeMode, error) {
if val, ok := _BacktestFeeModeNameToValueMap[s]; ok {
return val, nil
}
2022-09-01 11:17:41 +00:00
if val, ok := _BacktestFeeModeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
2022-09-01 11:17:41 +00:00
return 0, fmt.Errorf("%s does not belong to BacktestFeeMode values", s)
}
2022-09-01 11:17:41 +00:00
// BacktestFeeModeValues returns all values of the enum
func BacktestFeeModeValues() []BacktestFeeMode {
return _BacktestFeeModeValues
}
2022-09-01 11:17:41 +00:00
// BacktestFeeModeStrings returns a slice of all String values of the enum
func BacktestFeeModeStrings() []string {
strs := make([]string, len(_BacktestFeeModeNames))
copy(strs, _BacktestFeeModeNames)
return strs
}
2022-09-01 11:17:41 +00:00
// 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
}
}
return false
}
2022-09-01 11:17:41 +00:00
// MarshalJSON implements the json.Marshaler interface for BacktestFeeMode
func (i BacktestFeeMode) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
2022-09-01 11:17:41 +00:00
// 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 {
2022-09-01 11:17:41 +00:00
return fmt.Errorf("BacktestFeeMode should be a string, got %s", data)
}
var err error
2022-09-01 11:17:41 +00:00
*i, err = BacktestFeeModeString(s)
return err
}
2022-09-01 11:17:41 +00:00
// MarshalYAML implements a YAML Marshaler for BacktestFeeMode
func (i BacktestFeeMode) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
2022-09-01 11:17:41 +00:00
// 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
2022-09-01 11:17:41 +00:00
*i, err = BacktestFeeModeString(s)
return err
}