config

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ResourcesPath 资源路径
	ResourcesPath = "resources"
)

Variables

View Source
var (
	ErrTimeFormat  = exception.New(errnoConfig+1, "时间格式错误")
	ErrRangeFormat = exception.New(errnoConfig+2, "数值范围格式错误")
)

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 int) string

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

func StartPprof

func StartPprof()

StartPprof 启动性能分析工具

Types

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 数值范围

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(text []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"` // 基础路径
	Runtime RuntimeParameter `yaml:"runtime"` // 运行时参数
	Rules   RuleParameter    `yaml:"rules"`   // 规则参数
	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
	IgnoreCodes                 []string    `yaml:"ignore_codes" default:"[\"sh68\",\"bj\"]"`        // 忽略的证券代码段, 默认忽略科创板和北交所全部
	SafetyScoreMin              float64     `yaml:"safety_score_min" default:"80"`                   // 80 通达信安全分最小值
	MaximumIncreaseWithin5days  float64     `yaml:"maximum_increase_within_5_days" default:"20.00"`  // 20.00 5日累计最大涨幅
	MaximumIncreaseWithin10days float64     `yaml:"maximum_increase_within_10_days" default:"70.00"` // 70.00 10日累计最大涨幅
	MaxReduceAmount             float64     `yaml:"max_reduce_amount" default:"-1000"`               // -1000 最大流出1000万
	VolumeRatioMax              float64     `yaml:"volume_ratio_max" default:"3.82"`                 // 1.800 成交量放大不能超过1.8
	Price                       NumberRange `yaml:"price" default:""`                                // 股价: 4.9E-324~1.7976931348623157e+308
	Capital                     NumberRange `yaml:"capital" default:"2~20"`                          // 流通股本, 默认2亿~20亿
	MarketCap                   NumberRange `yaml:"market_cap" default:"4~600"`                      // 流通市值, 默认4亿~600亿
	OpenRate                    NumberRange `yaml:"open_rate"  default:""`                           // 开盘涨幅, 默认不限制
	QuantityRatio               NumberRange `yaml:"quantity_ratio" default:""`                       // 开盘量比, 默认不限制
	TurnZ                       NumberRange `yaml:"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"`                  // 情绪范围
}

RuleParameter 规则参数

func RuleConfig added in v0.7.6

func RuleConfig() RuleParameter

RuleConfig 获取交易配置

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 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) UnmarshalText added in v0.9.1

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

UnmarshalText 设置默认值调用

func (*TimeRange) UnmarshalYAML added in v0.9.1

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

type TradeRule

type TradeRule struct {
	Id                  int            `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
	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        int            `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%
	GapDown             bool           `name:"跳空低开" yaml:"gap_down" default:"true"`                            // 买入是否允许跳空低开, 默认是允许
	// contains filtered or unexported fields
}

TradeRule 交易规则

func GetTradeRule added in v0.7.7

func GetTradeRule(code int) *TradeRule

GetTradeRule 通过策略编码查找规则

func (*TradeRule) BuyEnable added in v0.7.7

func (this *TradeRule) BuyEnable() bool

BuyEnable 获取可买入状态

func (*TradeRule) Enable added in v0.7.7

func (this *TradeRule) Enable() bool

Enable 策略是否有效

func (*TradeRule) Filter added in v0.9.7

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

func (*TradeRule) IsCookieCutterForSell added in v0.7.7

func (this *TradeRule) IsCookieCutterForSell() bool

IsCookieCutterForSell 是否一刀切卖出

func (*TradeRule) NumberOfTargets added in v0.7.7

func (this *TradeRule) NumberOfTargets() int

NumberOfTargets 获得可买入标的总数

func (*TradeRule) QmtStrategyName added in v0.7.9

func (this *TradeRule) QmtStrategyName() string

func (*TradeRule) SellEnable added in v0.7.7

func (this *TradeRule) SellEnable() bool

SellEnable 获取可卖出状态

func (*TradeRule) StockList added in v0.7.7

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

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

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            `yaml:"TopN" default:"3"`                                                                   // 最多输出前多少名个股
	HaveETF              bool           `yaml:"是否包含ETF" default:"false"`                                                            // 是否包含ETF
	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           []TradeRule    `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) 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