protocol

package
v0.0.64 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: MIT Imports: 14 Imported by: 3

Documentation

Index

Constants

View Source
const (
	TypeConnect            = 0x000D //建立连接
	TypeHeart              = 0x0004 //心跳
	TypeGbbq               = 0x000F //除权除息
	TypeCount              = 0x044E //获取股票数量
	TypeCode               = 0x0450 //获取股票代码
	TypeQuote              = 0x053E //行情信息
	TypeMinute             = 0x051D //分时数据
	TypeCallAuction        = 0x056A //集合竞价
	TypeMinuteTrade        = 0x0FC5 //分时交易
	TypeHistoryMinute      = 0x0FB4 //历史分时数据
	TypeHistoryMinuteTrade = 0x0FB5 //历史分时交易
	TypeKline              = 0x052D //K线图
)
View Source
const (
	// Prefix 固定帧头
	Prefix = 0x0C

	// PrefixResp 响应帧头
	PrefixResp = 0xB1CB7400
)
View Source
const (
	TypeKline5Minute  uint8 = 0  // 5分钟K 线
	TypeKline15Minute uint8 = 1  // 15分钟K 线
	TypeKline30Minute uint8 = 2  // 30分钟K 线
	TypeKline60Minute uint8 = 3  // 60分钟K 线
	TypeKlineHour     uint8 = 3  // 1小时K 线
	TypeKlineDay2     uint8 = 4  // 日K 线, 发现和Day的区别是这个要除以100,其他未知
	TypeKlineWeek     uint8 = 5  // 周K 线
	TypeKlineMonth    uint8 = 6  // 月K 线
	TypeKlineMinute   uint8 = 7  // 1分钟
	TypeKlineMinute2  uint8 = 8  // 1分钟K 线,未知啥区别
	TypeKlineDay      uint8 = 9  // 日K 线
	TypeKlineQuarter  uint8 = 10 // 季K 线
	TypeKlineYear     uint8 = 11 // 年K 线
)
View Source
const (
	KindIndex = "index"
	KindStock = "stock"
)

Variables

View Source
var (
	MConnect       = connect{}
	MHeart         = heart{}
	MCount         = count{}
	MQuote         = quote{}
	MCode          = code{}
	MMinute        = minute{}
	MHistoryMinute = historyMinute{}
	MCallAuction   = callAuction{}
	MTrade         = trade{}
	MHistoryTrade  = historyTrade{}
	MKline         = kline{}
	MGbbq          = gbbq{}
)
View Source
var (
	// ExchangeEstablish 交易所成立时间
	ExchangeEstablish = time.Date(1990, 12, 19, 0, 0, 0, 0, time.Local)
)

Functions

func AddPrefix

func AddPrefix(code string) string

AddPrefix 添加股票/基金代码前缀,针对股票/基金生效,例如000001,会增加前缀sz000001(平安银行),而不是sh000001(上证指数)

func Bytes

func Bytes(n any) []byte

Bytes 任意类型转小端字节

func CutInt

func CutInt(bs []byte) ([]byte, int)

func FloatUnit

func FloatUnit(f float64) (float64, string)

func FloatUnitString

func FloatUnitString(f float64) string

func GetHourMinute

func GetHourMinute(bs [2]byte) string

func GetTime

func GetTime(bs [4]byte, Type uint8) time.Time

func Int64UnitString

func Int64UnitString(n int64) string

func IntUnitString

func IntUnitString(n int) string

func IsBJStock

func IsBJStock(code string) bool

func IsETF

func IsETF(code string) bool

IsETF 是否是基金,示例sz159558

func IsIndex

func IsIndex(code string) bool

IsIndex 是否是指数,sh000001,sz399001,bj899100

func IsSHStock

func IsSHStock(code string) bool

func IsSZStock

func IsSZStock(code string) bool

func IsStock

func IsStock(code string) bool

IsStock 是否是股票,示例sz000001

func ReadFrom

func ReadFrom(r io.Reader) (result []byte, err error)

ReadFrom 这里的r推荐传入*bufio.Reader

func Reverse

func Reverse(bs []byte) []byte

Reverse 字节倒序

func String

func String(bs []byte) string

String 字节先转小端,再转字符

func UTF8ToGBK

func UTF8ToGBK(text []byte) []byte

func Uint16

func Uint16(bs []byte) uint16

Uint16 字节通过小端方式转为uint16

func Uint32

func Uint32(bs []byte) uint32

Uint32 字节通过小端方式转为uint32

Types

type CallAuction added in v0.0.56

type CallAuction struct {
	Time      time.Time //时间
	Price     Price     //价格
	Match     uint32    //匹配量
	Unmatched uint32    //未匹配量
}

type CallAuctionResp added in v0.0.56

type CallAuctionResp struct {
	Count uint16
	List  []*CallAuction
}

type Code

type Code struct {
	Name      string  //股票名称
	Code      string  //股票代码
	Multiple  uint16  //倍数,基本是0x64=100
	Decimal   int8    //小数点,基本是2
	LastPrice float64 //昨收价格,单位元,对个股无效,对指数有效,对其他未知
}

func (*Code) String

func (this *Code) String() string

type CodeResp

type CodeResp struct {
	Count uint16
	List  []*Code
}

type ConnectResp

type ConnectResp struct {
	Info string
}

type Control

type Control uint8
const (
	Control01 Control = 0x01 //好像都是01,暂时不知道啥含义
)

func (Control) Uint8

func (this Control) Uint8() uint8

type CountResp

type CountResp struct {
	Count uint16
}

type Equity added in v0.0.61

type Equity struct {
	Category int       //2, 3, 5, 7, 8, 9, 10
	Code     string    //例sh600000
	Time     time.Time //时间
	Float    float64   //流通股本,单位股
	Total    float64   //总股本,单位股
}

func (*Equity) Turnover added in v0.0.61

func (this *Equity) Turnover(volume int64) float64

Turnover 换手率,传入股,通达信获取的一般是手,注意

type Exchange

type Exchange uint8
const (
	ExchangeSZ Exchange = iota //深圳交易所
	ExchangeSH                 //上海交易所
	ExchangeBJ                 //北京交易所
)

func DecodeCode

func DecodeCode(code string) (Exchange, string, error)

func (Exchange) Name

func (this Exchange) Name() string

func (Exchange) String

func (this Exchange) String() string

func (Exchange) Uint8

func (this Exchange) Uint8() uint8

type Factor added in v0.0.61

type Factor struct {
	Time    time.Time //日期
	Last    Price     //昨收价
	PreLast Price     //除权除息后昨收价
	QFQ     float64   //前复权因子
	HFQ     float64   //后复权因子
}

type Frame

type Frame struct {
	MsgID   uint32  //消息ID
	Control Control //控制码,这个还不知道怎么定义
	Type    uint16  //请求类型,如建立连接,请求分时数据等
	Data    []byte  //数据
}

Frame 数据帧 0c 02189300 01 0300 0300 0d00 01 0c 00000000 00 0200 0200 1500 0c 01000000 01 0300 0300 0d00 01 0c 01000000 01 0300 0300 0d00 01 0c 02000000 01 1a00 1a00 3e05 050000000000000002000030303030303101363030303038

0c0100000001030003000d0001

func (*Frame) Bytes

func (this *Frame) Bytes() types.Bytes

Bytes

0c00000000011c001c002d0500003030303030310900010000000a0000000000000000000000

Prefix: 0c MsgID: 0208d301 Control: 01 Length: 1c00 Length: 1c00 Type: 2d05 000030303030303104000100a401a40100000000000000000000

type Gbbq added in v0.0.61

type Gbbq struct {
	Code     string
	Time     time.Time //15:00,注意判断逻辑
	Category int       //2, 3, 5, 7, 8, 9, 10
	C1       float64
	C2       float64
	C3       float64
	C4       float64
}

func (*Gbbq) Equity added in v0.0.61

func (this *Gbbq) Equity() *Equity

func (*Gbbq) IsEquity added in v0.0.61

func (this *Gbbq) IsEquity() bool

func (*Gbbq) IsXRXD added in v0.0.61

func (this *Gbbq) IsXRXD() bool

func (*Gbbq) TableName added in v0.0.61

func (this *Gbbq) TableName() string

func (*Gbbq) XRXD added in v0.0.61

func (this *Gbbq) XRXD() *XRXD

type GbbqResp added in v0.0.61

type GbbqResp struct {
	Count uint16
	List  []*Gbbq
}

type HistoryTradeResp

type HistoryTradeResp = TradeResp

HistoryTradeResp 兼容之前的版本

type K

type K struct {
	Last  Price //昨天收盘价
	Open  Price //今日开盘价
	High  Price //今日最高价
	Low   Price //今日最低价
	Close Price //今日收盘价
}

