config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TenThousand = 1e4               // 万
	Million     = 100 * TenThousand // 百万
	Billion     = 100 * Million     // 1亿
)
View Source
const (
	// ResourcesPath 资源路径
	ResourcesPath = "resources"
)

Variables

View Source
var (
	ErrRangeFormat = exception.New(errnoConfig+0, "数值范围格式错误")
)

错误信息

View Source
var (
	ErrTimeFormat = exception.New(errnoConfig+1, "时间格式错误")
)

Functions

func CrontabConfig added in v0.7.7

func CrontabConfig() map[string]JobParameter

CrontabConfig 获取定时任务配置

func GetConfigFilename

func GetConfigFilename() string

GetConfigFilename 获取配置文件路径

func PprofEnable added in v0.8.1

func PprofEnable() bool

PprofEnable 获取配置中pprof开关

func QmtStrategyNameFromId added in v0.7.9

func QmtStrategyNameFromId(strategyCode uint64) string

QmtStrategyNameFromId 通过策略ID返回用于在QMT系统中表示的string类型的策略名称

func StartPprof

func StartPprof()

StartPprof 启动性能分析工具

Types

type DataParameter added in v1.1.8

type DataParameter struct {
	Trans HistoricalTradingDataParameter `name:"历史成交数据" yaml:"trans"`
}

DataParameter 数据源参数

func GetDataConfig added in v1.1.8

func GetDataConfig() DataParameter

GetDataConfig 取得数据配置

type HistoricalTradingDataParameter added in v1.1.8

type HistoricalTradingDataParameter struct {
	BeginDate string `name:"默认开始日期" yaml:"begin_date" default:"2023-10-01"`
}

HistoricalTradingDataParameter 历史成交数据参数

type JobParameter added in v0.7.7

type JobParameter struct {
	//Name    string `yaml:"name" default:""`       // 任务名称
	Trigger string `yaml:"trigger"  default:""`   // 触发条件
	Enable  bool   `yaml:"enable" default:"true"` // 任务是否有效
}

JobParameter 定时任务配置

func GetJobParameter added in v0.7.7

func GetJobParameter(name string) *JobParameter

GetJobParameter 获取计划执行任务

type NumberRange added in v0.9.1

type NumberRange struct {
	// contains filtered or unexported fields
}

NumberRange 数值范围

支持:
1) "1~2",   最小值1, 最大值2
2) "",      最小值默认, 最大值默认
3) "3.82",  最小值, 最大值默认
4) "3.82~", 最小值, 最大值默认
5) "~3.82", 最小值默认, 最大值

func (NumberRange) MarshalText added in v1.0.0

func (this NumberRange) MarshalText() (text []byte, err error)

func (*NumberRange) Max added in v1.0.0

func (this *NumberRange) Max() float64

func (*NumberRange) Min added in v1.0.0

func (this *NumberRange) Min() float64

func (*NumberRange) Parse added in v0.9.1

func (this *NumberRange) Parse(text string) error

func (NumberRange) String added in v0.9.1

func (this NumberRange) String() string

func (*NumberRange) UnmarshalText added in v0.9.1

func (this *NumberRange) UnmarshalText(bytes []byte) error

UnmarshalText 设置默认值调用

func (*NumberRange) UnmarshalYAML added in v0.9.1

func (this *NumberRange) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML YAML自定义解析

func (*NumberRange) Validate added in v0.9.1

func (this *NumberRange) Validate(v float64) bool

Validate 验证

type PprofParameter

type PprofParameter struct {
	Enable bool `yaml:"enable" default:"false"` // 是否开启go tool pprof
	Port   int  `yaml:"port" default:"6060"`    // pprof web端口
}

type Quant1XConfig

type Quant1XConfig struct {
	BaseDir    string           `yaml:"basedir"` // 基础路径
	DataSource DataParameter    `yaml:"data"`    // 数据源
	Runtime    RuntimeParameter `yaml:"runtime"` // 运行时参数
	Trader     TraderParameter  `yaml:"trader"`  // 预览交易参数
}

Quant1XConfig Quant1X基础配置

var (
	// GlobalConfig engine配置信息
	GlobalConfig Quant1XConfig
)

func LoadConfig

func LoadConfig() (config Quant1XConfig, found bool)

LoadConfig 加载配置文件

func ReadConfig

func ReadConfig(rootPath string) (config Quant1XConfig)

ReadConfig 读取配置文件

type RuleParameter

