strategy

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STOP    = 0
	LOADING = 1
	RUNNING = 2
	REPLAY  = 3
)

* * @Description: 策略状态 * @return unc

View Source
const (
	TICKTYPE  = "TICK"
	KLINETYPE = "KLINE"
)

* * @Description: Tick类型 * @return unc

Variables

View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  1,
	MagicCookieKey:   "BASIC_PLUGIN",
	MagicCookieValue: "hello",
}

插件握手协议

View Source
var LastTimeStamp int64

测试用

Functions

This section is empty.

Types

type Base

type Base struct {
	Contract Contract

	T T

	K K

	Multiplier map[string]int64
	MinMove    map[string]float64

	Extend map[string]interface{}
	// contains filtered or unexported fields
}

func (*Base) Active

func (s *Base) Active() string

*

  • @Description: 激活插件
  • @receiver s

func (*Base) AddIndicator

func (s *Base) AddIndicator(onlypush bool, flags []string, columnvalues ...interface{})

AddIndicator

@Description: 记录回测自定义数据到CSV
@receiver s
@param onlypush 只推送给前端不记录到csv
@param columnvalues 键值对

func (*Base) Buy

func (s *Base) Buy(symbol string, price float64, volume int64, ptype string, offset string) (int32, string, error)

*

  • @Description: 买单
  • @receiver s 策略指针
  • @param symbol 合约代码
  • @param price 价格
  • @param volume 数量
  • @param ptype 订单价格类型 PRICEMARKET:市价/PRICELIMIT:限价
  • @param offset 开平仓 TRADEOPEN:开仓/TRADECLOSE:平仓
  • @return int32 报单请求id
  • @return string 订单号
  • @return error 错误信息

func (*Base) Cancel

func (s *Base) Cancel(requestid int32, ordersn string) int

*

  • @Description: 撤单
  • @receiver o
  • @param requestid 报单请求id
  • @param ordersn 订单编号
  • @return int 返回错误码

func (*Base) DetectDaemonAlive

func (s *Base) DetectDaemonAlive()

*

  • @Description: 检测daemon是否存活
  • @receiver s

func (*Base) GetInstrument

func (s *Base) GetInstrument(symbol string) (error, string, string, int64, float64)

*

  • @Description: 获取合约信息
  • @receiver s
  • @param symbol
  • @return error

func (*Base) GetInstrumentMultiple

func (s *Base) GetInstrumentMultiple(symbolT string) (error, int64, float64)

*

  • @Description: 获取合约乘数
  • @receiver s
  • @param symbol
  • @return error

func (*Base) GetLastPrice

func (s *Base) GetLastPrice(symbol string) (common.LastPrice, error)

*

  • @Description: 从本地获取最新价
  • @receiver s
  • @param symbol 合约代码
  • @param period 周期
  • @return common.LastPrice
  • @return error

func (*Base) GetMainKlineHistory

func (s *Base) GetMainKlineHistory(len int) string

*

  • @Description: 获取主合约历史k线数据
  • @receiver s
  • @param len
  • @return string

func (*Base) GetMainTickHistory

func (s *Base) GetMainTickHistory(len int) string

*

  • @Description: 获取主Tick历史数据
  • @receiver s
  • @param len
  • @return string

func (*Base) GetMainVirtualPosition

func (s *Base) GetMainVirtualPosition() int64

*

  • @Description: 获取主交易合约虚拟持仓
  • @receiver s
  • @return int64

func (*Base) GetStrategyInfo

func (s *Base) GetStrategyInfo() string

*

  • @Description: 查询策略信息
  • @receiver s
  • @return string

func (*Base) GetSubKlineHistory

func (s *Base) GetSubKlineHistory(len int) string

*

  • @Description: 获取次合约历史k线数据
  • @receiver s
  • @param len
  • @return string

func (*Base) GetSubTickHistory

func (s *Base) GetSubTickHistory(len int) string

*

  • @Description: 获取次Tick历史数据
  • @receiver s
  • @param len
  • @return string

func (*Base) GetSubVirtualPosition

