mirror of
https://github.com/injoyai/tdx.git
synced 2025-11-26 21:25:35 +08:00
修改同花顺的复权日线数据接口
This commit is contained in:
@@ -2,11 +2,9 @@ package extend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/injoyai/conv"
|
"github.com/injoyai/conv"
|
||||||
"github.com/injoyai/tdx"
|
|
||||||
"github.com/injoyai/tdx/protocol"
|
"github.com/injoyai/tdx/protocol"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -20,48 +18,12 @@ const (
|
|||||||
THS_HFQ uint8 = 2 //后复权
|
THS_HFQ uint8 = 2 //后复权
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewTHSDayKline() *THSDayKline {
|
|
||||||
return &THSDayKline{
|
|
||||||
Client: http.DefaultClient,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
THSDayKline
|
GetTHSDayKline
|
||||||
前复权,和通达信对的上,和东方财富对不上
|
前复权,和通达信对的上,和东方财富对不上
|
||||||
后复权,和通达信,东方财富都对不上
|
后复权,和通达信,东方财富都对不上
|
||||||
*/
|
*/
|
||||||
type THSDayKline struct {
|
func GetTHSDayKline(code string, _type uint8) ([]*Kline, error) {
|
||||||
Codes []string
|
|
||||||
Client *http.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *THSDayKline) GetName() string {
|
|
||||||
return "同花顺日线"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *THSDayKline) Run(ctx context.Context, m *tdx.Manage) error {
|
|
||||||
codes := this.Codes
|
|
||||||
if len(codes) == 0 {
|
|
||||||
codes = m.Codes.GetStocks()
|
|
||||||
}
|
|
||||||
for _, _type := range []uint8{THS_QFQ, THS_HFQ} {
|
|
||||||
for _, code := range codes {
|
|
||||||
ls, err := this.Pull(ctx, code, _type)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
_ = ls
|
|
||||||
//加入数据库
|
|
||||||
|
|
||||||
<-time.After(time.Millisecond * 300)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *THSDayKline) Pull(ctx context.Context, code string, _type uint8) ([]*Kline, error) {
|
|
||||||
if _type != THS_QFQ && _type != THS_HFQ {
|
if _type != THS_QFQ && _type != THS_HFQ {
|
||||||
return nil, fmt.Errorf("数据类型错误,例如:前复权1或后复权2")
|
return nil, fmt.Errorf("数据类型错误,例如:前复权1或后复权2")
|
||||||
}
|
}
|
||||||
@@ -85,7 +47,7 @@ func (this *THSDayKline) Pull(ctx context.Context, code string, _type uint8) ([]
|
|||||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54")
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54")
|
||||||
req.Header.Set("Referer", "http://stockpage.10jqka.com.cn/")
|
req.Header.Set("Referer", "http://stockpage.10jqka.com.cn/")
|
||||||
req.Header.Set("DNT", "1")
|
req.Header.Set("DNT", "1")
|
||||||
resp, err := this.Client.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package extend
|
package extend
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewSpiderTHS(t *testing.T) {
|
func TestNewSpiderTHS(t *testing.T) {
|
||||||
x := NewTHSDayKline()
|
ls, err := GetTHSDayKline("sz000001", THS_HFQ)
|
||||||
ls, err := x.Pull(context.Background(), "sz000001", THS_HFQ)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user