K k线图

func DecodeK

func DecodeK(bs []byte) ([]byte, K)

DecodeK 一般是占用6字节

func (K) String

func (this K) String() string

type Kline

type Kline struct {
	Last      Price     //昨日收盘价,这个是列表的上一条数据的收盘价,如果没有上条数据,那么这个值为0
	Open      Price     //开盘价
	High      Price     //最高价
	Low       Price     //最低价
	Close     Price     //收盘价,如果是当天,则是最新价/实时价
	Order     int       //成交单数,不一定有值
	Volume    int64     //成交量
	Amount    Price     //成交额
	Time      time.Time //时间
	UpCount   int       //上涨数量,指数有效
	DownCount int       //下跌数量,指数有效
}

func FixKlineTime

func FixKlineTime(ks []*Kline) []*Kline

FixKlineTime 修复盘内下午(13~15点)拉取数据的时候,11.30的时间变成13.00

func (*Kline) MaxDifference

func (this *Kline) MaxDifference() Price

MaxDifference 最大差值,最高-最低

func (*Kline) RisePrice

func (this *Kline) RisePrice() Price

RisePrice 涨跌金额,第一个数据不准,仅做参考

func (*Kline) RiseRate

func (this *Kline) RiseRate() float64

RiseRate 涨跌比例/涨跌幅,第一个数据不准,仅做参考

func (*Kline) String

func (this *Kline) String() string

type KlineCache

type KlineCache struct {
	Type uint8  //1分钟,5分钟,日线等
	Kind string //指数,个股等
}

type KlineReq

type KlineReq struct {
	Exchange Exchange
	Code     string
	Start    uint16
	Count    uint16
}

func (*KlineReq) Bytes

func (this *KlineReq) Bytes(Type uint8) (types.Bytes, error)

type KlineResp

type KlineResp struct {
	Count uint16
	List  []*Kline
}

type Klines

type Klines []*Kline

func (Klines) Kline

func (this Klines) Kline(t time.Time, last Price) *Kline

func (Klines) LastPrice

func (this Klines) LastPrice() Price

LastPrice 获取最后一个K线的收盘价

func (Klines) Len

func (this Klines) Len() int

func (Klines) Less

func (this Klines) Less(i, j int) bool

func (Klines) Merge

func (this Klines) Merge(n int) Klines

Merge 合并成其他类型的K线

func (Klines) Sort

func (this Klines) Sort()

func (Klines) Swap

func (this Klines) Swap(i, j int)

type Message

type Message interface {
	Bytes() types.Bytes
}

type MinuteResp

type MinuteResp struct {
	Count uint16
	List  []PriceNumber
}

type PreKline added in v0.0.61

type PreKline struct {
	*Kline
	PreLast Price
}

func (*PreKline) HFQFactor added in v0.0.61

func (this *PreKline) HFQFactor() float64

func (*PreKline) QFQFactor added in v0.0.61

func (this *PreKline) QFQFactor() float64

type PreKlines added in v0.0.61

type PreKlines []*PreKline

func (PreKlines) Factors added in v0.0.61

func (this PreKlines) Factors() []*Factor

type Price

type Price int64

Price 价格,单位厘

func GetPrice

func GetPrice(bs []byte) ([]byte, Price)

func Yuan added in v0.0.61

func Yuan(f float64) Price

func (Price) Float64

func (this Price) Float64() float64

func (Price) Int64

func (this Price) Int64() int64

func (Price) String

func (this Price) String() string

type PriceLevel

type PriceLevel struct {
	Buy    bool  //买卖
	Price  Price //价 想买卖的价格
	Number int   //量 想买卖的数量
}

type PriceLevels

type PriceLevels [5]PriceLevel

func (PriceLevels) String

func (this PriceLevels) String() string

type PriceNumber

type PriceNumber struct {
	Time   string
	Price  Price
	Number int
}

func (PriceNumber) String

func (this PriceNumber) String() string

type Quote