type RuleParameter struct {
	SectorsFilter               bool        `yaml:"sectors_filter" default:"false"`              // 是否启用板块过滤, false代表全市场扫描
	SectorsTopN                 int         `yaml:"sectors_top_n" default:"3"`                   // 最多关联多少个板块, 默认3个
	StockTopNInSector           int         `yaml:"stock_top_n_in_sector" default:"5"`           // 板块内个股排名前N
	IgnoreRuleGroup             []int       `yaml:"ignore_rule_group"`                           // 忽略规则组合
	IgnoreCodes                 []string    `yaml:"ignore_codes" default:"[\"sh68\",\"bj\"]"`    // 忽略的证券代码段, 默认忽略科创板和北交所全部
	MaximumIncreaseWithin5days  float64     `yaml:"maximum_increase_within_5d" default:"20.00"`  // 20.00 5日累计最大涨幅
	MaximumIncreaseWithin10days float64     `yaml:"maximum_increase_within_10d" default:"70.00"` // 70.00 10日累计最大涨幅
	MaxReduceAmount             float64     `yaml:"max_reduce_amount" default:"-1000"`           // -1000 最大流出1000万
	SafetyScore                 NumberRange `yaml:"safety_score" default:"80~"`                  // 80 通达信安全分最小值
	VolumeRatio                 NumberRange `yaml:"volume_ratio" default:"0.382~3.820"`          // 1.800 成交量放大不能超过1.8
	Capital                     NumberRange `yaml:"capital" default:"0.5~20"`                    // 流通股本, 默认0.5亿~20亿
	MarketCap                   NumberRange `yaml:"market_cap" default:"4~600"`                  // 流通市值, 默认4亿~600亿
	Price                       NumberRange `yaml:"price" default:"2~"`                          // 股价: 4.9E-324~1.7976931348623157e+308
	OpenChangeRate              NumberRange `yaml:"open_change_rate"  default:""`                // 开盘涨幅, 默认不限制
	OpenQuantityRatio           NumberRange `yaml:"open_quantity_ratio" default:""`              // 开盘量比, 默认不限制
	OpenTurnZ                   NumberRange `yaml:"open_turn_z" default:""`                      // 开盘换手, 默认不限制
	Vix                         NumberRange `yaml:"vix" default:""`                              // 波动率, 默认不限制
	TurnoverRate                NumberRange `yaml:"turnover_rate" default:""`                    // 换手率范围, 默认不限制
	AmplitudeRatio              NumberRange `yaml:"amplitude_ratio" default:""`                  // 振幅范围, 默认不限制
	BiddingVolume               NumberRange `yaml:"bidding_volume" default:""`                   // 5档行情委托平均值范围, 默认不限制
	Sentiment                   NumberRange `yaml:"sentiment" default:"38.2~61.80"`              // 情绪范围
	GapDown                     bool        `yaml:"gap_down" default:"true"`                     // 买入是否允许跳空低开, 默认是允许
}

RuleParameter 规则参数

type RuntimeParameter

type RuntimeParameter struct {
	Pprof   PprofParameter          `name:"性能分析" yaml:"pprof"`
	Debug   bool                    `name:"业务调试开关" yaml:"debug" default:"false"`
	Crontab map[string]JobParameter `name:"定时任务" yaml:"crontab" default:"{}"`
}

RuntimeParameter 运行时配置参数

type StrategyParameter added in v1.0.1

type StrategyParameter struct {
	Id                          uint64         `name:"策略编码" yaml:"id" default:"1"`                                     // 策略ID, 默认是1
	Auto                        bool           `name:"是否自动执行" yaml:"auto" default:"false"`                             // 是否自动执行
	Name                        string         `name:"策略名称" yaml:"name"`                                               // 策略名称
	Flag                        string         `name:"订单标识" yaml:"flag"`                                               // 订单标识,分早盘,尾盘和盘中
	Session                     TradingSession `name:"时间范围" yaml:"time" default:"09:30:00~11:30:00,13:00:00~14:56:30"` // 可操作的交易时段
	Weight                      float64        `name:"持仓占比" yaml:"weight" default:"0"`                                 // 策略权重, 默认0, 由系统自动分配
	Total                       int            `name:"订单数上限" yaml:"total" default:"3"`                                 // 订单总数, 默认是3
	PriceCageRatio              float64        `name:"价格笼子比例" yaml:"price_cage_ratio" default:"0.00"`                  // 价格笼子比例, 默认0%
	MinimumPriceFluctuationUnit float64        `name:"价格变动最小单位" yaml:"minimum_price_fluctuation_unit" default:"0.05"`  // 价格最小变动单位, 默认0.05
	FeeMax                      float64        `name:"最大费用" yaml:"fee_max" default:"20000.00"`                         // 可投入资金-最大
	FeeMin                      float64        `name:"最小费用" yaml:"fee_min" default:"10000.00"`                         // 可投入资金-最小
	Sectors                     []string       `name:"板块" yaml:"sectors" default:""`                                   // 板块, 策略适用的板块列表, 默认板块为空, 即全部个股
	IgnoreMarginTrading         bool           `name:"剔除两融" yaml:"ignore_margin_trading" default:"true"`               // 剔除两融标的, 默认是剔除
	HoldingPeriod               int            `name:"持仓周期" yaml:"holding_period" default:"1"`                         // 持仓周期, 默认为1天, 即T+1日触发117号策略
	SellStrategy                uint64         `name:"卖出策略" yaml:"sell_strategy" default:"117"`                        // 卖出策略, 默认117
	TakeProfitRatio             float64        `name:"止盈比例" yaml:"take_profit_ratio" default:"15.00"`                  // 止盈比例, 默认15%
	StopLossRatio               float64        `name:"止损比例" yaml:"stop_loss_ratio" default:"-2.00"`                    // 止损比例, 默认-2%
	Rules                       RuleParameter  `name:"规则参数" yaml:"rules"`                                              // 过滤规则
	// contains filtered or unexported fields
}

