mirror of
https://github.com/bensema/gotdx.git
synced 2025-11-21 02:45:33 +08:00
get security quotes
This commit is contained in:
216
proto/proto.go
216
proto/proto.go
@@ -1,6 +1,12 @@
|
||||
package proto
|
||||
|
||||
import "sync/atomic"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"math"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
MessageHeaderBytes = 0x10
|
||||
@@ -26,6 +32,35 @@ const (
|
||||
KMSG_SECURITYQUOTES = 0x053e // 行情信息
|
||||
KMSG_TRANSACTIONDATA = 0x0fc5 // 分笔成交信息
|
||||
KMSG_XDXRINFO = 0x000f // 除权除息信息
|
||||
|
||||
/*
|
||||
K线种类
|
||||
# K 线种类
|
||||
# 0 - 5 分钟K 线
|
||||
# 1 - 15 分钟K 线
|
||||
# 2 - 30 分钟K 线
|
||||
# 3 - 1 小时K 线
|
||||
# 4 - 日K 线
|
||||
# 5 - 周K 线
|
||||
# 6 - 月K 线
|
||||
# 7 - 1 分钟
|
||||
# 8 - 1 分钟K 线
|
||||
# 9 - 日K 线
|
||||
# 10 - 季K 线
|
||||
# 11 - 年K 线
|
||||
*/
|
||||
KLINE_TYPE_5MIN = 0
|
||||
KLINE_TYPE_15MIN = 1
|
||||
KLINE_TYPE_30MIN = 2
|
||||
KLINE_TYPE_1HOUR = 3
|
||||
KLINE_TYPE_DAILY = 4
|
||||
KLINE_TYPE_WEEKLY = 5
|
||||
KLINE_TYPE_MONTHLY = 6
|
||||
KLINE_TYPE_EXHQ_1MIN = 7
|
||||
KLINE_TYPE_1MIN = 8
|
||||
KLINE_TYPE_RI_K = 9
|
||||
KLINE_TYPE_3MONTH = 10
|
||||
KLINE_TYPE_YEARLY = 11
|
||||
)
|
||||
|
||||
type Msg interface {
|
||||
@@ -63,3 +98,182 @@ func seqID() uint32 {
|
||||
atomic.AddUint32(&_seqId, 1)
|
||||
return _seqId
|
||||
}
|
||||
|
||||
// pytdx : 类似utf-8的编码方式保存有符号数字
|
||||
func getprice(b []byte, pos *int) int {
|
||||
posbype := 6
|
||||
bdata := b[*pos]
|
||||
intdata := int(bdata & 0x3f)
|
||||
|
||||
sign := false
|
||||
if (bdata & 0x40) > 0 {
|
||||
sign = true
|
||||
}
|
||||
|
||||
if (bdata & 0x80) > 0 {
|
||||
for {
|
||||
*pos += 1
|
||||
bdata = b[*pos]
|
||||
intdata += (int(bdata&0x7f) << posbype)
|
||||
|
||||
posbype += 7
|
||||
|
||||
if (bdata & 0x80) <= 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
*pos += 1
|
||||
|
||||
if sign {
|
||||
intdata = -intdata
|
||||
}
|
||||
return intdata
|
||||
}
|
||||
|
||||
func gettime(b []byte, pos *int) (h uint16, m uint16) {
|
||||
var sec uint16
|
||||
binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &sec)
|
||||
h = sec / 60
|
||||
m = sec % 60
|
||||
(*pos) += 2
|
||||
return
|
||||
}
|
||||
|
||||
func getdatetime(category int, b []byte, pos *int) (year int, month int, day int, hour int, minute int) {
|
||||
hour = 15
|
||||
if category < 4 || category == 7 || category == 8 {
|
||||
var zipday, tminutes uint16
|
||||
binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &zipday)
|
||||
(*pos) += 2
|
||||
binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &tminutes)
|
||||
(*pos) += 2
|
||||
|
||||
year = int((zipday >> 11) + 2004)
|
||||
month = int((zipday % 2048) / 100)
|
||||
day = int((zipday % 2048) % 100)
|
||||
hour = int(tminutes / 60)
|
||||
minute = int(tminutes % 60)
|
||||
} else {
|
||||
var zipday uint32
|
||||
binary.Read(bytes.NewBuffer(b[*pos:*pos+4]), binary.LittleEndian, &zipday)
|
||||
(*pos) += 4
|
||||
year = int(zipday / 10000)
|
||||
month = int((zipday % 10000) / 100)
|
||||
day = int(zipday % 100)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func getdatetimenow(category int, lasttime string) (year int, month int, day int, hour int, minute int) {
|
||||
utime, _ := time.Parse("2006-01-02 15:04:05", lasttime)
|
||||
switch category {
|
||||
case KLINE_TYPE_5MIN:
|
||||
utime = utime.Add(time.Minute * 5)
|
||||
case KLINE_TYPE_15MIN:
|
||||
utime = utime.Add(time.Minute * 15)
|
||||
case KLINE_TYPE_30MIN:
|
||||
utime = utime.Add(time.Minute * 30)
|
||||
case KLINE_TYPE_1HOUR:
|
||||
utime = utime.Add(time.Hour)
|
||||
case KLINE_TYPE_DAILY:
|
||||
utime = utime.AddDate(0, 0, 1)
|
||||
case KLINE_TYPE_WEEKLY:
|
||||
utime = utime.Add(time.Hour * 24 * 7)
|
||||
case KLINE_TYPE_MONTHLY:
|
||||
utime = utime.AddDate(0, 1, 0)
|
||||
case KLINE_TYPE_EXHQ_1MIN:
|
||||
utime = utime.Add(time.Minute)
|
||||
case KLINE_TYPE_1MIN:
|
||||
utime = utime.Add(time.Minute)
|
||||
case KLINE_TYPE_RI_K:
|
||||
utime = utime.AddDate(0, 0, 1)
|
||||
case KLINE_TYPE_3MONTH:
|
||||
utime = utime.AddDate(0, 3, 0)
|
||||
case KLINE_TYPE_YEARLY:
|
||||
utime = utime.AddDate(1, 0, 0)
|
||||
}
|
||||
|
||||
if category < 4 || category == 7 || category == 8 {
|
||||
if (utime.Hour() >= 15 && utime.Minute() > 0) || (utime.Hour() > 15) {
|
||||
utime = utime.AddDate(0, 0, 1)
|
||||
utime = utime.Add(time.Minute * 30)
|
||||
hour = (utime.Hour() + 18) % 24
|
||||
} else {
|
||||
hour = utime.Hour()
|
||||
}
|
||||
minute = utime.Minute()
|
||||
} else {
|
||||
if utime.Unix() > time.Now().Unix() {
|
||||
utime = time.Now()
|
||||
}
|
||||
hour = utime.Hour()
|
||||
minute = utime.Minute()
|
||||
if utime.Hour() > 15 {
|
||||
hour = 15
|
||||
minute = 0
|
||||
}
|
||||
}
|
||||
year = utime.Year()
|
||||
month = int(utime.Month())
|
||||
day = utime.Day()
|
||||
return
|
||||
}
|
||||
|
||||
func getvolume(ivol int) (volume float64) {
|
||||
logpoint := ivol >> (8 * 3)
|
||||
//hheax := ivol >> (8 * 3) // [3]
|
||||
hleax := (ivol >> (8 * 2)) & 0xff // [2]
|
||||
lheax := (ivol >> 8) & 0xff //[1]
|
||||
lleax := ivol & 0xff //[0]
|
||||
|
||||
//dbl_1 := 1.0
|
||||
//dbl_2 := 2.0
|
||||
//dbl_128 := 128.0
|
||||
|
||||
dwEcx := logpoint*2 - 0x7f
|
||||
dwEdx := logpoint*2 - 0x86
|
||||
dwEsi := logpoint*2 - 0x8e
|
||||
dwEax := logpoint*2 - 0x96
|
||||
tmpEax := dwEcx
|
||||
if dwEcx < 0 {
|
||||
tmpEax = -dwEcx
|
||||
} else {
|
||||
tmpEax = dwEcx
|
||||
}
|
||||
|
||||
dbl_xmm6 := 0.0
|
||||
dbl_xmm6 = math.Pow(2.0, float64(tmpEax))
|
||||
if dwEcx < 0 {
|
||||
dbl_xmm6 = 1.0 / dbl_xmm6
|
||||
}
|
||||
|
||||
dbl_xmm4 := 0.0
|
||||
dbl_xmm0 := 0.0
|
||||
|
||||
if hleax > 0x80 {
|
||||
tmpdbl_xmm3 := 0.0
|
||||
//tmpdbl_xmm1 := 0.0
|
||||
dwtmpeax := dwEdx + 1
|
||||
tmpdbl_xmm3 = math.Pow(2.0, float64(dwtmpeax))
|
||||
dbl_xmm0 = math.Pow(2.0, float64(dwEdx)) * 128.0
|
||||
dbl_xmm0 += float64(hleax&0x7f) * tmpdbl_xmm3
|
||||
dbl_xmm4 = dbl_xmm0
|
||||
} else {
|
||||
if dwEdx >= 0 {
|
||||
dbl_xmm0 = math.Pow(2.0, float64(dwEdx)) * float64(hleax)
|
||||
} else {
|
||||
dbl_xmm0 = (1 / math.Pow(2.0, float64(dwEdx))) * float64(hleax)
|
||||
}
|
||||
dbl_xmm4 = dbl_xmm0
|
||||
}
|
||||
|
||||
dbl_xmm3 := math.Pow(2.0, float64(dwEsi)) * float64(lheax)
|
||||
dbl_xmm1 := math.Pow(2.0, float64(dwEax)) * float64(lleax)
|
||||
if (hleax & 0x80) > 0 {
|
||||
dbl_xmm3 *= 2.0
|
||||
dbl_xmm1 *= 2.0
|
||||
}
|
||||
volume = dbl_xmm6 + dbl_xmm4 + dbl_xmm3 + dbl_xmm1
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user