func (s *Base) GetSubVirtualPosition() int64

*

  • @Description: 获取次交易合约虚拟持仓
  • @receiver s
  • @return int64

func (*Base) Hello

func (s *Base) Hello() string

*

  • @Description: 检测策略是否存活
  • @receiver s
  • @return string

func (*Base) IsLoading

func (s *Base) IsLoading() bool

* * @Description: 是否在加载历史数据状态 * @receiver s * @return bool

func (*Base) IsReplaying

func (s *Base) IsReplaying() bool

*

  • @Description: 是否回测状态
  • @receiver s
  • @return bool

func (*Base) IsRunning

func (s *Base) IsRunning() bool

* * @Description: 是否在运行 * @receiver s * @return bool

func (*Base) MakeReplayReport

func (s *Base) MakeReplayReport() string

MakeReplayReport

@Description: 生成回测报告
@receiver s
@return string

func (*Base) ReadLoadingIndicators

func (s *Base) ReadLoadingIndicators() string

ReadLoadingIndicators 读取Loading指标数据

@Description:
@receiver s
@return string

func (*Base) ReadReplayIndicators

func (s *Base) ReadReplayIndicators() string

ReadReplayIndicators 读取指标数据

@Description:
@receiver s
@return string

func (*Base) ReadRunningIndicators

func (s *Base) ReadRunningIndicators() string

ReadRunningIndicators 读取Running指标数据

@Description:
@receiver s
@return string

func (*Base) RegOnInit

func (s *Base) RegOnInit(on OnInitType)

*

  • @Description: 注册初始化回调函数
  • @receiver s
  • @param on

func (*Base) RegOnKline

func (s *Base) RegOnKline(on OnKlineType)

*

  • @Description: 注册kline行情回调函数
  • @receiver s
  • @param on

func (*Base) RegOnTick

func (s *Base) RegOnTick(on OnTickType)

*

  • @Description: 注册tick行情回调函数
  • @receiver s
  • @param on

func (*Base) Replay

func (s *Base) Replay(startdate string, enddate string) string

*

  • @Description: 回测
  • @receiver s
  • @param staname
  • @param startdate
  • @param enddate
  • @return error

func (*Base) Run

func (s *Base) Run() string

*

  • @Description: 运行策略
  • @receiver s
  • @return error

func (*Base) Sell

func (s *Base) Sell(symbol string, price float64, volume int64, ptype string, offset string) (int32, string, error)

*

  • @Description: 卖单
  • @receiver s 策略指针
  • @param symbol 合约代码
  • @param price 价格
  • @param volume 数量
  • @param ptype 订单价格类型 PRICEMARKET:市价/PRICELIMIT:限价
  • @param offset 开平仓 TRADEOPEN:开仓/TRADECLOSE:平仓
  • @return int32 报单请求id
  • @return string 订单号
  • @return error 错误信息

func (*Base) SetConfig

func (s *Base) SetConfig(daemonhost string, daemonwebhost string, daemonchannel string, quoteserverhost string, quotehttphost string, tradeserverhost string, apikey string) string

*

  • @Description: 设置配置文件
  • @receiver s

* @param daemonhost 策略守护程序地址

  • @param string 行情服务器地址
  • @param string 交易服务器地址
  • @param path 插件所在目录
  • @param staname 策略名称

func (*Base) Stop

func (s *Base) Stop() string

*

  • @Description: 停止策略
  • @receiver s
  • @return error

func (*Base) StopReplay

func (s *Base) StopReplay() string

*

  • @Description: 停止回测
  • @receiver s
  • @return string

func (*Base) TailOrder

func (s *Base) TailOrder(requestid int32, ordersn string, timeout int64, retry int, limit float64) error

*

  • @Description: 追单
  • @receiver s
  • @param requestid 原订单报单请求id
  • @param ordersn 原订单号
  • @param timeout 超时时间(毫秒单位)
  • @param retry 尝试次数
  • @param limit 限定价格
  • @return error

type ColumnValue

type ColumnValue struct {
	Name  string
	Value string
}

* * @Description: 列名值键值对参数结构 * @Name: 列名 * @Value: 值

