goalgo

package module
v0.0.0-...-9f5570a Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 23 Imported by: 0

README

goalgo

A real-time quantitative trading platform in Golang.

这是一个基于 Go 的量化系统,此项目不支持回测,新项目请移步: [crex] https://github.com/coinrust/crex (同时支持BitMEX, Deribit, ByBit...)

目前支持基于以下两个库编写策略

GoEx https://github.com/nntaoli-project/GoEx

bitmex-api https://github.com/frankrap/bitmex-api

其中 bitmexwrap 提供了对 BitMEX 交易所的支持,内部集成了 Rest 和 WebSocket 接口

欢迎交流,欲使用此系统,请自行登录以下官网注册账号:

https://www.coinrust.com

如有问题,请联系加QQ群: 932289088

1.简单的基于 GoEx 策略脚本:

package main

import (
	"time"

	"github.com/nntaoli-project/GoEx"
	"github.com/frankrap/goalgo"
	"github.com/frankrap/goalgo/algo"
	"github.com/frankrap/goalgo/log"
)

// SimpleGoExStrategy 简单的GoEx策略
type SimpleGoExStrategy struct {
	algo.GoExStrategy
}

// Init 策略初始化方法,必须实现
func (s *SimpleGoExStrategy) Init() error {
	log.Info("Init")
	return nil
}

// Run 策略主逻辑,必须实现
func (s *SimpleGoExStrategy) Run() error {
	log.Info("Run")
	for s.IsRunning() {
		time.Sleep(5 * time.Second)
		// 获取交易所 Ticker 数据
		ticker, err := s.Exchange.GetTicker(goex.BTC_USDT)
		if err != nil {
			log.Errorf("%v", err)
			continue
		}
		log.Infof("Ticker %#v", ticker)
	}
	return nil
}

func main() {
	s := &SimpleGoExStrategy{}
	goalgo.Serve(s)
}

2.简单的基于 bitmexwrap(BitMEX 期货市场)策略脚本:

package main

import (
	"time"

	"github.com/frankrap/goalgo"
	"github.com/frankrap/goalgo/algo"
	"github.com/frankrap/goalgo/log"
)

// BitMEXDemoStrategy 示例策略(BitMEX)
type BitMEXDemoStrategy struct {
	algo.BitMEXStrategy
}

// Init 策略初始化方法,必须实现
func (s *BitMEXDemoStrategy) Init() error {
	log.Info("Init")
	balance, err := s.Exchange.Balance()
	if err != nil {
		log.Errorf("Balance error: %v", err)
		return err
	}
	log.Infof("balance: %v", balance)

	return nil
}

// Run 策略主逻辑,必须实现
func (s *BitMEXDemoStrategy) Run() error {
	log.Info("Run")
	for s.IsRunning() {
		time.Sleep(3 * time.Second)
		ticker, err := s.Exchange.Ticker()
		if err != nil {
			log.Errorf("%v", err)
			continue
		}
		log.Infof("ticker: %v", ticker)
	}
	return nil
}

func main() {
	s := &BitMEXDemoStrategy{}
	goalgo.Serve(s)
}
Thanks

This project uses the following external projects or products

  1. [RabbitMQ] https://www.rabbitmq.com/
  2. [PostgreSQL] https://www.postgresql.org/
  3. [ClickHouse] https://clickhouse.yandex/
  4. [Docker] https://www.docker.com/
  5. [GoEx] https://github.com/nntaoli-project/GoEx
  6. [coinex] https://github.com/SuperGod/coinex
  7. [porthos-go] https://github.com/porthos-rpc/porthos-go
  8. [go-plugin] https://github.com/hashicorp/go-plugin
  9. [gin] https://github.com/gin-gonic/gin
  10. [vuejs] https://vuejs.org/
  11. ...
捐赠

BTC:17XauetDWtwAZKHRyEw3DpYcRqzhKZzPHq

ETH:0x5e065711852fda9b75c4e490b1e35eea89b9aaa5

XRP:rshdB4kyxXkuPCtCgZw8DrcuSo7jEWfqck

Documentation

Index

Constants

View Source
const (
	// OptionTag 选项Tag
	OptionTag = "option"
)
View Source
const (
	PluginMapStrategyCtlKey = "strategyCtl"
)

Variables

View Source
var (
	// ErrNotFound is returned when an item or index is not in the database.
	ErrNotFound = errors.New("not found")
)
View Source
var HandshakeConfig = plugin.HandshakeConfig{
	ProtocolVersion:  plugin.CoreProtocolVersion,
	MagicCookieKey:   "STRATEGY_PLUGIN",
	MagicCookieValue: "QtMWr4VtAC*r",
}

pluginMap is the map of plugins we can dispense.

View Source
var PluginMap = map[string]plugin.Plugin{
	PluginMapStrategyCtlKey: &StrategyPlugin{},
}

Functions

