config

package
v0.1.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2024 License: AGPL-3.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
	NoDB             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
	TakeOverStgy     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. 钱包余额不足单笔金额时,达到单笔金额的此比例则允许开单
	BTNetCost        float64 // Order placement delay during backtesting, simulated slippage, unit seconds 回测时下单延迟,模拟滑点,单位秒
	MaxOpenOrders    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
	StrtgPerf        *StrtgPerfConfig
	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 DumpYaml

func DumpYaml() ([]byte, *errs.Error)

func GetAccLeverage

func GetAccLeverage(account string) float64

func GetDataDir

func GetDataDir() string

func GetStakeAmount

func GetStakeAmount(accName string) float64

func GetStratDir

func GetStratDir() string

func GetTakeOverTF

func GetTakeOverTF(pair, defTF string) string

func LoadConfig

func LoadConfig(args *CmdArgs) *errs.Error

func LoadPerfs added in v0.1.7

func LoadPerfs(inDir string)

func ParsePath

func ParsePath(path string) string

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 密钥和秘密的配置

type ArrString

type ArrString []string

func (*ArrString) Set

func (i *ArrString) Set(value string) error

func (*ArrString) String

func (i *ArrString) String() string

type CmdArgs

type CmdArgs struct {
	Configs       ArrString
	Logfile       string
	DataDir       string
	NoDb          bool
	NoCompress    bool
	NoDefault     bool
	LogLevel      string
	TimeRange     string
	RawTimeFrames string
	TimeFrames    []string
	StakeAmount   float64
	StakePct      float64
	RawPairs      string
	Pairs         []string
	RawTables     string
	Tables        []string
	StrategyDirs  ArrString
	Force         bool
	WithSpider    bool
	Medium        string
	TaskHash      string
	TaskId        int
	MaxPoolSize   int
	CPUProfile    bool
	MemProfile    bool
	InPath        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时策略组合单独测试
}

func (*CmdArgs) Init

func (a *CmdArgs) Init()

func (*CmdArgs) ParseTimeZone

func (a *CmdArgs) ParseTimeZone() (*time.Location, *errs.Error)

func (*CmdArgs) SetLog added in v0.1.7

func (a *CmdArgs) SetLog(showLog bool, handlers ...zapcore.Core)

type CommonPairFilter

type CommonPairFilter struct {
	Name  string                 `yaml:"name" mapstructure:"name"`
	Items map[string]interface{} `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"`
	TakeOverStgy    string                            `yaml:"take_over_stgy" mapstructure:"take_over_stgy"`
	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"`
	BTNetCost       float64                           `yaml:"bt_net_cost" mapstructure:"bt_net_cost"`
	MaxOpenOrders   int                               `yaml:"max_open_orders" mapstructure:"max_open_orders"`
	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"`
	StrtgPerf       *StrtgPerfConfig                  `yaml:"strtg_perf" mapstructure:"strtg_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 是根配置结构体

type DatabaseConfig

type DatabaseConfig struct {
	Url         string `yaml:"url" mapstructure:"url"`
	Retention   string `yaml:"retention" mapstructure:"retention"`
	MaxPoolSize int    `yaml:"max_pool_size" mapstructure:"max_pool_size"`
}

type ExchangeConfig

type ExchangeConfig struct {
	Name  string                    `yaml:"name" mapstructure:"name"`
	Items map[string]*ExgItemConfig `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 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"`
}

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"`
	Dirt          string                        `yaml:"dirt" mapstructure:"dirt"`
	StrtgPerf     *StrtgPerfConfig              `yaml:"strtg_perf" mapstructure:"strtg_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) Def

func (c *RunPolicyConfig) Def(k string, dv float64, p *core.Param) float64

func (*RunPolicyConfig) HyperParams

func (c *RunPolicyConfig) HyperParams() []*core.Param

func (*RunPolicyConfig) ID

func (c *RunPolicyConfig) ID() string

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) Param

func (c *RunPolicyConfig) Param(k string, dv float64) float64

func (*RunPolicyConfig) ToYaml

func (c *RunPolicyConfig) ToYaml() string

type StrtgPerfConfig

type StrtgPerfConfig 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 (*StrtgPerfConfig) Validate

func (p *StrtgPerfConfig) Validate()

type TelegramChannel

type TelegramChannel struct {
	Enable   bool     `yaml:"enable" mapstructure:"enable"`
	Type     string   `yaml:"type" mapstructure:"type"`
	MsgTypes []string `yaml:"msg_types" mapstructure:"msg_types"`
	Token    string   `yaml:"token" mapstructure:"token"`
	Channel  string   `yaml:"channel" mapstructure:"channel"`
}

type TimeTuple

type TimeTuple struct {
	StartMS int64
	EndMS   int64
}

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"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL