Documentation ¶
Overview ¶
对A股中沪深股票,指数,板块,债券和基金提供k线,分时成交和5档报价等行情功能。
GetSecurityBars,GetTransactionData和GetHistoryMinuteTimeData请求:
ths := ths_quote.NewThsQuote(map[string]any{}) resp, err := ths.GetSecurityBars("1A0001", ths_quote.MarketUSHI, -10, 0, ths_quote.FuquanNo, ths_quote.KlineDay) ... resp, err := ths.GetTransactionData"1A0001", ths_quote.MarketUSHI, 100) ... resp, err := ths.GetHistoryMinuteTimeData("1A0001", ths_quote.MarketUSHI, "20220729")
Examples
package main import ( "github.com/bensema/ths_quote" "github.com/panghu1103/quote" "log" "time" ) func main() { var ops = map[string]any{ "username": "xxxxxx", "password": "xxxxxx", "addr": "xxxxxx", } ths := ths_quote.NewThsQuote(ops) quoteApi := quote.NewQuote(ops) ths.SetQuote(quoteApi) if err := ths.Connect(); err != nil { log.Fatal(err) } var req string req = "id=200&instance=815498240&zipversion=2&codelist=399001,399006&market=USZI&datatype=5,6,10,19" startTime := time.Now() results, err := ths.QueryDataAndParse(req) if err != nil { log.Fatal(err) } for _, result := range results { log.Println(result) } endTime := time.Now() log.Println("条数:", len(results), " 耗时:", endTime.Sub(startTime)) }
Output:
2022/07/31 10:20:04 map[code:USZI399001 prev_close:12428.72 price:12266.92 todo_32773:327680 turnover:6041.8436] 2022/07/31 10:20:04 map[code:USZI399006 prev_close:2705.9 price:2670.45 todo_32773:327680 turnover:2016.1737] 2022/07/31 10:20:04 条数: 2 耗时: 32.457397ms
Index ¶
- Constants
- Variables
- func FieldName(num uint32) string
- func GetCodeTypeByMarket(market string) int
- func LoadQuote(pluginPath string, ops map[string]any) (any, error)
- type Quote
- type QuoteResponse
- type ThsQuote
- func (ths *ThsQuote) BlockDataFromBlockServer(sortBegin int, sortCount int, sortOrder string, sortId string, blockId int) ([]map[string]any, error)
- func (ths *ThsQuote) Connect() error
- func (ths *ThsQuote) DisConnect() error
- func (ths *ThsQuote) GetCompleteCode(codes string) ([]map[string]any, error)
- func (ths *ThsQuote) GetHistoryMinuteTimeData(code string, market string, date string) ([]map[string]any, error)
- func (ths *ThsQuote) GetRelevanceCodes(linkKey string) (map[string]string, error)
- func (ths *ThsQuote) GetSecurityBars(code string, market string, start int, end int, fuquan string, period int) ([]map[string]any, error)
- func (ths *ThsQuote) GetTransactionData(code string, market string, count int) ([]map[string]any, error)
- func (ths *ThsQuote) GetTransactionTickData(code string, market string, count int) ([]map[string]any, error)
- func (ths *ThsQuote) ParseFieldName(reply []map[uint32]any) ([]map[string]any, error)
- func (ths *ThsQuote) QueryData(req string) ([]map[uint32]any, error)
- func (ths *ThsQuote) QueryDataAndParse(req string) ([]map[string]any, error)
- func (ths *ThsQuote) Read() (QuoteResponse, error)
- func (ths *ThsQuote) SetQuote(quote Quote)
- func (ths *ThsQuote) Ticker(codes string, market string) ([]map[string]any, error)
- func (ths *ThsQuote) Version() string
- func (ths *ThsQuote) Write(req string) error
Constants ¶
const ( MarketUSHI = "USHI" // 上海指数 MarketUSHA = "USHA" // 上海A股 MarketUSHB = "USHB" // 上海B股 MarketUSHD = "USHD" // 上海可转债 MarketUSHJ = "USHJ" // 上海基金 MarketUSHT = "USHT" // MarketUSHP = "USHP" // MarketUSZP = "USZP" // MarketUZZI = "UZZI" // MarketURFI = "URFI" // 沪深板块? MarketURFA = "URFA" // 沪深板块? MarketUIFF = "UIFF" // 股指期货 MarketUFII = "UFII" // 国外指数 MarketUCMI = "UCMI" // 国外指数 MarketUNQS = "UNQS" // 美股 MarketUNYN = "UNYN" // 美股 MarketUNQQ = "UNQQ" // 美股 MarketUNYA = "UNYA" // 美股 MarketUUSD = "UUSD" // 美股 MarketUUSA = "UUSA" // 美股 MarketUFXB = "UFXB" // 外汇 MarketUFXC = "UFXC" // 外汇 MarketUFXR = "UFXR" // 外汇 MarketUCMN = "UCMN" // 国外期货 MarketUCMS = "UCMS" // 国外期货 MarketUFIS = "UFIS" // 国外期货 MarketUCFS = "UCFS" // 国内期货 MarketUCFD = "UCFD" // 国内期货 MarketUCFZ = "UCFZ" // 国内期货 MarketUSTA = "USTA" // 股转 MarketUSTB = "USTB" // 股转 MarketUSTT = "USTT" // 股转 MarketUSTI = "USTI" // 股转指数 MarketUSOO = "USOO" // 期权 MarketUZOO = "UZOO" // 期权 MarketUCFT = "UCFT" // 期权 MarketUCFL = "UCFL" // 期权 MarketUCFX = "UCFX" // 期权 MarketUIFB = "UIFB" // 期权 MarketUHKI = "UHKI" // 港股指数 MarketUSZI = "USZI" // 深圳指数 MarketUSZA = "USZA" // 深圳A股 MarketUSZB = "USZB" // 深圳B股 MarketUSZJ = "USZJ" // 深圳基金 MarketUSZD = "USZD" // 深圳可转债 )
Market 请求市场字段。
规则 A:A股 B:B股 H:港股 Q:权证 Z:债券 K:板块 X:指数 F:基金 U:美股 G:沪港通 D:叠加 All:所有 QH:期货。
const ( Fuquanqian = "Q" // 前复权 Fuquanhou = "B" // 后复权 FuquanNo = "" // 不复权 )
复权
const ( Kline1m = 0x3001 // 1分钟k Kline5m = 0x3005 // 5分钟k Kline15m = 0x300f // 15分钟k Kline30m = 0x301e // 30分钟k Kline60m = 0x303c // 60分钟k Kline120m = 0x3078 // 120分钟k KlineDay = 0x4000 // 日k KlineWeek = 0x5001 // 周k KlineMoon = 0x6001 // 月k KlineQuarterly = 0x6003 // 季k KlineYear = 0x7001 // 年k )
K线
const (
ZipVersion = "2"
)
Zip版本
Variables ¶
var ErrEmptyData = errors.New("error empty data")
空数据
Functions ¶
func GetCodeTypeByMarket ¶
Types ¶
type QuoteResponse ¶
type ThsQuote ¶
type ThsQuote struct {
// contains filtered or unexported fields
}
func NewThsQuote ¶
func (*ThsQuote) BlockDataFromBlockServer ¶
func (ths *ThsQuote) BlockDataFromBlockServer(sortBegin int, sortCount int, sortOrder string, sortId string, blockId int) ([]map[string]any, error)
BlockDataFromBlockServer 按照block查询数据
sortOrder: A正序 D反序
func (*ThsQuote) GetCompleteCode ¶
GetCompleteCode 数字代码获取完整代码 eg. 159607,600399->USZJ159607, USHA600399
func (*ThsQuote) GetHistoryMinuteTimeData ¶
func (ths *ThsQuote) GetHistoryMinuteTimeData(code string, market string, date string) ([]map[string]any, error)
GetHistoryMinuteTimeData 获取历史分时成交单图数据 可能用于做分时间图
date=0 表示当天
func (*ThsQuote) GetRelevanceCodes ¶
GetRelevanceCodes 关联代码查询 eg. stock_16_Z_A stock_32_Z_A
func (*ThsQuote) GetSecurityBars ¶
func (ths *ThsQuote) GetSecurityBars(code string, market string, start int, end int, fuquan string, period int) ([]map[string]any, error)
GetSecurityBars K线
code: 股票代码
market: 对应市场
start: start是倒序,如果想查20条 start就对应 -20
end: 结束点,到最新对应0
fuquan Q:前复权 B:后复权 空为不复权
period: 对应kline项
func (*ThsQuote) GetTransactionData ¶
func (ths *ThsQuote) GetTransactionData(code string, market string, count int) ([]map[string]any, error)
GetTransactionData 获取分时成交单
func (*ThsQuote) GetTransactionTickData ¶
func (ths *ThsQuote) GetTransactionTickData(code string, market string, count int) ([]map[string]any, error)
GetTransactionTickData 逐笔成交
func (*ThsQuote) ParseFieldName ¶
func (*ThsQuote) QueryDataAndParse ¶
QueryDataAndParse 查询数据返回初步处理后的加工对应field name