func RegisterRobotCtlServer

func RegisterRobotCtlServer(s *grpc.Server, srv RobotCtlServer)

func Serve

func Serve(strategy Strategy)

func SetValue

func SetValue(key string, value Value) error

SetValue 设置一个全局变量

func ToBool

func ToBool(value interface{}) bool

ToBool convert any type to boolean

func ToFloat

func ToFloat(value interface{}) float64

ToFloat convert any type to float

func ToFloat32

func ToFloat32(value interface{}) float32

ToFloat32 convert any type to float32

func ToInt

func ToInt(value interface{}) int

ToInt convert any type to int

func ToInt64

func ToInt64(value interface{}) int64

ToInt64 convert any type to int64

func ToUint64

func ToUint64(value interface{}) uint64

ToUint64 convert any type to uint64

Types

type AfterOptionsChanged

type AfterOptionsChanged interface {
	AfterOptionsChanged()
}

AfterOptionsChanged 策略参数改变接口,实现此接口的策略,在动态改变参数后触发此方法

type BaseStrategy

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

BaseStrategy 策略基础类

func (*BaseStrategy) GetCommand

func (s *BaseStrategy) GetCommand() *Command

GetCommand 获取一个命令结构

func (*BaseStrategy) GetOptions

func (s *BaseStrategy) GetOptions() (optionMap map[string]*OptionInfo)

GetOptions 获取参数

func (*BaseStrategy) GetProxy

func (s *BaseStrategy) GetProxy() string

GetProxy 获取当前代理

func (*BaseStrategy) GetState

func (s *BaseStrategy) GetState() RobotStatus

GetState 获取策略状态

func (*BaseStrategy) GetValue

func (s *BaseStrategy) GetValue(key string) (Value, error)

GetValue 获取一个全局变量

func (*BaseStrategy) IsRunning

func (s *BaseStrategy) IsRunning() bool

IsRunning 是否运行中

func (*BaseStrategy) Pause

func (s *BaseStrategy) Pause() plugin.BasicError

Pause 暂停

func (*BaseStrategy) QueueCommand

func (s *BaseStrategy) QueueCommand(command string) plugin.BasicError

QueueCommand 命令入队列

func (*BaseStrategy) QueueCommandRaw

func (s *BaseStrategy) QueueCommandRaw(command Command)

QueueCommandRaw 命令入队列

func (*BaseStrategy) SetOptions

func (s *BaseStrategy) SetOptions(options map[string]interface{}) plugin.BasicError

SetOptions 设置参数

func (*BaseStrategy) SetProxy

func (s *BaseStrategy) SetProxy(proxy string)