type Contract

type Contract struct {
	MainQuote         string
	MainQuoteLen      int
	SubQuote          string
	SubQuoteLen       int
	MainKline         common.KlineKey
	MainKlineLen      int
	SubKline          common.KlineKey
	SubKlineLen       int
	MainTrade         string
	MainTradeExchange string
	SubTrade          string
	SubTradeExchange  string
}

* * @Description: 合约相关结构 * @MainQuote: 监控Quote行情主合约 * @SubQuote: 监控Quote行情次合约 * @Mainkline: 监控Kline行情主合约 * @subkline: 监控Kline行情次合约 * @MainTrade: 主交易合约 * @SubTrade: 次交易合约

type Indicator

type Indicator struct {
	LoadingFile         *os.File
	LoadingFileName     string
	LoadingColumnNames  []string
	LoadingColumnValues map[string]string
	LoadingCsvWritter   *csv.Writer
	RunningFile         *os.File
	RunningFileName     string
	RunningColumnNames  []string
	RunningColumnValues map[string]string
	RunningCsvWritter   *csv.Writer
	// contains filtered or unexported fields
}

type K

type K struct {
	Time         map[common.KlineKey][]time.Time
	Open         map[common.KlineKey][]float64
	High         map[common.KlineKey][]float64
	Low          map[common.KlineKey][]float64
	Close        map[common.KlineKey][]float64
	Volume       map[common.KlineKey][]int64
	OpenInterest map[common.KlineKey][]int64
}

type KlineBuffer

type KlineBuffer struct {
	Buffer    map[common.KlineKey][]common.Kline
	BufferLen map[common.KlineKey]int
}

* * @Description: K线缓存器

type OnInitType

type OnInitType func()

定义Init回调函数

type OnKlineType

type OnKlineType func(klinekey common.KlineKey, kline common.Kline, offsetflag bool)

定义Kline回调函数

type OnTickType

type OnTickType func(symbol string, quote common.Quote)

定义Tick回调函数

type Replayer

type Replayer struct {
	DataFile              *os.File
	DataFileName          string
	DataColumnNames       []string
	DataColumnValues      map[string]string
	DataCsvWritter        *csv.Writer
	IndicatorFile         *os.File
	IndicatorFileName     string
	IndicatorColumnNames  []string
	IndicatorColumnValues map[string]string
	IndicatorCsvWritter   *csv.Writer
}

* * @Description: 回测日志结构

type StrategyIf

type StrategyIf interface {
	// 检测插件
	Hello() string

	// 运行策略
	Run() string

	// 停止策略
	Stop() string

	// 回测策略
	Replay(startdate string, enddate string) string

	// 生成回测报告
	MakeReplayReport() string

	// 停止回测
	StopReplay() string

	// 激活插件
	Active() string

	// 设置配置参数
	SetConfig(daemonhost string, daemonwebhost string, daemonchannel string, quoteserverhost string, quotehttphost string, tradeserverhost string, apikey string) string

	// 获取策略信息
	GetStrategyInfo() string

	// 获取主Tick行情历史k线
	GetMainTickHistory(len int) string

	// 获取次Tick行情历史k线
	GetSubTickHistory(len int) string

	// 获取主合约行情历史k线
	GetMainKlineHistory(len int) string

	// 获取次合约行情历史k线
	GetSubKlineHistory(len int) string

	// 读取Loading指标数据
	ReadLoadingIndicators() string

	// 读取Running指标数据
	ReadRunningIndicators() string

	// 读取回测指标数据
	ReadReplayIndicators() string
}

type StrategyPlugin

type StrategyPlugin struct {
	// Impl Injection
	Impl StrategyIf
}

策略插件

func (StrategyPlugin) Client

func (StrategyPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error)

func (*StrategyPlugin) Server

func (p *StrategyPlugin) Server(*plugin.MuxBroker) (interface{}, error)

type StrategyRPCServer

type StrategyRPCServer struct {
	Impl StrategyIf
}

* * @Description: 策略插件服务端RPC