StrategyParameter 策略参数

func GetStrategyParameterByCode added in v1.0.1

func GetStrategyParameterByCode(strategyCode uint64) *StrategyParameter

GetStrategyParameterByCode 通过策略编码查找规则

func (*StrategyParameter) BuyEnable added in v1.0.1

func (this *StrategyParameter) BuyEnable() bool

BuyEnable 获取可买入状态

func (*StrategyParameter) Enable added in v1.0.1

func (this *StrategyParameter) Enable() bool

Enable 策略是否有效

func (*StrategyParameter) Filter added in v1.0.1

func (this *StrategyParameter) Filter(codes []string) []string

func (*StrategyParameter) IsCookieCutterForSell added in v1.0.1

func (this *StrategyParameter) IsCookieCutterForSell() bool

IsCookieCutterForSell 是否一刀切卖出

func (*StrategyParameter) NumberOfTargets added in v1.0.1

func (this *StrategyParameter) NumberOfTargets() int

NumberOfTargets 获得可买入标的总数

func (*StrategyParameter) QmtStrategyName added in v1.0.1

func (this *StrategyParameter) QmtStrategyName() string

func (*StrategyParameter) SellEnable added in v1.0.1

func (this *StrategyParameter) SellEnable() bool

SellEnable 获取可卖出状态

func (*StrategyParameter) StockList added in v1.0.1

func (this *StrategyParameter) StockList() []string

StockList 取得可以交易的证券代码列表

type TimeRange

type TimeRange struct {
	// contains filtered or unexported fields
}

TimeRange 时间范围

func (*TimeRange) IsTrading

func (this *TimeRange) IsTrading(timestamp ...string) bool

func (*TimeRange) Parse added in v0.9.1

func (this *TimeRange) Parse(text string) error

func (TimeRange) String

func (this TimeRange) String() string

func (*TimeRange) UnmarshalYAML added in v0.9.1

func (this *TimeRange) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML YAML自定义解析

type TraderParameter added in v0.7.6

type TraderParameter struct {
	AccountId                   string              `name:"账号ID" yaml:"account_id" dataframe:"888xxxxxxx"`                                      // 账号ID
	OrderPath                   string              `name:"订单路径" yaml:"order_path"`                                                             // 订单路径
	TopN                        int                 `name:"TopN" yaml:"top_n" default:"3"`                                                      // 最多输出前多少名个股
	HaveETF                     bool                `name:"是否包含ETF" yaml:"have_etf" default:"false"`                                            // 是否包含ETF
	PriceCageRatio              float64             `name:"价格笼子比例" yaml:"price_cage_ratio" default:"0.02"`                                      // 价格笼子比例, 默认2%, 小于0就是无限制
	MinimumPriceFluctuationUnit float64             `name:"价格变动最小单位" yaml:"minimum_price_fluctuation_unit" default:"0.10"`                      // 价格最小变动单位, 默认0.10
	StampDutyRateForBuy         float64             `name:"买入印花税" yaml:"stamp_duty_rate_for_buy" default:"0.0000"`                              // 印花说-买入, 没有
	StampDutyRateForSell        float64             `name:"卖出印花税" yaml:"stamp_duty_rate_for_sell" default:"0.0010"`                             // 印花说-卖出, 默认是千分之1
	TransferRate                float64             `name:"过户费" yaml:"transfer_rate" default:"0.0006"`                                          // 过户费, 双向, 默认是万分之6
	CommissionRate              float64             `name:"佣金率" yaml:"commission_rate" default:"0.00025"`                                       // 券商佣金, 双向, 默认万分之2.5
	CommissionMin               float64             `name:"佣金最低" yaml:"commission_min" default:"5.0000"`                                        // 券商佣金最低, 双向, 默认5.00
	PositionRatio               float64             `name:"持仓占比" yaml:"position_ratio" default:"0.5000"`                                        // 当日持仓占比, 默认50%
	KeepCash                    float64             `name:"保留现金" yaml:"keep_cash" default:"10000.00"`                                           // 保留现金, 默认10000.00
	BuyAmountMax                float64             `name:"可买最大金额" yaml:"buy_amount_max" default:"250000.00"`                                   // 买入最大金额, 默认250000.00
	BuyAmountMin                float64             `name:"可买最小金额" yaml:"buy_amount_min" default:"1000.00"`                                     // 买入最小金额, 默认1000.00
	Role                        TraderRole          `name:"角色" yaml:"role" default:"3"`                                                         // 交易员角色, 默认是需要人工干预, 系统不做自动交易处理
	ProxyUrl                    string              `name:"代理URL" yaml:"proxy_url" default:"http://127.0.0.1:18168/qmt"`                        // 禁止使用公网地址
	Strategies                  []StrategyParameter `name:"策略集合" yaml:"strategies"`                                                             // 策略集合
	CancelSession               TradingSession      `name:"撤单时段" yaml:"cancel" default:"09:15:00~09:19:59,09:25:00~11:29:59,13:00:00~14:59:59"` // 可撤单配置
}