SetProxy 设置访问网络的代理(主要方便本地测试,如:http://127.0.0.1:1080)

func (*BaseStrategy) SetSelf

func (s *BaseStrategy) SetSelf(self Strategy)

SetSelf 设置 self 对象

func (*BaseStrategy) SetValue

func (s *BaseStrategy) SetValue(key string, value Value) error

SetValue 设置一个全局变量

func (*BaseStrategy) Start

func (s *BaseStrategy) Start() plugin.BasicError

Start 启动

func (*BaseStrategy) Stop

func (s *BaseStrategy) Stop() plugin.BasicError

Stop 停止

func (*BaseStrategy) UpdateStat

func (s *BaseStrategy) UpdateStat(name string, value []byte) error

UpdateStat 更新统计数据

type Client

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

Client RPC客户端对象

func GetClient

func GetClient() *Client

GetClient 获得RPC客户端对象

func (Client) Close

func (c Client) Close()

func (*Client) GetRobotExchangeInfo

func (c *Client) GetRobotExchangeInfo(uid string, id string) ([]*RobotExchangeInfo, error)

func (*Client) GetRobotOptions

func (c *Client) GetRobotOptions(uid string, id string) ([]*RobotOption, error)

func (*Client) GetValue

func (c *Client) GetValue(key string) (Value, error)

func (*Client) Log

func (c *Client) Log(sid int, id uint64, tm int64, level int32, message string) error

func (*Client) SetValue

func (c *Client) SetValue(key string, value Value) error

func (*Client) UpdateStat

func (c *Client) UpdateStat(name string, value []byte) error

func (*Client) UpdateStatus

func (c *Client) UpdateStatus(robotID string, status RobotStatus) error

type Command

type Command struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

Command 表示一个交互命令结构

type ExchangeParams

type ExchangeParams struct {
	Label     string
	Name      string
	AccessKey string
	SecretKey string
}

ExchangeParams 初始化交易所所需参数

type GRPCLog

type GRPCLog struct {
	SID int
}

func (*GRPCLog) Log

func (l *GRPCLog) Log(e *log.Entry) error

type GetValueReply

type GetValueReply struct {
	Success              bool     `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	Value                []byte   `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GetValueReply) Descriptor

func (*GetValueReply) Descriptor() ([]byte, []int)

func (*GetValueReply) GetMessage

func (m *GetValueReply) GetMessage() string

func (*GetValueReply) GetSuccess

func (m *GetValueReply) GetSuccess() bool

func (*GetValueReply) GetValue

func (m *GetValueReply) GetValue() []byte

func (*GetValueReply) ProtoMessage

func (*GetValueReply) ProtoMessage()

func (*GetValueReply) Reset

func (m *GetValueReply) Reset()

func (*GetValueReply) String

func (m *GetValueReply) String() string

func (*GetValueReply) XXX_DiscardUnknown

func (m *GetValueReply) XXX_DiscardUnknown()

func (*GetValueReply) XXX_Marshal

func (m *GetValueReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetValueReply) XXX_Merge

func (m *GetValueReply) XXX_Merge(src proto.Message)

func (*GetValueReply) XXX_Size

func (m *GetValueReply) XXX_Size() int

func (*GetValueReply) XXX_Unmarshal

func (m *GetValueReply) XXX_Unmarshal(b []byte) error

type GetValueRequest

type GetValueRequest struct {
	RobotId              string   `protobuf:"bytes,1,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	Key                  string   `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GetValueRequest) Descriptor

func (*GetValueRequest) Descriptor() ([]byte, []int)

func (*GetValueRequest) GetKey

func (m *GetValueRequest) GetKey() string

func (*GetValueRequest) GetRobotId

func (m *GetValueRequest) GetRobotId() string

func (*GetValueRequest) ProtoMessage

func (*GetValueRequest) ProtoMessage()

func (*GetValueRequest) Reset

func (m *GetValueRequest) Reset()

func (*GetValueRequest) String

func (m *GetValueRequest) String() string

func (*GetValueRequest) XXX_DiscardUnknown

func (m *GetValueRequest) XXX_DiscardUnknown()

func (*GetValueRequest) XXX_Marshal

func (m *GetValueRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GetValueRequest) XXX_Merge

func (m *GetValueRequest) XXX_Merge(src proto.Message)

func (*GetValueRequest) XXX_Size

func (m *GetValueRequest) XXX_Size() int

func (*GetValueRequest) XXX_Unmarshal

func (m *GetValueRequest) XXX_Unmarshal(b []byte) error

type LogReply

type LogReply struct {
	Success              bool     `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*LogReply) Descriptor

func (*LogReply) Descriptor() ([]byte, []int)

func (*LogReply) GetMessage

func (m *LogReply) GetMessage() string

func (*LogReply) GetSuccess

func (m *LogReply) GetSuccess() bool

func (*LogReply) ProtoMessage

func (*LogReply) ProtoMessage()

func (*LogReply) Reset

func (m *LogReply) Reset()

func (*LogReply) String

func (m *LogReply) String() string

func (*LogReply) XXX_DiscardUnknown

func (m *LogReply) XXX_DiscardUnknown()

func (*LogReply) XXX_Marshal

func (m *LogReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LogReply) XXX_Merge

func (m *LogReply) XXX_Merge(src proto.Message)

func (*LogReply) XXX_Size

func (m *LogReply) XXX_Size() int

func (*LogReply) XXX_Unmarshal

func (m *LogReply) XXX_Unmarshal(b []byte) error

type LogRequest

type LogRequest struct {
	Sid                  int32    `protobuf:"varint,1,opt,name=sid,proto3" json:"sid,omitempty"`
	Id                   uint64   `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	Time                 int64    `protobuf:"varint,3,opt,name=time,proto3" json:"time,omitempty"`
	Level                int32    `protobuf:"varint,4,opt,name=level,proto3" json:"level,omitempty"`
	Message              string   `protobuf:"bytes,5,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*LogRequest) Descriptor

func (*LogRequest) Descriptor() ([]byte, []int)

func (*LogRequest) GetId

func (m *LogRequest) GetId() uint64

func (*LogRequest) GetLevel

func (m *LogRequest) GetLevel() int32

func (*LogRequest) GetMessage

func (m *LogRequest) GetMessage() string

func (*LogRequest) GetSid

func (m *LogRequest) GetSid() int32

func (*LogRequest) GetTime

func (m *LogRequest) GetTime() int64

func (*LogRequest) ProtoMessage

func (*LogRequest) ProtoMessage()

func (*LogRequest) Reset

func (m *LogRequest) Reset()

func (*LogRequest) String

func (m *LogRequest) String() string

func (*LogRequest) XXX_DiscardUnknown

func (m *LogRequest) XXX_DiscardUnknown()

func (*LogRequest) XXX_Marshal

func (m *LogRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*LogRequest) XXX_Merge

func (m *LogRequest) XXX_Merge(src proto.Message)

func (*LogRequest) XXX_Size

func (m *LogRequest) XXX_Size() int

func (*LogRequest) XXX_Unmarshal

func (m *LogRequest) XXX_Unmarshal(b []byte) error

type OptionInfo

type OptionInfo struct {
	Name         string      `json:"name"`
	Description  string      `json:"description"`
	Type         string      `json:"type"`
	Value        interface{} `json:"value"`
	DefaultValue interface{} `json:"default_value"`
}

OptionInfo 参数信息

type RobotCtlClient

type RobotCtlClient interface {
	// 获取运行参数
	GetRobotOptions(ctx context.Context, in *RobotOptionsRequest, opts ...grpc.CallOption) (*RobotOptionsReply, error)
	// 获取交易所配置
	GetRobotExchangeInfo(ctx context.Context, in *RobotExchangeInfoRequest, opts ...grpc.CallOption) (*RobotExchangeInfoReply, error)
	// 获取配置值
	GetValue(ctx context.Context, in *GetValueRequest, opts ...grpc.CallOption) (*GetValueReply, error)
	// 保存配置值
	SetValue(ctx context.Context, in *SetValueRequest, opts ...grpc.CallOption) (*SetValueReply, error)
	// 写入日志
	Log(ctx context.Context, in *LogRequest, opts ...grpc.CallOption) (*LogReply, error)
	// 更新状态
	UpdateStatus(ctx context.Context, in *UpdateStatusRequest, opts ...grpc.CallOption) (*UpdateStatusReply, error)
	// 更新统计数据
	UpdateStat(ctx context.Context, in *StatRequest, opts ...grpc.CallOption) (*StatReply, error)
}

RobotCtlClient is the client API for RobotCtl service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewRobotCtlClient

func NewRobotCtlClient(cc *grpc.ClientConn) RobotCtlClient

type RobotCtlServer

type RobotCtlServer interface {
	// 获取运行参数
	GetRobotOptions(context.Context, *RobotOptionsRequest) (*RobotOptionsReply, error)
	// 获取交易所配置
	GetRobotExchangeInfo(context.Context, *RobotExchangeInfoRequest) (*RobotExchangeInfoReply, error)
	// 获取配置值
	GetValue(context.Context, *GetValueRequest) (*GetValueReply, error)
	// 保存配置值
	SetValue(context.Context, *SetValueRequest) (*SetValueReply, error)
	// 写入日志
	Log(context.Context, *LogRequest) (*LogReply, error)
	// 更新状态
	UpdateStatus(context.Context, *UpdateStatusRequest) (*UpdateStatusReply, error)
	// 更新统计数据
	UpdateStat(context.Context, *StatRequest) (*StatReply, error)
}

RobotCtlServer is the server API for RobotCtl service.

type RobotExchangeInfo

type RobotExchangeInfo struct {
	Label                string   `protobuf:"bytes,1,opt,name=label,proto3" json:"label,omitempty"`
	Name                 string   `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	AccessKey            string   `protobuf:"bytes,3,opt,name=access_key,json=accessKey,proto3" json:"access_key,omitempty"`
	SecretKey            string   `protobuf:"bytes,4,opt,name=secret_key,json=secretKey,proto3" json:"secret_key,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RobotExchangeInfo) Descriptor

func (*RobotExchangeInfo) Descriptor() ([]byte, []int)

func (*RobotExchangeInfo) GetAccessKey

func (m *RobotExchangeInfo) GetAccessKey() string

func (*RobotExchangeInfo) GetLabel

func (m *RobotExchangeInfo) GetLabel() string

func (*RobotExchangeInfo) GetName

func (m *RobotExchangeInfo) GetName() string

func (*RobotExchangeInfo) GetSecretKey

func (m *RobotExchangeInfo) GetSecretKey() string

func (*RobotExchangeInfo) ProtoMessage

func (*RobotExchangeInfo) ProtoMessage()

func (*RobotExchangeInfo) Reset

func (m *RobotExchangeInfo) Reset()

func (*RobotExchangeInfo) String

func (m *RobotExchangeInfo) String() string

func (*RobotExchangeInfo) XXX_DiscardUnknown

func (m *RobotExchangeInfo) XXX_DiscardUnknown()

func (*RobotExchangeInfo) XXX_Marshal

func (m *RobotExchangeInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotExchangeInfo) XXX_Merge

func (m *RobotExchangeInfo) XXX_Merge(src proto.Message)

func (*RobotExchangeInfo) XXX_Size

func (m *RobotExchangeInfo) XXX_Size() int

func (*RobotExchangeInfo) XXX_Unmarshal

func (m *RobotExchangeInfo) XXX_Unmarshal(b []byte) error

type RobotExchangeInfoReply

type RobotExchangeInfoReply struct {
	Exchanges            []*RobotExchangeInfo `protobuf:"bytes,1,rep,name=exchanges,proto3" json:"exchanges,omitempty"`
	XXX_NoUnkeyedLiteral struct{}             `json:"-"`
	XXX_unrecognized     []byte               `json:"-"`
	XXX_sizecache        int32                `json:"-"`
}

func (*RobotExchangeInfoReply) Descriptor

func (*RobotExchangeInfoReply) Descriptor() ([]byte, []int)

func (*RobotExchangeInfoReply) GetExchanges

func (m *RobotExchangeInfoReply) GetExchanges() []*RobotExchangeInfo

func (*RobotExchangeInfoReply) ProtoMessage

func (*RobotExchangeInfoReply) ProtoMessage()

func (*RobotExchangeInfoReply) Reset

func (m *RobotExchangeInfoReply) Reset()

func (*RobotExchangeInfoReply) String

func (m *RobotExchangeInfoReply) String() string

func (*RobotExchangeInfoReply) XXX_DiscardUnknown

func (m *RobotExchangeInfoReply) XXX_DiscardUnknown()

func (*RobotExchangeInfoReply) XXX_Marshal

func (m *RobotExchangeInfoReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotExchangeInfoReply) XXX_Merge

func (m *RobotExchangeInfoReply) XXX_Merge(src proto.Message)

func (*RobotExchangeInfoReply) XXX_Size

func (m *RobotExchangeInfoReply) XXX_Size() int

func (*RobotExchangeInfoReply) XXX_Unmarshal

func (m *RobotExchangeInfoReply) XXX_Unmarshal(b []byte) error

type RobotExchangeInfoRequest

type RobotExchangeInfoRequest struct {
	Uid                  string   `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
	RobotId              string   `protobuf:"bytes,2,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RobotExchangeInfoRequest) Descriptor

func (*RobotExchangeInfoRequest) Descriptor() ([]byte, []int)

func (*RobotExchangeInfoRequest) GetRobotId

func (m *RobotExchangeInfoRequest) GetRobotId() string

func (*RobotExchangeInfoRequest) GetUid

func (m *RobotExchangeInfoRequest) GetUid() string

func (*RobotExchangeInfoRequest) ProtoMessage

func (*RobotExchangeInfoRequest) ProtoMessage()

func (*RobotExchangeInfoRequest) Reset

func (m *RobotExchangeInfoRequest) Reset()

func (*RobotExchangeInfoRequest) String

func (m *RobotExchangeInfoRequest) String() string

func (*RobotExchangeInfoRequest) XXX_DiscardUnknown

func (m *RobotExchangeInfoRequest) XXX_DiscardUnknown()

func (*RobotExchangeInfoRequest) XXX_Marshal

func (m *RobotExchangeInfoRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotExchangeInfoRequest) XXX_Merge

func (m *RobotExchangeInfoRequest) XXX_Merge(src proto.Message)

func (*RobotExchangeInfoRequest) XXX_Size

func (m *RobotExchangeInfoRequest) XXX_Size() int

func (*RobotExchangeInfoRequest) XXX_Unmarshal

func (m *RobotExchangeInfoRequest) XXX_Unmarshal(b []byte) error

type RobotOption

type RobotOption struct {
	Key                  string   `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
	Value                string   `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RobotOption) Descriptor

func (*RobotOption) Descriptor() ([]byte, []int)

func (*RobotOption) GetKey

func (m *RobotOption) GetKey() string

func (*RobotOption) GetValue

func (m *RobotOption) GetValue() string

func (*RobotOption) ProtoMessage

func (*RobotOption) ProtoMessage()

func (*RobotOption) Reset

func (m *RobotOption) Reset()

func (*RobotOption) String

func (m *RobotOption) String() string

func (*RobotOption) XXX_DiscardUnknown

func (m *RobotOption) XXX_DiscardUnknown()

func (*RobotOption) XXX_Marshal

func (m *RobotOption) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotOption) XXX_Merge

func (m *RobotOption) XXX_Merge(src proto.Message)

func (*RobotOption) XXX_Size

func (m *RobotOption) XXX_Size() int

func (*RobotOption) XXX_Unmarshal

func (m *RobotOption) XXX_Unmarshal(b []byte) error

type RobotOptionsReply

type RobotOptionsReply struct {
	Options              []*RobotOption `protobuf:"bytes,1,rep,name=options,proto3" json:"options,omitempty"`
	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
	XXX_unrecognized     []byte         `json:"-"`
	XXX_sizecache        int32          `json:"-"`
}

func (*RobotOptionsReply) Descriptor

func (*RobotOptionsReply) Descriptor() ([]byte, []int)

func (*RobotOptionsReply) GetOptions

func (m *RobotOptionsReply) GetOptions() []*RobotOption

func (*RobotOptionsReply) ProtoMessage

func (*RobotOptionsReply) ProtoMessage()

func (*RobotOptionsReply) Reset

func (m *RobotOptionsReply) Reset()

func (*RobotOptionsReply) String

func (m *RobotOptionsReply) String() string

func (*RobotOptionsReply) XXX_DiscardUnknown

func (m *RobotOptionsReply) XXX_DiscardUnknown()

func (*RobotOptionsReply) XXX_Marshal

func (m *RobotOptionsReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotOptionsReply) XXX_Merge

func (m *RobotOptionsReply) XXX_Merge(src proto.Message)

func (*RobotOptionsReply) XXX_Size

func (m *RobotOptionsReply) XXX_Size() int

func (*RobotOptionsReply) XXX_Unmarshal

func (m *RobotOptionsReply) XXX_Unmarshal(b []byte) error

type RobotOptionsRequest

type RobotOptionsRequest struct {
	Uid                  string   `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
	RobotId              string   `protobuf:"bytes,2,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*RobotOptionsRequest) Descriptor

func (*RobotOptionsRequest) Descriptor() ([]byte, []int)

func (*RobotOptionsRequest) GetRobotId

func (m *RobotOptionsRequest) GetRobotId() string

func (*RobotOptionsRequest) GetUid

func (m *RobotOptionsRequest) GetUid() string

func (*RobotOptionsRequest) ProtoMessage

func (*RobotOptionsRequest) ProtoMessage()

func (*RobotOptionsRequest) Reset

func (m *RobotOptionsRequest) Reset()

func (*RobotOptionsRequest) String

func (m *RobotOptionsRequest) String() string

func (*RobotOptionsRequest) XXX_DiscardUnknown

func (m *RobotOptionsRequest) XXX_DiscardUnknown()

func (*RobotOptionsRequest) XXX_Marshal

func (m *RobotOptionsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RobotOptionsRequest) XXX_Merge

func (m *RobotOptionsRequest) XXX_Merge(src proto.Message)

func (*RobotOptionsRequest) XXX_Size

func (m *RobotOptionsRequest) XXX_Size() int

func (*RobotOptionsRequest) XXX_Unmarshal

func (m *RobotOptionsRequest) XXX_Unmarshal(b []byte) error

type RobotStatus

type RobotStatus int8

RobotStatus 机器人状态

const (
	// RobotStatusDisabled 禁用
	RobotStatusDisabled RobotStatus = iota
	// RobotStatusStopped 停止
	RobotStatusStopped
	// RobotStatusStarting 启动中
	RobotStatusStarting
	// RobotStatusRunning 运行中
	RobotStatusRunning
	// RobotStatusRequested RobotStatusStopping 停止中
	RobotStatusRequested
	// RobotStatusError 出错
	RobotStatusError
)

type SetValueReply

type SetValueReply struct {
	Success              bool     `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SetValueReply) Descriptor

func (*SetValueReply) Descriptor() ([]byte, []int)

func (*SetValueReply) GetMessage

func (m *SetValueReply) GetMessage() string

func (*SetValueReply) GetSuccess

func (m *SetValueReply) GetSuccess() bool

func (*SetValueReply) ProtoMessage

func (*SetValueReply) ProtoMessage()

func (*SetValueReply) Reset

func (m *SetValueReply) Reset()

func (*SetValueReply) String

func (m *SetValueReply) String() string

func (*SetValueReply) XXX_DiscardUnknown

func (m *SetValueReply) XXX_DiscardUnknown()

func (*SetValueReply) XXX_Marshal

func (m *SetValueReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SetValueReply) XXX_Merge

func (m *SetValueReply) XXX_Merge(src proto.Message)

func (*SetValueReply) XXX_Size

func (m *SetValueReply) XXX_Size() int

func (*SetValueReply) XXX_Unmarshal

func (m *SetValueReply) XXX_Unmarshal(b []byte) error

type SetValueRequest

type SetValueRequest struct {
	RobotId              string   `protobuf:"bytes,1,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	Key                  string   `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"`
	Value                []byte   `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*SetValueRequest) Descriptor

func (*SetValueRequest) Descriptor() ([]byte, []int)

func (*SetValueRequest) GetKey

func (m *SetValueRequest) GetKey() string

func (*SetValueRequest) GetRobotId

func (m *SetValueRequest) GetRobotId() string

func (*SetValueRequest) GetValue

func (m *SetValueRequest) GetValue() []byte

func (*SetValueRequest) ProtoMessage

func (*SetValueRequest) ProtoMessage()

func (*SetValueRequest) Reset

func (m *SetValueRequest) Reset()

func (*SetValueRequest) String

func (m *SetValueRequest) String() string

func (*SetValueRequest) XXX_DiscardUnknown

func (m *SetValueRequest) XXX_DiscardUnknown()

func (*SetValueRequest) XXX_Marshal

func (m *SetValueRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*SetValueRequest) XXX_Merge

func (m *SetValueRequest) XXX_Merge(src proto.Message)

func (*SetValueRequest) XXX_Size

func (m *SetValueRequest) XXX_Size() int

func (*SetValueRequest) XXX_Unmarshal

func (m *SetValueRequest) XXX_Unmarshal(b []byte) error

type StatReply

type StatReply struct {
	Success              bool     `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*StatReply) Descriptor

func (*StatReply) Descriptor() ([]byte, []int)

func (*StatReply) GetMessage

func (m *StatReply) GetMessage() string

func (*StatReply) GetSuccess

func (m *StatReply) GetSuccess() bool

func (*StatReply) ProtoMessage

func (*StatReply) ProtoMessage()

func (*StatReply) Reset

func (m *StatReply) Reset()

func (*StatReply) String

func (m *StatReply) String() string

func (*StatReply) XXX_DiscardUnknown

func (m *StatReply) XXX_DiscardUnknown()

func (*StatReply) XXX_Marshal

func (m *StatReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StatReply) XXX_Merge

func (m *StatReply) XXX_Merge(src proto.Message)

func (*StatReply) XXX_Size

func (m *StatReply) XXX_Size() int

func (*StatReply) XXX_Unmarshal

func (m *StatReply) XXX_Unmarshal(b []byte) error

type StatRequest

type StatRequest struct {
	RobotId              string   `protobuf:"bytes,1,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	Name                 string   `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Value                []byte   `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*StatRequest) Descriptor

func (*StatRequest) Descriptor() ([]byte, []int)

func (*StatRequest) GetName

func (m *StatRequest) GetName() string

func (*StatRequest) GetRobotId

func (m *StatRequest) GetRobotId() string

func (*StatRequest) GetValue

func (m *StatRequest) GetValue() []byte

func (*StatRequest) ProtoMessage

func (*StatRequest) ProtoMessage()

func (*StatRequest) Reset

func (m *StatRequest) Reset()

func (*StatRequest) String

func (m *StatRequest) String() string

func (*StatRequest) XXX_DiscardUnknown

func (m *StatRequest) XXX_DiscardUnknown()

func (*StatRequest) XXX_Marshal

func (m *StatRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*StatRequest) XXX_Merge

func (m *StatRequest) XXX_Merge(src proto.Message)

func (*StatRequest) XXX_Size

func (m *StatRequest) XXX_Size() int

func (*StatRequest) XXX_Unmarshal

func (m *StatRequest) XXX_Unmarshal(b []byte) error

type Strategy

type Strategy interface {
	StrategyCtl
	SetSelf(self Strategy)
	Setup(params []ExchangeParams) error
	Init() error
	Run() error
}

Strategy 策略接口

type StrategyCtl

type StrategyCtl interface {
	GetState() RobotStatus
	GetOptions() (optionMap map[string]*OptionInfo)
	SetOptions(options map[string]interface{}) plugin.BasicError
	QueueCommand(command string) plugin.BasicError
	Start() plugin.BasicError
	Stop() plugin.BasicError
	Pause() plugin.BasicError
}

StrategyCtl 插件接口

type StrategyPlugin

type StrategyPlugin struct {
	// Impl Injection
	Impl StrategyCtl
}

This is the implementation of plugin.Plugin so we can serve/consume this

This has two methods: Server must return an RPC server for this plugin type. We construct a GreeterRPCServer for this.

Client must return an implementation of our interface that communicates over an RPC client. We return GreeterRPC for this.

Ignore MuxBroker. That is used to create more multiplexed streams on our plugin connection and is a more advanced use case.

func (StrategyPlugin) Client

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

Client client

func (*StrategyPlugin) Server

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

Server server

type StrategyRPC

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

StrategyRPC Here is an implementation that talks over RPC

func (*StrategyRPC) GetOptions

func (g *StrategyRPC) GetOptions() (optionMap map[string]*OptionInfo)

GetOptions ...

func (*StrategyRPC) GetState

func (g *StrategyRPC) GetState() RobotStatus

GetState ...

func (*StrategyRPC) Pause

func (g *StrategyRPC) Pause() plugin.BasicError

Pause ...

func (*StrategyRPC) QueueCommand

func (g *StrategyRPC) QueueCommand(command string) plugin.BasicError

QueueCommand ...

func (*StrategyRPC) SetOptions

func (g *StrategyRPC) SetOptions(options map[string]interface{}) plugin.BasicError

SetOptions ...

func (*StrategyRPC) Start

func (g *StrategyRPC) Start() plugin.BasicError

Start ...

func (*StrategyRPC) Stop

func (g *StrategyRPC) Stop() plugin.BasicError

Stop ...

type StrategyRPCServer

type StrategyRPCServer struct {
	// This is the real implementation
	Impl StrategyCtl
}

StrategyRPCServer Here is the RPC server that GreeterRPC talks to, conforming to the requirements of net/rpc

func (*StrategyRPCServer) GetOptions

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

func (*StrategyRPCServer) GetState

func (s *StrategyRPCServer) GetState(args interface{}, resp *RobotStatus) error

func (*StrategyRPCServer) Pause

func (s *StrategyRPCServer) Pause(args interface{}, resp *plugin.BasicError) error

func (*StrategyRPCServer) QueueCommand

func (s *StrategyRPCServer) QueueCommand(args string, resp *plugin.BasicError) error

func (*StrategyRPCServer) SetOptions

func (s *StrategyRPCServer) SetOptions(args map[string]interface{}, resp *plugin.BasicError) error

func (*StrategyRPCServer) Start

func (s *StrategyRPCServer) Start(args interface{}, resp *plugin.BasicError) error

func (*StrategyRPCServer) Stop

func (s *StrategyRPCServer) Stop(args interface{}, resp *plugin.BasicError) error

type UpdateStatusReply

type UpdateStatusReply struct {
	Success              bool     `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
	Message              string   `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*UpdateStatusReply) Descriptor

func (*UpdateStatusReply) Descriptor() ([]byte, []int)

func (*UpdateStatusReply) GetMessage

func (m *UpdateStatusReply) GetMessage() string

func (*UpdateStatusReply) GetSuccess

func (m *UpdateStatusReply) GetSuccess() bool

func (*UpdateStatusReply) ProtoMessage

func (*UpdateStatusReply) ProtoMessage()

func (*UpdateStatusReply) Reset

func (m *UpdateStatusReply) Reset()

func (*UpdateStatusReply) String

func (m *UpdateStatusReply) String() string

func (*UpdateStatusReply) XXX_DiscardUnknown

func (m *UpdateStatusReply) XXX_DiscardUnknown()

func (*UpdateStatusReply) XXX_Marshal

func (m *UpdateStatusReply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UpdateStatusReply) XXX_Merge

func (m *UpdateStatusReply) XXX_Merge(src proto.Message)

func (*UpdateStatusReply) XXX_Size

func (m *UpdateStatusReply) XXX_Size() int

func (*UpdateStatusReply) XXX_Unmarshal

func (m *UpdateStatusReply) XXX_Unmarshal(b []byte) error

type UpdateStatusRequest

type UpdateStatusRequest struct {
	RobotId              string   `protobuf:"bytes,1,opt,name=robot_id,json=robotId,proto3" json:"robot_id,omitempty"`
	Status               int32    `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*UpdateStatusRequest) Descriptor

func (*UpdateStatusRequest) Descriptor() ([]byte, []int)

func (*UpdateStatusRequest) GetRobotId

func (m *UpdateStatusRequest) GetRobotId() string

func (*UpdateStatusRequest) GetStatus

func (m *UpdateStatusRequest) GetStatus() int32

func (*UpdateStatusRequest) ProtoMessage

func (*UpdateStatusRequest) ProtoMessage()

func (*UpdateStatusRequest) Reset

func (m *UpdateStatusRequest) Reset()

func (*UpdateStatusRequest) String

func (m *UpdateStatusRequest) String() string

func (*UpdateStatusRequest) XXX_DiscardUnknown

func (m *UpdateStatusRequest) XXX_DiscardUnknown()

func (*UpdateStatusRequest) XXX_Marshal

func (m *UpdateStatusRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*UpdateStatusRequest) XXX_Merge

func (m *UpdateStatusRequest) XXX_Merge(src proto.Message)

func (*UpdateStatusRequest) XXX_Size

func (m *UpdateStatusRequest) XXX_Size() int

func (*UpdateStatusRequest) XXX_Unmarshal

func (m *UpdateStatusRequest) XXX_Unmarshal(b []byte) error

type Value

type Value struct {
	Kind  ValueKind
	Value interface{}
}

func BoolValue

func BoolValue(value bool) Value

func Float32Value

func Float32Value(value float32) Value

func Float64Value

func Float64Value(value float64) Value

func GetValue

func GetValue(key string) (Value, error)

GetValue 获取一个全局变量

func Int32Value

func Int32Value(value int32) Value

func Int64Value

func Int64Value(value int64) Value

func IntValue

func IntValue(value int) Value

func StringValue

func StringValue(value string) Value

func (*Value) DecodeMsgpack

func (r *Value) DecodeMsgpack(enc *msgpack.Decoder) error

func (*Value) EncodeMsgpack

func (r *Value) EncodeMsgpack(enc *msgpack.Encoder) error

func (*Value) SetValue

func (value *Value) SetValue(val interface{})

func (*Value) ToBool

func (value *Value) ToBool() bool

func (*Value) ToFloat64

func (value *Value) ToFloat64() float64

func (*Value) ToInt

func (value *Value) ToInt() int

func (*Value) ToString

func (value *Value) ToString() string

type ValueKind

type ValueKind uint32
const (
	ValueNil ValueKind = iota
	ValueBoolean
	ValueString
	ValueInt32
	ValueInt64
	ValueUint32
	ValueUint64
	ValueFloat32
	ValueFloat64
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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