Compare commits

...

10 Commits

5 changed files with 36 additions and 11 deletions

View File

@@ -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 发送数据,并等待响应
func (this *Client) SendFrame(f *protocol.Frame, cache ...any) (any, error) {
f.MsgID = atomic.AddUint32(&this.msgID, 1)
@@ -440,7 +445,12 @@ func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16
}
// 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)
resp, err := this.GetKlineMonthAll(code)
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())
var res *protocol.TradeResp
for ; start.Before(time.Now()); start = start.Add(time.Hour * 24) {
res, err = this.GetHistoryTradeDay(start.Format("20060102"), code)
w.Range(start, before, func(t time.Time) bool {
for i := 0; i < 3; i++ {
res, err = this.GetHistoryTradeDay(t.Format("20060102"), code)
if err == nil {
break
}
}
if err != nil {
return nil, err
return false
}
ls = append(ls, res.List...)
}
return ls, nil
return true
})
return ls, err
}
// GetHistoryTradeDay 获取历史某天分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据

View File

@@ -4,6 +4,14 @@ import (
"github.com/injoyai/tdx"
)
func GetBjCodes() ([]*tdx.BjCode, error) {
return tdx.GetBjCodes()
func GetBjCodes() ([]string, error) {
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
}

View File

@@ -293,6 +293,7 @@ func (this Klines) Merge(n int) Klines {
if n <= 1 {
return this
}
ks := Klines(nil)
ls := Klines(nil)
for i := 0; ; i++ {

View File

@@ -210,7 +210,7 @@ func (this Trades) klinesForDay(date time.Time) Klines {
//分组,按
for _, v := range this {
ms := minutes(v.Time)
t := conv.Select(ms <= _930, _930, ms)
t := conv.Select(ms < _930, _930, ms)
t++
t = conv.Select(t > _1130 && t <= _1300, _1130, t)
t = conv.Select(t > _1500, _1500, t)

View File

@@ -135,10 +135,10 @@ func basePrice(code string) Price {
return 1
}
switch code[:2] {
case "60", "30", "68", "00", "92", "43":
case "60", "30", "68", "00", "92", "43", "39":
return 1
default:
return 10
return 1
}
}