TraderParameter 预览交易通道参数

func TraderConfig added in v0.7.6

func TraderConfig() TraderParameter

TraderConfig 获取交易配置

func (TraderParameter) ResetPositionRatio added in v0.7.7

func (t TraderParameter) ResetPositionRatio()

ResetPositionRatio 重置仓位占比

func (TraderParameter) TotalNumberOfTargets added in v0.7.7

func (t TraderParameter) TotalNumberOfTargets() int

TotalNumberOfTargets 统计标的总数

type TraderRole added in v0.7.7

type TraderRole int

TraderRole 交易员角色

const (
	RoleDisable TraderRole = iota // 禁止自动化交易
	RolePython                    // python脚本自动化交易
	RoleProxy                     // 代理交易模式
	RoleManual                    // 人工干预, 作用同
)

type TradingSession

type TradingSession struct {
	// contains filtered or unexported fields
}

TradingSession 交易时段

func (*TradingSession) CanStopLoss added in v0.9.0

func (this *TradingSession) CanStopLoss(timestamp ...string) bool

CanStopLoss 当前时段是否可以进行止损操作

如果是3个时段, 止损操作在第2时段, 如果是4个时段, 止损在第3个
如果是2个时段, 则是第2个时段, 也就是最后一个时段

func (*TradingSession) CanTakeProfit added in v0.9.0

func (this *TradingSession) CanTakeProfit(timestamp ...string) bool

CanTakeProfit 当前时段是否可以止盈

func (*TradingSession) Index added in v0.7.9

func (this *TradingSession) Index(timestamp ...string) int

Index 判断timestamp是第几个交易时段

func (*TradingSession) IsTodayLastSession added in v0.7.9

func (this *TradingSession) IsTodayLastSession(timestamp ...string) bool

IsTodayLastSession 当前时段是否今天最后一个交易时段

备选函数名 IsTodayFinalSession

func (*TradingSession) IsTrading

func (this *TradingSession) IsTrading(timestamp ...string) bool

IsTrading 是否交易时段

func (TradingSession) MarshalText added in v1.0.0

func (this TradingSession) MarshalText() (text []byte, err error)

func (*TradingSession) Parse added in v0.9.1

func (this *TradingSession) Parse(text string) error

func (*TradingSession) Size added in v0.7.9

func (this *TradingSession) Size() int

Size 获取时段总数

func (TradingSession) String

func (this TradingSession) String() string

func (*TradingSession) UnmarshalText added in v0.9.1

func (this *TradingSession) UnmarshalText(text []byte) error

UnmarshalText 设置默认值调用

func (*TradingSession) UnmarshalYAML added in v0.9.1

func (this *TradingSession) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML YAML自定义解析

type ValueRange

type ValueRange[T ValueType] struct {
	// contains filtered or unexported fields
}

ValueRange 数值范围

func ParseRange

func ParseRange[T ValueType](text string) ValueRange[T]

func (ValueRange[T]) In

func (r ValueRange[T]) In(v T) bool

In 检查是否包含在范围内

type ValueType

type ValueType interface {
	~int | ~float64 | ~string
}

Jump to

Keyboard shortcuts

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