mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4d1487f0b6 | ||
|
|
bd3863d3c5 | ||
|
|
5fb1a212c6 | ||
|
|
f381d72ec4 | ||
|
|
5fa572f298 | ||
|
|
61b2e737b3 | ||
|
|
5654065954 | ||
|
|
d7dd7fe0bf | ||
|
|
9fb1a3b651 | ||
|
|
f8a24c0cf1 | ||
|
|
ad0abbe6ba | ||
|
|
0b35006323 | ||
|
|
3b823e2e54 |
28
client.go
28
client.go
@@ -181,6 +181,11 @@ func (this *Client) handlerDealMessage(c *client.Client, msg ios.Acker) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTimeout 设置超时时间
|
||||||
|
func (this *Client) SetTimeout(t time.Duration) {
|
||||||
|
this.Wait.SetTimeout(t)
|
||||||
|
}
|
||||||
|
|
||||||
// SendFrame 发送数据,并等待响应
|
// SendFrame 发送数据,并等待响应
|
||||||
func (this *Client) SendFrame(f *protocol.Frame, cache ...any) (any, error) {
|
func (this *Client) SendFrame(f *protocol.Frame, cache ...any) (any, error) {
|
||||||
f.MsgID = atomic.AddUint32(&this.msgID, 1)
|
f.MsgID = atomic.AddUint32(&this.msgID, 1)
|
||||||
@@ -440,7 +445,12 @@ func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHistoryTradeFull 获取上市至今的分时成交
|
// GetHistoryTradeFull 获取上市至今的分时成交
|
||||||
func (this *Client) GetHistoryTradeFull(code string) (protocol.Trades, error) {
|
func (this *Client) GetHistoryTradeFull(code string, w *Workday) (protocol.Trades, error) {
|
||||||
|
return this.GetHistoryTradeBefore(code, w, time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHistoryTradeBefore 获取上市至今的分时成交
|
||||||
|
func (this *Client) GetHistoryTradeBefore(code string, w *Workday, before time.Time) (protocol.Trades, error) {
|
||||||
ls := protocol.Trades(nil)
|
ls := protocol.Trades(nil)
|
||||||
resp, err := this.GetKlineMonthAll(code)
|
resp, err := this.GetKlineMonthAll(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -451,14 +461,20 @@ func (this *Client) GetHistoryTradeFull(code string) (protocol.Trades, error) {
|
|||||||
}
|
}
|
||||||
start := time.Date(resp.List[0].Time.Year(), resp.List[0].Time.Month(), 1, 0, 0, 0, 0, resp.List[0].Time.Location())
|
start := time.Date(resp.List[0].Time.Year(), resp.List[0].Time.Month(), 1, 0, 0, 0, 0, resp.List[0].Time.Location())
|
||||||
var res *protocol.TradeResp
|
var res *protocol.TradeResp
|
||||||
for ; start.Before(time.Now()); start = start.Add(time.Hour * 24) {
|
w.Range(start, before, func(t time.Time) bool {
|
||||||
res, err = this.GetHistoryTradeDay(start.Format("20060102"), code)
|
for i := 0; i < 3; i++ {
|
||||||
|
res, err = this.GetHistoryTradeDay(t.Format("20060102"), code)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return false
|
||||||
}
|
}
|
||||||
ls = append(ls, res.List...)
|
ls = append(ls, res.List...)
|
||||||
}
|
return true
|
||||||
return ls, nil
|
})
|
||||||
|
return ls, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetHistoryTradeDay 获取历史某天分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据
|
// GetHistoryTradeDay 获取历史某天分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ import (
|
|||||||
"github.com/injoyai/tdx"
|
"github.com/injoyai/tdx"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBjCodes() ([]*tdx.BjCode, error) {
|
func GetBjCodes() ([]string, error) {
|
||||||
return tdx.GetBjCodes()
|
cs, err := tdx.GetBjCodes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ls := []string(nil)
|
||||||
|
for _, v := range cs {
|
||||||
|
ls = append(ls, "bj"+v.Code)
|
||||||
|
}
|
||||||
|
return ls, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,6 +293,7 @@ func (this Klines) Merge(n int) Klines {
|
|||||||
if n <= 1 {
|
if n <= 1 {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
ks := Klines(nil)
|
ks := Klines(nil)
|
||||||
ls := Klines(nil)
|
ls := Klines(nil)
|
||||||
for i := 0; ; i++ {
|
for i := 0; ; i++ {
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ func (this Trades) klinesForDay(date time.Time) Klines {
|
|||||||
//分组,按
|
//分组,按
|
||||||
for _, v := range this {
|
for _, v := range this {
|
||||||
ms := minutes(v.Time)
|
ms := minutes(v.Time)
|
||||||
t := conv.Select(ms <= _930, _930, ms)
|
t := conv.Select(ms < _930, _930, ms)
|
||||||
t++
|
t++
|
||||||
t = conv.Select(t > _1130 && t <= _1300, _1130, t)
|
t = conv.Select(t > _1130 && t <= _1300, _1130, t)
|
||||||
t = conv.Select(t > _1500, _1500, t)
|
t = conv.Select(t > _1500, _1500, t)
|
||||||
|
|||||||
@@ -281,11 +281,11 @@ func IsETF(code string) bool {
|
|||||||
code = strings.ToLower(code)
|
code = strings.ToLower(code)
|
||||||
switch {
|
switch {
|
||||||
case code[0:2] == ExchangeSH.String() &&
|
case code[0:2] == ExchangeSH.String() &&
|
||||||
(code[2:5] == "510" || code[2:5] == "511" || code[2:5] == "512" || code[2:5] == "513" || code[2:5] == "515"):
|
(code[2:4] == "51" || code[2:4] == "56" || code[2:4] == "58"):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case code[0:2] == ExchangeSZ.String() &&
|
case code[0:2] == ExchangeSZ.String() &&
|
||||||
(code[2:5] == "159"):
|
(code[2:4] == "15" || code[2:4] == "16"):
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|||||||
15
workday.go
15
workday.go
@@ -6,6 +6,7 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/injoyai/base/maps"
|
"github.com/injoyai/base/maps"
|
||||||
"github.com/injoyai/conv"
|
"github.com/injoyai/conv"
|
||||||
|
"github.com/injoyai/ios/client"
|
||||||
"github.com/injoyai/logs"
|
"github.com/injoyai/logs"
|
||||||
"github.com/injoyai/tdx/protocol"
|
"github.com/injoyai/tdx/protocol"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
@@ -16,6 +17,14 @@ import (
|
|||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DialWorkday(op ...client.Option) (*Workday, error) {
|
||||||
|
c, err := DialDefault(op...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewWorkdaySqlite(c)
|
||||||
|
}
|
||||||
|
|
||||||
func NewWorkdayMysql(c *Client, dsn string) (*Workday, error) {
|
func NewWorkdayMysql(c *Client, dsn string) (*Workday, error) {
|
||||||
|
|
||||||
//连接数据库
|
//连接数据库
|
||||||
@@ -150,11 +159,11 @@ func (this *Workday) RangeYear(year int, f func(t time.Time) bool) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Range 遍历指定范围的工作日
|
// Range 遍历指定范围的工作日,推荐start带上时间15:00,这样当天小于15点不会触发
|
||||||
func (this *Workday) Range(start, end time.Time, f func(t time.Time) bool) {
|
func (this *Workday) Range(start, end time.Time, f func(t time.Time) bool) {
|
||||||
start = conv.Select(start.Before(protocol.ExchangeEstablish), protocol.ExchangeEstablish, start)
|
start = conv.Select(start.Before(protocol.ExchangeEstablish), protocol.ExchangeEstablish, start)
|
||||||
now := IntegerDay(time.Now())
|
//now := IntegerDay(time.Now())
|
||||||
end = conv.Select(end.After(now), now, end).Add(1)
|
//end = conv.Select(end.After(now), now, end).Add(1)
|
||||||
for ; start.Before(end); start = start.Add(time.Hour * 24) {
|
for ; start.Before(end); start = start.Add(time.Hour * 24) {
|
||||||
if this.Is(start) {
|
if this.Is(start) {
|
||||||
if !f(start) {
|
if !f(start) {
|
||||||
|
|||||||
Reference in New Issue
Block a user