Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyConfig(args *CmdArgs, c *Config) *errs.Error
- func ApplyPairPolicy(pairs []string, policies []*RunPolicyConfig)
- func DumpYaml(desensitize bool) ([]byte, *errs.Error)
- func GetAccLeverage(account string) float64
- func GetDataDir() string
- func GetStakeAmount(accName string) float64
- func GetStratDir() string
- func GetTakeOverTF(pair, defTF string) string
- func LoadConfig(args *CmdArgs) *errs.Error
- func LoadPerfs(inDir string)
- func ParsePath(path string) string
- func ParseTimeRange(timeRange string) (int64, int64, error)
- type APIServerConfig
- type AccountConfig
- type ArrString
- type CmdArgs
- type CommonPairFilter
- type Config
- func (c *Config) Apply(args *CmdArgs)
- func (c *Config) Clone() *Config
- func (c *Config) Desensitize() *Config
- func (c *Config) DumpYaml() ([]byte, *errs.Error)
- func (c *Config) HashCode() (string, *errs.Error)
- func (c *Config) ShowPairs() string
- func (c *Config) Strats() []string
- func (c *Config) TimeFrames() []string
- type DatabaseConfig
- type ExchangeConfig
- type ExgItemConfig
- type ExportConfig
- type MarketRange
- type MarketSymbolsRange
- type MarketTFSymbolsRange
- type PairMgrConfig
- type RunPolicyConfig
- func (c *RunPolicyConfig) Clone() *RunPolicyConfig
- func (c *RunPolicyConfig) Def(k string, dv float64, p *core.Param) float64
- func (c *RunPolicyConfig) DefInt(k string, dv int, p *core.Param) int
- func (c *RunPolicyConfig) HyperParams() []*core.Param
- func (c *RunPolicyConfig) ID() string
- func (c *RunPolicyConfig) IsInt(k string) bool
- func (c *RunPolicyConfig) KeepHyperOnly(keys ...string)
- func (c *RunPolicyConfig) Key() string
- func (c *RunPolicyConfig) OdDirt() int
- func (c *RunPolicyConfig) PairDup(pair string) (*RunPolicyConfig, bool)
- func (c *RunPolicyConfig) Param(k string, dv float64) float64
- func (c *RunPolicyConfig) ToYaml() string
- type StratPerfConfig
- type TelegramChannel
- type TimeTuple
- type UserConfig
- type WeWorkChannel
Constants ¶
const (
MinPairCronGapMS = 1800000 // 交易对刷新最小间隔半小时
)
Variables ¶
var ( Data Config Args *CmdArgs Accounts map[string]*AccountConfig // Exchange tradable account 交易所可交易账户 BakAccounts map[string]*AccountConfig // Exchange account, not tradable 交易所账户,不可交易 DefAcc = "default" // For non-real trading, the default key of the account (backtesting, simulated trading) 非实盘交易时,账户默认的key(回测、模拟交易) Name string Loaded bool Leverage float64 LimitVolSecs int // How long the limit order is expected to wait for execution, in seconds 限价单预期等待多长时间成交,单位秒 PutLimitSecs int // Only limit orders executed within this expected time will be submitted to the exchange. 在此预期时间内成交的限价单,才提交到交易所 OdBookTtl int64 StopEnterBars int // The entry limit order will be canceled if it is not filled after the number of candles. 入场限价单超过多少个蜡烛未成交则取消 OrderType string PreFire float64 MarginAddRate float64 // When trading contracts, if a loss occurs and the loss reaches this value of the initial margin ratio, additional margin will be required to avoid forced liquidation. 交易合约时,如出现亏损,亏损达到初始保证金比率的此值时,进行追加保证金,避免强平 ChargeOnBomb bool TakeOverStrat string StakeAmount float64 // The amount of a single order, the priority is lower than StakePct 单笔开单金额,优先级低于StakePct StakePct float64 // Percentage of single bill amount 单笔开单金额百分比 MaxStakeAmt float64 // Maximum bill amount for a single transaction 单笔最大开单金额 OpenVolRate float64 // When opening an order without specifying a quantity, the multiple of the maximum allowed order quantity/average candle trading volume, defaults to 1 未指定数量开单时,最大允许开单数量/平均蜡烛成交量的倍数,默认1 MinOpenRate float64 // When the wallet balance is less than the single amount, orders are allowed to be issued when it reaches this ratio of the single amount. 钱包余额不足单笔金额时,达到单笔金额的此比例则允许开单 LowCostAction string // Actions taken when stake amount less than the minimum amount 花费不足最小金额时的动作:ignore, keep BTNetCost float64 // Order placement delay during backtesting, simulated slippage, unit seconds 回测时下单延迟,模拟滑点,单位秒 RelaySimUnFinish bool // 交易新品种时(回测/实盘),是否从开始时间未平仓订单接力开始交易 OrderBarMax int // 查找开始时间未平仓订单向前模拟最大bar数量 MaxOpenOrders int MaxSimulOpen int WalletAmounts map[string]float64 DrawBalanceOver float64 StakeCurrency []string StakeCurrencyMap map[string]bool FatalStop map[int]float64 FatalStopHours int TimeRange *TimeTuple RunTimeframes []string KlineSource string WatchJobs map[string][]string RunPolicy []*RunPolicyConfig StratPerf *StratPerfConfig Pairs []string PairMgr *PairMgrConfig PairFilters []*CommonPairFilter Exchange *ExchangeConfig DataDir string Database *DatabaseConfig SpiderAddr string APIServer *APIServerConfig RPCChannels map[string]map[string]interface{} Webhook map[string]map[string]string )
Functions ¶
func ApplyPairPolicy ¶ added in v0.1.33
func ApplyPairPolicy(pairs []string, policies []*RunPolicyConfig)
func GetAccLeverage ¶
func GetDataDir ¶
func GetDataDir() string
func GetStakeAmount ¶
func GetStratDir ¶
func GetStratDir() string
func GetTakeOverTF ¶
func LoadConfig ¶
Types ¶
type APIServerConfig ¶
type APIServerConfig struct {
Enable bool `yaml:"enable" mapstructure:"enable"` // Whether to enable 是否启用
BindIPAddr string `yaml:"bind_ip" mapstructure:"bind_ip"` // Binding address, 0.0.0.0 means exposed to the public network 绑定地址,0.0.0.0表示暴露到公网
Port int `yaml:"port" mapstructure:"port"` // LOCAL LISTENING PORT 本地监听端口
Verbosity string `yaml:"verbosity" mapstructure:"verbosity"` // Detail level 详细程度
JWTSecretKey string `yaml:"jwt_secret_key" mapstructure:"jwt_secret_key"` // Key used for password encryption 用于密码加密的密钥
CORSOrigins []string `yaml:"CORS_origins" mapstructure:"CORS_origins"` // When accessing banweb, you need to add the address of banweb here to allow access. banweb访问时,要这里添加banweb的地址放行
Users []*UserConfig `yaml:"users" mapstructure:"users"` // Login user 登录用户
}
type AccountConfig ¶
type AccountConfig struct {
APIKey string `yaml:"api_key" mapstructure:"api_key"`
APISecret string `yaml:"api_secret" mapstructure:"api_secret"`
NoTrade bool `yaml:"no_trade" mapstructure:"no_trade"`
MaxStakeAmt float64 `yaml:"max_stake_amt" mapstructure:"max_stake_amt"` // Maximum amount allowed for a single transaction 允许的单笔最大金额
StakeRate float64 `yaml:"stake_rate" mapstructure:"stake_rate"` // Multiple of billing amount relative to benchmark 相对基准的开单金额倍数
StakePctAmt float64 // The amount currently allowed when billing by percentage按百分比开单时,当前允许的金额
Leverage float64 `yaml:"leverage" mapstructure:"leverage"`
}
AccountConfig Configuration to store API keys and secrets 存储 API 密钥和秘密的配置
func (*AccountConfig) Desensitize ¶ added in v0.1.27
func (a *AccountConfig) Desensitize() *AccountConfig
type CmdArgs ¶
type CmdArgs struct {
Configs ArrString
Logfile string
DataDir string
NoCompress bool
NoDefault bool
LogLevel string
TimeRange string
RawTimeFrames string
TimeFrames []string
StakeAmount float64
StakePct float64
RawPairs string
Pairs []string
RawTables string
Tables []string
Force bool
WithSpider bool
Medium string
MaxPoolSize int
CPUProfile bool
MemProfile bool
InPath string
PrgOut string
OutPath string
OutType string // output data type
AdjType string // adjustment type: 复权类型: pre,post,none
TimeZone string
ExgReal string
OptRounds int // Hyperparameter optimization single task execution round 超参数优化单任务执行轮次
Concur int // Hyperparameter optimization of multi-process concurrency 超参数优化多进程并发数量
Sampler string // Hyperparameter optimization methods 超参数优化的方法: tpe/bayes/random/cmaes/ipop-cmaes/bipop-cmaes
EachPairs bool // Execute target by target 逐个标的执行
ReviewPeriod string // During continuous parameter adjustment and backtesting, the period of parameter adjustment review 持续调参回测时,调参回顾的周期
RunPeriod string // During continuous parameter adjustment and backtesting, the effective running period after parameter adjustment 持续调参回测时,调参后有效运行周期
Picker string // Method for selecting targets from multiple hyperparameter optimization results 从多个超参数优化结果中挑选目标的方法
Alpha float64 // the smoothing factor of calculate EMA 计算EMA的平滑因子
PairPicker string // pairs picker for hyper opt
InType string // Input file data type 输入文件的数据类型
RunEveryTF string // run once every n timeframe
BatchSize int
Separate bool // Used for backtesting. When true, the strategy combination is tested separately. 用于回测,true时策略组合单独测试
}
type CommonPairFilter ¶
type CommonPairFilter struct {
Name string `yaml:"name" mapstructure:"name"`
Items map[string]interface{} `yaml:",inline" mapstructure:",remain"`
}
UNIVERSAL FILTER 通用的过滤器
type Config ¶
type Config struct {
Name string `yaml:"name" mapstructure:"name"`
Env string `yaml:"env" mapstructure:"env"`
Leverage float64 `yaml:"leverage" mapstructure:"leverage"`
LimitVolSecs int `yaml:"limit_vol_secs" mapstructure:"limit_vol_secs"`
PutLimitSecs int `yaml:"put_limit_secs" mapstructure:"put_limit_secs"`
MarketType string `yaml:"market_type" mapstructure:"market_type"`
ContractType string `yaml:"contract_type" mapstructure:"contract_type"`
OdBookTtl int64 `yaml:"odbook_ttl" mapstructure:"odbook_ttl"`
StopEnterBars int `json:"stop_enter_bars" mapstructure:"stop_enter_bars"`
ConcurNum int `json:"concur_num" mapstructure:"concur_num"`
OrderType string `yaml:"order_type" mapstructure:"order_type"`
PreFire float64 `yaml:"prefire" mapstructure:"prefire"`
MarginAddRate float64 `yaml:"margin_add_rate" mapstructure:"margin_add_rate"`
ChargeOnBomb bool `yaml:"charge_on_bomb" mapstructure:"charge_on_bomb"`
TakeOverStrat string `yaml:"take_over_strat" mapstructure:"take_over_strat"`
StakeAmount float64 `yaml:"stake_amount" mapstructure:"stake_amount"`
StakePct float64 `yaml:"stake_pct" mapstructure:"stake_pct"`
MaxStakeAmt float64 `yaml:"max_stake_amt" mapstructure:"max_stake_amt"`
OpenVolRate float64 `yaml:"open_vol_rate" mapstructure:"open_vol_rate"`
MinOpenRate float64 `yaml:"min_open_rate" mapstructure:"min_open_rate"`
LowCostAction string `yaml:"low_cost_action" mapstructure:"low_cost_action"`
BTNetCost float64 `yaml:"bt_net_cost" mapstructure:"bt_net_cost"`
RelaySimUnFinish bool `yaml:"relay_sim_unfinish" mapstructure:"relay_sim_unfinish"`
OrderBarMax int `yaml:"order_bar_max" mapstructure:"order_bar_max"`
MaxOpenOrders int `yaml:"max_open_orders" mapstructure:"max_open_orders"`
MaxSimulOpen int `yaml:"max_simul_open" mapstructure:"max_simul_open"`
WalletAmounts map[string]float64 `yaml:"wallet_amounts" mapstructure:"wallet_amounts"`
DrawBalanceOver float64 `yaml:"draw_balance_over" mapstructure:"draw_balance_over"`
StakeCurrency []string `yaml:"stake_currency" mapstructure:"stake_currency"`
FatalStop map[string]float64 `yaml:"fatal_stop" mapstructure:"fatal_stop"`
FatalStopHours int `yaml:"fatal_stop_hours" mapstructure:"fatal_stop_hours"`
TimeRangeRaw string `yaml:"timerange" mapstructure:"timerange"`
TimeRange *TimeTuple `json:"-" mapstructure:"-"`
RunTimeframes []string `yaml:"run_timeframes" mapstructure:"run_timeframes"`
KlineSource string `yaml:"kline_source" mapstructure:"kline_source"`
WatchJobs map[string][]string `yaml:"watch_jobs" mapstructure:"watch_jobs"`
RunPolicy []*RunPolicyConfig `yaml:"run_policy" mapstructure:"run_policy"`
StratPerf *StratPerfConfig `yaml:"strat_perf" mapstructure:"strat_perf"`
Pairs []string `yaml:"pairs" mapstructure:"pairs"`
PairMgr *PairMgrConfig `yaml:"pairmgr" mapstructure:"pairmgr"`
PairFilters []*CommonPairFilter `yaml:"pairlists" mapstructure:"pairlists"`
Exchange *ExchangeConfig `yaml:"exchange" mapstructure:"exchange"`
Database *DatabaseConfig `yaml:"database" mapstructure:"database"`
SpiderAddr string `yaml:"spider_addr" mapstructure:"spider_addr"`
APIServer *APIServerConfig `yaml:"api_server" mapstructure:"api_server"`
RPCChannels map[string]map[string]interface{} `yaml:"rpc_channels" mapstructure:"rpc_channels"`
Webhook map[string]map[string]string `yaml:"webhook" mapstructure:"webhook"`
}
Config Is the root configuration structure 是根配置结构体
func GetConfig ¶ added in v0.1.12
GetConfig get config from args
args: NoDefault, Configs, TimeRange, MaxPoolSize, StakeAmount, StakePct, TimeFrames, Pairs
func (*Config) Desensitize ¶ added in v0.1.27
Desensitize 屏蔽配置对象中的敏感信息 database.url exchange.account_*.*.(api_key|api_secret) rpc_channels.*.*secret api_server.jwt_secret_key api_server.users[*].pwd
func (*Config) TimeFrames ¶ added in v0.1.12
type DatabaseConfig ¶
type ExchangeConfig ¶
type ExchangeConfig struct {
Name string `yaml:"name" mapstructure:"name"`
Items map[string]*ExgItemConfig `yaml:",inline" mapstructure:",remain"`
}
ExchangeConfig Represents the configuration information of the exchange 表示交易所的配置信息
type ExgItemConfig ¶
type ExgItemConfig struct {
AccountProds map[string]*AccountConfig `yaml:"account_prods,omitempty" mapstructure:"account_prods,omitempty"`
AccountTests map[string]*AccountConfig `yaml:"account_tests,omitempty" mapstructure:"account_tests,omitempty"`
Options map[string]interface{} `yaml:"options,omitempty" mapstructure:"options,omitempty"`
}
Configuration of specific exchanges 具体交易所的配置
func GetExgConfig ¶
func GetExgConfig() *ExgItemConfig
type ExportConfig ¶ added in v0.1.24
type ExportConfig struct {
Klines []*MarketTFSymbolsRange `yaml:"klines"`
AdjFactors []*MarketSymbolsRange `yaml:"adj_factors"`
Calendars []*MarketRange `yaml:"calendars"`
}
ExportConfig represents the export configuration
func GetExportConfig ¶ added in v0.1.24
func GetExportConfig(path string) (*ExportConfig, *errs.Error)
type MarketRange ¶ added in v0.1.24
type MarketSymbolsRange ¶ added in v0.1.24
type MarketSymbolsRange struct {
*MarketRange `yaml:",inline"`
Symbols []string `yaml:"symbols"`
}
type MarketTFSymbolsRange ¶ added in v0.1.24
type MarketTFSymbolsRange struct {
*MarketSymbolsRange `yaml:",inline"`
TimeFrames []string `yaml:"timeframes"`
}
type PairMgrConfig ¶
type PairMgrConfig struct {
Cron string `yaml:"cron" mapstructure:"cron"`
// Offset limited quantity selection. 偏移限定数量选择。
Offset int `yaml:"offset" mapstructure:"offset,omitempty"`
// Limit the number of currencies 限制币种数量
Limit int `yaml:"limit" mapstructure:"limit,omitempty"`
// apply filters to static pairs force
ForceFilters bool `yaml:"force_filters" mapstructure:"force_filters,omitempty"`
// hole/close 品种切换时保留还是退出仓位
PosOnRotation string `yaml:"pos_on_rotation" mapstructure:"pos_on_rotation"`
}
type RunPolicyConfig ¶
type RunPolicyConfig struct {
Name string `yaml:"name" mapstructure:"name"`
Filters []*CommonPairFilter `yaml:"filters" mapstructure:"filters"`
RunTimeframes []string `yaml:"run_timeframes" mapstructure:"run_timeframes"`
MaxPair int `yaml:"max_pair" mapstructure:"max_pair"`
MaxOpen int `yaml:"max_open" mapstructure:"max_open"`
MaxSimulOpen int `yaml:"max_simul_open" mapstructure:"max_simul_open"`
OrderBarMax int `yaml:"order_bar_max" mapstructure:"order_bar_max"`
StakeRate float64 `yaml:"stake_rate" mapstructure:"stake_rate"`
Dirt string `yaml:"dirt" mapstructure:"dirt"`
StratPerf *StratPerfConfig `yaml:"strat_perf" mapstructure:"strat_perf"`
Pairs []string `yaml:"pairs" mapstructure:"pairs"`
Params map[string]float64 `yaml:"params" mapstructure:"params"`
PairParams map[string]map[string]float64 `yaml:"pair_params" mapstructure:"pair_params"`
Score float64
// contains filtered or unexported fields
}
The strategy to run, multiple strategies can be run at the same time 运行的策略,可以多个策略同时运行
func (*RunPolicyConfig) Clone ¶
func (c *RunPolicyConfig) Clone() *RunPolicyConfig
func (*RunPolicyConfig) HyperParams ¶
func (c *RunPolicyConfig) HyperParams() []*core.Param
func (*RunPolicyConfig) ID ¶
func (c *RunPolicyConfig) ID() string
func (*RunPolicyConfig) IsInt ¶ added in v0.1.24
func (c *RunPolicyConfig) IsInt(k string) bool
func (*RunPolicyConfig) KeepHyperOnly ¶
func (c *RunPolicyConfig) KeepHyperOnly(keys ...string)
KeepHyperOnly Only keep the given hyperparameters for optimization and remove other hyperparameters
func (*RunPolicyConfig) Key ¶ added in v0.1.7
func (c *RunPolicyConfig) Key() string
func (*RunPolicyConfig) OdDirt ¶
func (c *RunPolicyConfig) OdDirt() int
func (*RunPolicyConfig) PairDup ¶
func (c *RunPolicyConfig) PairDup(pair string) (*RunPolicyConfig, bool)
func (*RunPolicyConfig) ToYaml ¶
func (c *RunPolicyConfig) ToYaml() string
type StratPerfConfig ¶ added in v0.1.12
type StratPerfConfig struct {
Enable bool `yaml:"enable" mapstructure:"enable"`
MinOdNum int `yaml:"min_od_num" mapstructure:"min_od_num"`
MaxOdNum int `yaml:"max_od_num" mapstructure:"max_od_num"`
MinJobNum int `yaml:"min_job_num" mapstructure:"min_job_num"`
MidWeight float64 `yaml:"mid_weight" mapstructure:"mid_weight"`
BadWeight float64 `yaml:"bad_weight" mapstructure:"bad_weight"`
}
func (*StratPerfConfig) Validate ¶ added in v0.1.12
func (p *StratPerfConfig) Validate()
type TelegramChannel ¶
type UserConfig ¶
type UserConfig struct {
Username string `yaml:"user" mapstructure:"user"` // 用户名
Password string `yaml:"pwd" mapstructure:"pwd"` // 密码
AccRoles map[string]string `yaml:"acc_roles" mapstructure:"acc_roles"` // Role permissions for different accounts 对不同账户的角色权限
ExpireHours float64 `yaml:"exp_hours" mapstructure:"exp_hours"` // Token expiration time, default 168 hours token过期时间,默认168小时
}
type WeWorkChannel ¶
type WeWorkChannel struct {
Enable bool `yaml:"enable" mapstructure:"enable"`
Type string `yaml:"type" mapstructure:"type"`
MsgTypes []string `yaml:"msg_types" mapstructure:"msg_types"`
AgentId string `yaml:"agentid" mapstructure:"agentid"`
CorpId string `yaml:"corpid" mapstructure:"corpid"`
CorpSecret string `yaml:"corpsecret" mapstructure:"corpsecret"`
Keywords string `yaml:"keywords" mapstructure:"keywords"`
}