config Package
The config package provides system configuration-related structures and methods.
Important Structures
CmdArgs
Command line argument structure, containing the following fields:
Configs
: []string - List of configuration file pathsLogfile
: string - Log file pathDataDir
: string - Data directory pathNoCompress
: bool - Whether to disable compressionNoDefault
: bool - Whether to disable default configurationLogLevel
: string - Log levelTimeRange
: string - Time range in "YYYYMMDD-YYYYMMDD" formatTimeFrames
: []string - List of time framesStakeAmount
: float64 - Single order amountStakePct
: float64 - Single order amount percentagePairs
: []string - List of trading pairsForce
: bool - Whether to force executionWithSpider
: bool - Whether to use crawlerMaxPoolSize
: int - Maximum connection pool sizeCPUProfile
: bool - Whether to enable CPU profilingMemProfile
: bool - Whether to enable memory profilingTimeZone
: string - Time zoneOptRounds
: int - Number of rounds for hyperparameter optimization single taskConcur
: int - Number of concurrent processes for hyperparameter optimizationSampler
: string - Hyperparameter optimization method (tpe/bayes/random/cmaes etc.)EachPairs
: bool - Whether to execute for each trading pair individuallyReviewPeriod
: string - Review period for continuous parameter optimization backtestingRunPeriod
: string - Effective running period after parameter optimizationAlpha
: float64 - Smoothing factor for EMA calculationSeparate
: bool - Whether to test strategy combinations separately during backtesting
Config
Root configuration structure, containing the following fields:
Name
: string - Configuration nameEnv
: string - Running environmentLeverage
: float64 - Leverage multiplierLimitVolSecs
: int - Expected waiting time for limit orders (seconds)PutLimitSecs
: int - Expected time for submitting limit orders to exchangeMarketType
: string - Market typeContractType
: string - Contract typeOdBookTtl
: int64 - Order book time to liveStopEnterBars
: int - Number of candles after which to cancel unfilled entry limit ordersConcurNum
: int - Concurrency numberOrderType
: string - Order typePreFire
: float64 - Pre-firingMarginAddRate
: float64 - Margin addition rateChargeOnBomb
: bool - Whether to charge on liquidationTakeOverStgy
: string - Takeover strategyStakeAmount
: float64 - Single order amountStakePct
: float64 - Single order amount percentageMaxStakeAmt
: float64 - Maximum single order amountOpenVolRate
: float64 - Open position volume rateMinOpenRate
: float64 - Minimum open position rateBTNetCost
: float64 - Backtesting network delay (seconds)MaxOpenOrders
: int - Maximum number of open ordersMaxSimulOpen
: int - Maximum number of simultaneous open ordersWalletAmounts
: map[string]float64 - Wallet amountsDrawBalanceOver
: float64 - Balance withdrawal thresholdStakeCurrency
: []string - Order currenciesFatalStop
: map[string]float64 - Fatal stop conditionsFatalStopHours
: int - Fatal stop hoursTimeRange
: *TimeTuple - Time rangeRunTimeframes
: []string - Running time framesKlineSource
: string - Kline data sourceWatchJobs
: map[string][]string - Monitoring jobsRunPolicy
: []*RunPolicyConfig - Running policy configurationStratPerf
: *StratPerfConfig - Strategy performance configurationPairs
: []string - Trading pairs listPairMgr
: *PairMgrConfig - Pair manager configurationPairFilters
: []*CommonPairFilter - Pair filtersExchange
: *ExchangeConfig - Exchange configurationDatabase
: *DatabaseConfig - Database configurationAPIServer
: *APIServerConfig - API server configurationRPCChannels
: map[string]map[string]interface{} - RPC channel configurationWebhook
: map[string]map[string]string - Webhook configuration
RunPolicyConfig
Running policy configuration, allowing multiple strategies to run simultaneously, containing the following fields:
Name
: string - Strategy nameFilters
: []*CommonPairFilter - Pair filtersRunTimeframes
: []string - Running time framesMaxPair
: int - Maximum number of trading pairsMaxOpen
: int - Maximum number of open ordersMaxSimulOpen
: int - Maximum number of simultaneous open ordersDirt
: string - Trading direction (long/short)StratPerf
: *StratPerfConfig - Strategy performance configurationPairs
: []string - Trading pairs listParams
: map[string]float64 - Strategy parametersPairParams
: map[string]map[string]float64 - Pair parameters
StratPerfConfig
Strategy performance configuration, containing the following fields:
Enable
: bool - Whether to enableMinOdNum
: int - Minimum number of ordersMaxOdNum
: int - Maximum number of ordersMinJobNum
: int - Minimum number of tasksMidWeight
: float64 - Medium weightBadWeight
: float64 - Bad weight
DatabaseConfig
Database configuration, containing the following fields:
Url
: string - Database connection URLRetention
: string - Data retention timeMaxPoolSize
: int - Maximum connection pool sizeAutoCreate
: bool - Whether to automatically create the database
APIServerConfig
API server configuration, containing the following fields:
Enable
: bool - Whether to enableBindIPAddr
: string - Binding IP addressPort
: int - Listening portVerbosity
: string - Log verbosityJWTSecretKey
: string - JWT secret keyCORSOrigins
: []string - CORS allowed sourcesUsers
: []*UserConfig - User configurations
UserConfig
User configuration, containing the following fields:
Username
: string - UsernamePassword
: string - PasswordAccRoles
: map[string]string - Account role permissionsExpireHours
: float64 - Token expiration time (hours)
WeWorkChannel
WeWork channel configuration, containing the following fields:
Enable
: bool - Whether to enableType
: string - TypeMsgTypes
: []string - Message typesAgentId
: string - Application IDCorpId
: string - Enterprise IDCorpSecret
: string - Application secretKeywords
: string - Keywords
PairMgrConfig
Pair manager configuration, containing the following fields:
Cron
: string - Cron task expressionOffset
: int - OffsetLimit
: int - LimitForceFilters
: bool - Whether to force filtering
AccountConfig
Account configuration, containing the following fields:
APIKey
: string - API keyAPISecret
: string - API secretNoTrade
: bool - Whether to prohibit tradingMaxStakeAmt
: float64 - Maximum single order amountStakeRate
: float64 - Open position amount multiplierStakePctAmt
: float64 - Amount when opening positions based on percentageLeverage
: float64 - Leverage multiplier
Public Methods
GetDataDir
Get data directory path.
Returns:
string
- Absolute path of the data directory. Returns empty string if environment variableBanDataDir
is not set.
GetStratDir
Get strategy directory path.
Returns:
string
- Absolute path of the strategy directory. Returns empty string if environment variableBanStratDir
is not set.
LoadConfig
Load and apply configuration.
Parameters:
args
: *CmdArgs - Command line argument object
Returns:
*errs.Error
- Error information, returns nil if successful
GetConfig
Get configuration based on command line arguments.
Parameters:
args
: *CmdArgs - Command line argument objectshowLog
: bool - Whether to display logs
Returns:
*Config
- Configuration object*errs.Error
- Error information
ParseConfig
Parse configuration file at specified path.
Parameters:
path
: string - Configuration file path
Returns:
*Config
- Configuration object*errs.Error
- Error information
ApplyConfig
Apply configuration to global state.
Parameters:
args
: *CmdArgs - Command line argument objectc
: *Config - Configuration object
Returns:
*errs.Error
- Error information
GetExgConfig
Get current exchange configuration.
Returns:
*ExgItemConfig
- Exchange configuration object
GetTakeOverTF
Get takeover time frame for specified trading pair.
Parameters:
pair
: string - Trading pair namedefTF
: string - Default time frame
Returns:
string
- Time frame
GetAccLeverage
Get leverage multiplier for specified account.
Parameters:
account
: string - Account name
Returns:
float64
- Leverage multiplier
ParsePath
Parse path, replacing paths starting with $
with absolute path of data directory.
Parameters:
path
: string - Original path
Returns:
string
- Parsed path
GetStakeAmount
Get stake amount for specified account.
Parameters:
accName
: string - Account name
Returns:
float64
- Stake amount
DumpYaml
Export current configuration in YAML format.
Returns:
[]byte
- Configuration data in YAML format*errs.Error
- Error information
LoadPerfs
Load strategy performance data from specified directory.
Parameters:
inDir
: string - Input directory path
ParseTimeRange
Parse time range string.
Parameters:
timeRange
: string - Time range string in format "YYYYMMDD-YYYYMMDD"
Returns:
int64
- Start timestamp (milliseconds)int64
- End timestamp (milliseconds)error
- Error information
GetExportConfig
Get export configuration.
Parameters:
path
: string - Configuration file path
Returns:
*ExportConfig
- Export configuration object*errs.Error
- Error information