func (*StrategyRPCServer) Active

func (s *StrategyRPCServer) Active(args interface{}, resp *string) error

func (*StrategyRPCServer) GetMainKlineHistory

func (s *StrategyRPCServer) GetMainKlineHistory(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) GetMainTickHistory

func (s *StrategyRPCServer) GetMainTickHistory(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) GetStrategyInfo

func (s *StrategyRPCServer) GetStrategyInfo(args interface{}, resp *string) error

func (*StrategyRPCServer) GetSubKlineHistory

func (s *StrategyRPCServer) GetSubKlineHistory(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) GetSubTickHistory

func (s *StrategyRPCServer) GetSubTickHistory(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) Hello

func (s *StrategyRPCServer) Hello(args interface{}, resp *string) error

func (*StrategyRPCServer) MakeReplayReport

func (s *StrategyRPCServer) MakeReplayReport(args interface{}, resp *string) error

func (*StrategyRPCServer) ReadLoadingIndicators

func (s *StrategyRPCServer) ReadLoadingIndicators(args interface{}, resp *string) error

func (*StrategyRPCServer) ReadReplayIndicators

func (s *StrategyRPCServer) ReadReplayIndicators(args interface{}, resp *string) error

func (*StrategyRPCServer) ReadRunningIndicators

func (s *StrategyRPCServer) ReadRunningIndicators(args interface{}, resp *string) error

func (*StrategyRPCServer) Replay

func (s *StrategyRPCServer) Replay(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) Run

func (s *StrategyRPCServer) Run(args interface{}, resp *string) error

func (*StrategyRPCServer) SetConfig

func (s *StrategyRPCServer) SetConfig(args map[string]interface{}, resp *string) error

func (*StrategyRPCServer) Stop

func (s *StrategyRPCServer) Stop(args interface{}, resp *string) error

func (*StrategyRPCServer) StopReplay

func (s *StrategyRPCServer) StopReplay(args interface{}, resp *string) error

type StrategyRPClient

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

*

  • @Description: 策略插件客户端RPC

func (*StrategyRPClient) Active

func (g *StrategyRPClient) Active() string

func (*StrategyRPClient) GetMainKlineHistory

func (g *StrategyRPClient) GetMainKlineHistory(len int) string

func (*StrategyRPClient) GetMainTickHistory

func (g *StrategyRPClient) GetMainTickHistory(len int) string

func (*StrategyRPClient) GetStrategyInfo

func (g *StrategyRPClient) GetStrategyInfo() string

func (*StrategyRPClient) GetSubKlineHistory

func (g *StrategyRPClient) GetSubKlineHistory(len int) string

func (*StrategyRPClient) GetSubTickHistory

func (g *StrategyRPClient) GetSubTickHistory(len int) string

func (*StrategyRPClient) Hello

func (g *StrategyRPClient) Hello() string

func (*StrategyRPClient) MakeReplayReport

func (g *StrategyRPClient) MakeReplayReport() string

func (*StrategyRPClient) ReadLoadingIndicators

func (g *StrategyRPClient) ReadLoadingIndicators() string

func (*StrategyRPClient) ReadReplayIndicators

func (g *StrategyRPClient) ReadReplayIndicators() string

func (*StrategyRPClient) ReadRunningIndicators

func (g *StrategyRPClient) ReadRunningIndicators() string

func (*StrategyRPClient) Replay

func (g *StrategyRPClient) Replay(startdate string, enddate string) string

func (*StrategyRPClient) Run

func (g *StrategyRPClient) Run() string

func (*StrategyRPClient) SetConfig

func (g *StrategyRPClient) SetConfig(daemonhost string, daemonwebhost string, daemonchannel string, quoteserverhost string, quotehttphost string, tradeserverhost string, apikey string) string

func (*StrategyRPClient) Stop

func (g *StrategyRPClient) Stop() string

func (*StrategyRPClient) StopReplay

func (g *StrategyRPClient) StopReplay() string

type T

type T struct {
	Time      map[string][]time.Time
	LastPrice map[string][]float64
}

Jump to

Keyboard shortcuts

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