type Quote struct {
	Exchange       Exchange // 市场
	Code           string   // 股票代码 6个ascii字符串
	Active1        uint16   // 活跃度
	K              K        //k线
	ServerTime     string   // 时间
	ReversedBytes0 int      // 保留(时间 ServerTime)
	ReversedBytes1 int      // 保留 这个等于 负的收盘价格?
	TotalHand      int      // 总手(东财的盘口-总手)
	Intuition      int      // 现量(东财的盘口-现量)现在成交量
	Amount         float64  // 金额(东财的盘口-金额)
	InsideDish     int      // 内盘(东财的盘口-外盘)(和东财对不上)
	OuterDisc      int      // 外盘(东财的盘口-外盘)(和东财对不上)

	ReversedBytes2 int         // 保留,未知
	ReversedBytes3 int         // 保留,未知,基金的昨收净值?
	BuyLevel       PriceLevels // 5档买盘(买1-5)
	SellLevel      PriceLevels // 5档卖盘(卖1-5)

	ReversedBytes4 uint16  // 保留,未知
	ReversedBytes5 int     // 保留,未知
	ReversedBytes6 int     // 保留,未知
	ReversedBytes7 int     // 保留,未知
	ReversedBytes8 int     // 保留,未知
	ReversedBytes9 uint16  // 保留,未知
	Rate           float64 // 涨速,好像都是0
	Active2        uint16  // 活跃度
}

func (*Quote) String

func (this *Quote) String() string

type QuotesResp

type QuotesResp []*Quote

func (QuotesResp) String

func (this QuotesResp) String() string

type Response

type Response struct {
	Prefix    uint32 //未知,猜测是帧头
	Control   uint8  //响应的控制码,目前发现0c是错误,1c是成功,猜测左数右第4位代表是否成功
	MsgID     uint32 //消息ID
	Unknown   uint8  //未知,猜测是响应的控制码
	Type      uint16 //响应类型,对应请求类型,如建立连接,请求分时数据等
	ZipLength uint16 //数据长度
	Length    uint16 //未压缩长度
	Data      []byte //数据域
}

func Decode

func Decode(bs []byte) (*Response, error)

Decode 帧头 |控制码 |消息ID |控制码 |数据类型 |未解压长度 |解压长度 |数据域 b1cb7400 |1c |00000000 |00 |0d00 |5100 |bd00 |789c6378c1cecb252ace6066c5b4898987b9050ed1f90cc5b74c18a5bc18c1b43490fecff09c81819191f13fc3c9f3bb169f5e7dfefeb5ef57f7199a305009308208e5b32bb6bcbf70148712002d7f1e13

type Trade

type Trade struct {
	Time   time.Time //时间, 09:30
	Price  Price     //价格
	Volume int       //成交量,手
	Status int       //0是买,1是卖,2中性/汇总 中途也可能出现2,例20241115(sz000001)的14:56
	Number int       //单数,历史数据该字段无效
}

Trade 分时成交, 时间没有到秒,客户端上也没有,东方客户端能显示秒

func (*Trade) Amount

func (this *Trade) Amount() Price

Amount 成交额

func (*Trade) AvgPrice

func (this *Trade) AvgPrice() Price

AvgPrice 平均每单成交金额

func (*Trade) AvgVolume

func (this *Trade) AvgVolume() float64

AvgVolume 平均每单成交量

func (*Trade) IsBuy

func (this *Trade) IsBuy() bool

IsBuy 是否是买单

func (*Trade) IsSell

func (this *Trade) IsSell() bool

IsSell 是否是卖单

func (*Trade) StatusString

func (this *Trade) StatusString() string

func (*Trade) String

func (this *Trade) String() string

type TradeCache

type TradeCache struct {
	Date string //日期
	Code string //计算倍数
}

type TradeResp

type TradeResp struct {
	Count uint16
	List  Trades
}

type Trades

type Trades []*Trade

func (Trades) Kline

func (this Trades) Kline(t time.Time, last Price) *Kline

Kline 合并分时成交成1个k线,注意分时成交时间保持一致

func (Trades) Klines

func (this Trades) Klines() Klines

Klines 合并分时成交成k线

type XRXD added in v0.0.61

type XRXD struct {
	Code        string    //例sh600000
	Time        time.Time //时间
	Fenhong     float64   //分红,10股分n元
	Peigujia    float64   //配股价
	Songzhuangu float64   //送转股
	Peigu       float64   //配股
}

XRXD 除权 ex-rights 除息 ex-dividend

func (*XRXD) Pre added in v0.0.61

func (this *XRXD) Pre(p Price) Price

Pre 计算除权除息之后的价格,10元,10股分5元->9.5元

type XRXDs added in v0.0.61

type XRXDs []*XRXD

func (XRXDs) Pre added in v0.0.61

func (this XRXDs) Pre(ks []*Kline) PreKlines

Pre ks需要按时间从小到大

Jump to

Keyboard shortcuts

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