tdx

package module
v0.0.58 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 32 Imported by: 3

README

说明

如何使用

package main

import (
	"fmt"
	"github.com/injoyai/tdx"
)

func main() {
	//连接服务器,开启日志,开启断连重试
	c, err := tdx.Dial("124.71.187.122:7709", tdx.WithDebug(), tdx.WithRedial())
	if err != nil {
		panic(err)
	}
	resp, err := c.GetQuote("sz000001", "sh600008")
	if err != nil {
		panic(err)
	}

	for _, v := range resp {
		fmt.Printf("%#v\n", v)
	}
	<-c.Done()
}

开发进度(一期完成)

  • 基本信息(5档报价)
  • 股票列表
  • 分时成交
  • K线

数据校对

  • 日K线校对

  • 所有K线已校验

  • 校对分时成交

服务器地址(端口7709)

IP 测试时间 所属地区 运营商
124.71.187.122 2025-11-27 上海 华为
122.51.120.217 2025-11-27 上海 腾讯
111.229.247.189 2025-11-27 上海 腾讯
124.70.176.52 2025-11-27 上海 华为
123.60.186.45 2025-11-27 上海 华为
122.51.232.182 2025-11-27 上海 腾讯
118.25.98.114 2025-11-27 上海 腾讯
124.70.199.56 2025-11-27 上海 华为
121.36.225.169 2025-11-27 上海 华为
123.60.70.228 2025-11-27 上海 华为
123.60.73.44 2025-11-27 上海 华为
124.70.133.119 2025-11-27 上海 华为
124.71.187.72 2025-11-27 上海 华为
123.60.84.66 2025-11-27 上海 华为
121.36.54.217 2025-11-27 北京 华为
121.36.81.195 2025-11-27 北京 华为
123.249.15.60 2025-11-27 北京 华为
124.70.75.113 2025-11-27 北京 华为
120.46.186.223 2025-11-27 北京 华为
124.70.22.210 2025-11-27 北京 华为
139.9.133.247 2025-11-27 北京 华为
124.71.85.110 2025-11-27 广州 华为
139.9.51.18 2025-11-27 广州 华为
139.159.239.163 2025-11-27 广州 华为
124.71.9.153 2025-11-27 广州 华为
116.205.163.254 2025-11-27 广州 华为
116.205.171.132 2025-11-27 广州 华为
116.205.183.150 2025-11-27 广州 华为
111.230.186.52 2025-11-27 广州 腾讯
110.41.4.4 2025-11-27 广州 华为
110.41.2.72 2025-11-27 广州 华为
110.41.154.219 2025-11-27 广州 华为
110.41.147.114 2025-11-27 广州 华为
119.97.185.59 2025-11-27 武汉 电信

Documentation

Index

Constants

View Source
const (
	LevelNone  = common.LevelNone
	LevelDebug = common.LevelDebug
	LevelWrite = common.LevelWrite
	LevelRead  = common.LevelRead
	LevelInfo  = common.LevelInfo
	LevelError = common.LevelError
	LevelAll   = common.LevelAll
)
View Source
const (
	DefaultClients     = 1
	DefaultRetry       = 3
	DefaultDataDir     = "./data"
	DefaultDatabaseDir = "./data/database"
)

Variables

View Source
var (

	// Hosts 所有服务器地址(2024-11-30测试通过)
	Hosts = func() []string {
		lenSH := len(SHHosts)
		lenBJ := len(BJHosts)
		lenGZ := len(GZHosts)
		lenWH := len(WHHosts)

		ls := make([]string, lenSH+lenBJ+lenGZ+lenWH)
		copy(ls[:lenSH], SHHosts)
		copy(ls[lenSH:lenSH+lenBJ], BJHosts)
		copy(ls[lenSH+lenBJ:lenSH+lenBJ+lenGZ], GZHosts)
		copy(ls[lenSH+lenBJ+lenGZ:lenSH+lenBJ+lenGZ+lenWH], WHHosts)
		return ls
	}()

	// SHHosts 上海服务器地址
	SHHosts = []string{
		"124.71.187.122",
		"122.51.120.217",
		"111.229.247.189",
		"124.70.176.52",
		"123.60.186.45",
		"122.51.232.182",
		"118.25.98.114",
		"124.70.199.56",
		"121.36.225.169",
		"123.60.70.228",
		"123.60.73.44",
		"124.70.133.119",
		"124.71.187.72",
		"123.60.84.66",
	}

	// BJHosts 北京服务器地址
	BJHosts = []string{
		"121.36.54.217",
		"121.36.81.195",
		"123.249.15.60",
		"124.70.75.113",
		"120.46.186.223",
		"124.70.22.210",
		"139.9.133.247",
	}

	// GZHosts 广州服务器地址,客户端上可能显示深圳
	GZHosts = []string{
		"124.71.85.110",
		"139.9.51.18",
		"139.159.239.163",
		"124.71.9.153",
		"116.205.163.254",
		"116.205.171.132",
		"116.205.183.150",
		"111.230.186.52",
		"110.41.4.4",
		"110.41.2.72",
		"110.41.154.219",
		"110.41.147.114",
	}

	// WHHosts 武汉服务器地址
	WHHosts = []string{
		"119.97.185.59",
	}
)

Functions

func IntegerDay

func IntegerDay(t time.Time) time.Time

func NewHostDial

func NewHostDial(hosts []string) ios.DialFunc

func NewRandomDial

func NewRandomDial(hosts []string) ios.DialFunc

func NewRangeDial

func NewRangeDial(hosts []string) ios.DialFunc

func NewTCPDial

func NewTCPDial(addr string) ios.DialFunc

func WithDebug

func WithDebug(b ...bool) client.Option

WithDebug 是否打印通讯数据

func WithLevel

func WithLevel(level int) client.Option

func WithRedial

func WithRedial(b ...bool) client.Option

WithRedial 断线重连

Types

type Client

type Client struct {
	*client.Client              //客户端实例
	Wait           *wait.Entity //异步回调,设置超时时间,超时则返回错误
	// contains filtered or unexported fields
}

func Dial

func Dial(addr string, op ...client.Option) (cli *Client, err error)

Dial 与服务器建立连接

func DialDefault

func DialDefault(op ...client.Option) (cli *Client, err error)

DialDefault 默认连接方式

func DialHosts

func DialHosts(hosts []string, op ...client.Option) (cli *Client, err error)

DialHosts 与服务器建立连接,多个服务器轮询,开启重试生效

func DialHostsRandom

func DialHostsRandom(hosts []string, op ...client.Option) (cli *Client, err error)

DialHostsRandom 与服务器建立连接,多个服务器随机连接

func DialHostsRange

func DialHostsRange(hosts []string, op ...client.Option) (cli *Client, err error)

DialHostsRange 遍历设置的服务地址进行连接,成功则结束遍历

func DialWith

func DialWith(dial ios.DialFunc, op ...client.Option) (cli *Client, err error)

DialWith 与服务器建立连接

func (*Client) GetCallAuction added in v0.0.56

func (this *Client) GetCallAuction(code string) (*protocol.CallAuctionResp, error)

func (*Client) GetCode

func (this *Client) GetCode(exchange protocol.Exchange, start uint16) (*protocol.CodeResp, error)

GetCode 获取市场内指定范围内的所有证券代码,一次固定返回1000只,上证股票有效范围370-1480 上证前370只是395/399开头的(中证500/总交易等辅助类),在后面的话是一些100开头的国债 600开头的股票是上证A股,属于大盘股,其中6006开头的股票是最早上市的股票, 6016开头的股票为大盘蓝筹股;900开头的股票是上证B股; 000开头的股票是深证A股,001、002开头的股票也都属于深证A股, 其中002开头的股票是深证A股中小企业股票;200开头的股票是深证B股; 300开头的股票是创业板股票;400开头的股票是三板市场股票。

func (*Client) GetCodeAll

func (this *Client) GetCodeAll(exchange protocol.Exchange) (*protocol.CodeResp, error)

GetCodeAll 通过多次请求的方式获取全部证券代码

func (*Client) GetCount

func (this *Client) GetCount(exchange protocol.Exchange) (*protocol.CountResp, error)

GetCount 获取市场内的股票数量

func (*Client) GetETFCodeAll added in v0.0.57

func (this *Client) GetETFCodeAll() ([]string, error)

GetETFCodeAll 获取所有ETF代码,带前缀例sz159399

func (*Client) GetHistoryMinute

func (this *Client) GetHistoryMinute(date, code string) (*protocol.MinuteResp, error)

GetHistoryMinute 获取历史分时数据

func (*Client) GetHistoryMinuteTrade

func (this *Client) GetHistoryMinuteTrade(date, code string, start, count uint16) (*protocol.TradeResp, error)

GetHistoryMinuteTrade 获取历史分时交易 只能获取昨天及之前的数据,服务器最多返回2000条,count-start<=2000,如果日期输入错误,则返回0 历史数据只能查到20000609

func (*Client) GetHistoryMinuteTradeDay

func (this *Client) GetHistoryMinuteTradeDay(date, code string) (*protocol.TradeResp, error)

GetHistoryMinuteTradeDay 获取历史某天分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据 历史数据只能查到20000609

func (*Client) GetHistoryTrade

func (this *Client) GetHistoryTrade(date, code string, start, count uint16) (*protocol.TradeResp, error)

func (*Client) GetHistoryTradeBefore

func (this *Client) GetHistoryTradeBefore(code string, w *Workday, before time.Time) (protocol.Trades, error)

GetHistoryTradeBefore 获取上市至今的分时成交

func (*Client) GetHistoryTradeDay

func (this *Client) GetHistoryTradeDay(date, code string) (*protocol.TradeResp, error)

GetHistoryTradeDay 获取历史某天分时全部交易,通过多次请求来拼接,只能获取昨天及之前的数据

func (*Client) GetHistoryTradeFull

func (this *Client) GetHistoryTradeFull(code string, w *Workday) (protocol.Trades, error)

GetHistoryTradeFull 获取上市至今的分时成交

func (*Client) GetIndex

func (this *Client) GetIndex(Type uint8, code string, start, count uint16) (*protocol.KlineResp, error)

GetIndex 获取指数,接口是和k线一样的,但是解析不知道怎么区分(解析方式不一致),所以加一个方法

func (*Client) GetIndex5Minute

func (this *Client) GetIndex5Minute(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndex15Minute

func (this *Client) GetIndex15Minute(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndex30Minute

func (this *Client) GetIndex30Minute(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndex60Minute

func (this *Client) GetIndex60Minute(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndexAll

func (this *Client) GetIndexAll(Type uint8, code string) (*protocol.KlineResp, error)

GetIndexAll 获取全部k线数据

func (*Client) GetIndexCodeAll added in v0.0.57

func (this *Client) GetIndexCodeAll() ([]string, error)

GetIndexCodeAll 获取所有指数代码,带前缀例sz399001

func (*Client) GetIndexDay

func (this *Client) GetIndexDay(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndexDayAll

func (this *Client) GetIndexDayAll(code string) (*protocol.KlineResp, error)

func (*Client) GetIndexDayUntil

func (this *Client) GetIndexDayUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetIndexMinute

func (this *Client) GetIndexMinute(code string, start, count uint16) (*protocol.KlineResp, error)

func (*Client) GetIndexMonthAll

func (this *Client) GetIndexMonthAll(code string) (*protocol.KlineResp, error)

func (*Client) GetIndexQuarterAll

func (this *Client) GetIndexQuarterAll(code string) (*protocol.KlineResp, error)

func (*Client) GetIndexUntil

func (this *Client) GetIndexUntil(Type uint8, code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

GetIndexUntil 获取指数k线数据,通过多次请求来拼接,直到满足func返回true

func (*Client) GetIndexWeekAll

func (this *Client) GetIndexWeekAll(code string) (*protocol.KlineResp, error)

func (*Client) GetIndexYearAll

func (this *Client) GetIndexYearAll(code string) (*protocol.KlineResp, error)

func (*Client) GetKline

func (this *Client) GetKline(Type uint8, code string, start, count uint16) (*protocol.KlineResp, error)

GetKline 获取k线数据,推荐收盘之后获取,否则会获取到当天的数据

func (*Client) GetKline5Minute

func (this *Client) GetKline5Minute(code string, start, count uint16) (*protocol.KlineResp, error)

GetKline5Minute 获取五分钟k线数据

func (*Client) GetKline5MinuteAll

func (this *Client) GetKline5MinuteAll(code string) (*protocol.KlineResp, error)

GetKline5MinuteAll 获取5分钟k线全部数据

func (*Client) GetKline5MinuteUntil

func (this *Client) GetKline5MinuteUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKline15Minute

func (this *Client) GetKline15Minute(code string, start, count uint16) (*protocol.KlineResp, error)

GetKline15Minute 获取十五分钟k线数据

func (*Client) GetKline15MinuteAll

func (this *Client) GetKline15MinuteAll(code string) (*protocol.KlineResp, error)

GetKline15MinuteAll 获取十五分钟k线全部数据

func (*Client) GetKline15MinuteUntil

func (this *Client) GetKline15MinuteUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKline30Minute

func (this *Client) GetKline30Minute(code string, start, count uint16) (*protocol.KlineResp, error)

GetKline30Minute 获取三十分钟k线数据

func (*Client) GetKline30MinuteAll

func (this *Client) GetKline30MinuteAll(code string) (*protocol.KlineResp, error)

GetKline30MinuteAll 获取三十分钟k线全部数据

func (*Client) GetKline30MinuteUntil

func (this *Client) GetKline30MinuteUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKline60Minute

func (this *Client) GetKline60Minute(code string, start, count uint16) (*protocol.KlineResp, error)

GetKline60Minute 获取60分钟k线数据

func (*Client) GetKline60MinuteAll

func (this *Client) GetKline60MinuteAll(code string) (*protocol.KlineResp, error)

GetKline60MinuteAll 获取60分钟k线全部数据

func (*Client) GetKline60MinuteUntil

func (this *Client) GetKline60MinuteUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineAll

func (this *Client) GetKlineAll(Type uint8, code string) (*protocol.KlineResp, error)

GetKlineAll 获取全部k线数据

func (*Client) GetKlineDay

func (this *Client) GetKlineDay(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineDay 获取日k线数据

func (*Client) GetKlineDayAll

func (this *Client) GetKlineDayAll(code string) (*protocol.KlineResp, error)

GetKlineDayAll 获取日k线全部数据

func (*Client) GetKlineDayUntil

func (this *Client) GetKlineDayUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineHour

func (this *Client) GetKlineHour(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineHour 获取小时k线数据

func (*Client) GetKlineHourAll

func (this *Client) GetKlineHourAll(code string) (*protocol.KlineResp, error)

GetKlineHourAll 获取小时k线全部数据

func (*Client) GetKlineHourUntil

func (this *Client) GetKlineHourUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineMinute

func (this *Client) GetKlineMinute(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineMinute 获取一分钟k线数据,每次最多800条,最多只能获取24000条数据

func (*Client) GetKlineMinuteAll

func (this *Client) GetKlineMinuteAll(code string) (*protocol.KlineResp, error)

GetKlineMinuteAll 获取一分钟k线全部数据,最多只能获取24000条数据

func (*Client) GetKlineMinuteUntil

func (this *Client) GetKlineMinuteUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineMonth

func (this *Client) GetKlineMonth(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineMonth 获取月k线数据

func (*Client) GetKlineMonthAll

func (this *Client) GetKlineMonthAll(code string) (*protocol.KlineResp, error)

GetKlineMonthAll 获取月k线全部数据

func (*Client) GetKlineMonthUntil

func (this *Client) GetKlineMonthUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineQuarter

func (this *Client) GetKlineQuarter(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineQuarter 获取季k线数据

func (*Client) GetKlineQuarterAll

func (this *Client) GetKlineQuarterAll(code string) (*protocol.KlineResp, error)

GetKlineQuarterAll 获取季k线全部数据

func (*Client) GetKlineQuarterUntil

func (this *Client) GetKlineQuarterUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineUntil

func (this *Client) GetKlineUntil(Type uint8, code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

GetKlineUntil 获取k线数据,通过多次请求来拼接,直到满足func返回true

func (*Client) GetKlineWeek

func (this *Client) GetKlineWeek(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineWeek 获取周k线数据

func (*Client) GetKlineWeekAll

func (this *Client) GetKlineWeekAll(code string) (*protocol.KlineResp, error)

GetKlineWeekAll 获取周k线全部数据

func (*Client) GetKlineWeekUntil

func (this *Client) GetKlineWeekUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetKlineYear

func (this *Client) GetKlineYear(code string, start, count uint16) (*protocol.KlineResp, error)

GetKlineYear 获取年k线数据

func (*Client) GetKlineYearAll

func (this *Client) GetKlineYearAll(code string) (*protocol.KlineResp, error)

GetKlineYearAll 获取年k线数据

func (*Client) GetKlineYearUntil

func (this *Client) GetKlineYearUntil(code string, f func(k *protocol.Kline) bool) (*protocol.KlineResp, error)

func (*Client) GetMinute

func (this *Client) GetMinute(code string) (*protocol.MinuteResp, error)

GetMinute 获取分时数据,todo 解析好像不对,先用历史数据

func (*Client) GetMinuteTrade

func (this *Client) GetMinuteTrade(code string, start, count uint16) (*protocol.TradeResp, error)

GetMinuteTrade 获取分时交易详情,服务器最多返回1800条,count-start<=1800

func (*Client) GetMinuteTradeAll

func (this *Client) GetMinuteTradeAll(code string) (*protocol.TradeResp, error)

GetMinuteTradeAll 获取分时全部交易详情,todo 只做参考 因为交易实时在进行,然后又是分页读取的,所以会出现读取间隔内产生的交易会丢失

func (*Client) GetQuote

func (this *Client) GetQuote(codes ...string) (protocol.QuotesResp, error)

GetQuote 获取盘口五档报价

func (*Client) GetStockCodeAll added in v0.0.57

func (this *Client) GetStockCodeAll() ([]string, error)

GetStockCodeAll 获取所有股票代码,带前缀例sz000001

func (*Client) GetTrade

func (this *Client) GetTrade(code string, start, count uint16) (*protocol.TradeResp, error)

func (*Client) GetTradeAll

func (this *Client) GetTradeAll(code string) (*protocol.TradeResp, error)

func (*Client) SendFrame

func (this *Client) SendFrame(f *protocol.Frame, cache ...any) (any, error)

SendFrame 发送数据,并等待响应

func (*Client) SetTimeout

func (this *Client) SetTimeout(t time.Duration)

SetTimeout 设置超时时间

type CodeModel

type CodeModel struct {
	ID        int64   `json:"id"`                      //主键
	Name      string  `json:"name"`                    //名称,有时候名称会变,例STxxx
	Code      string  `json:"code" xorm:"index"`       //代码
	Exchange  string  `json:"exchange" xorm:"index"`   //交易所
	Multiple  uint16  `json:"multiple"`                //倍数
	Decimal   int8    `json:"decimal"`                 //小数位
	LastPrice float64 `json:"lastPrice"`               //昨收价格
	EditDate  int64   `json:"editDate" xorm:"updated"` //修改时间
	InDate    int64   `json:"inDate" xorm:"created"`   //创建时间
}

func (*CodeModel) FullCode

func (this *CodeModel) FullCode() string

FullCode 获取完整代码 sz000001

func (*CodeModel) Price

func (this *CodeModel) Price(p protocol.Price) protocol.Price

func (*CodeModel) TableName

func (*CodeModel) TableName() string

type CodeModels

type CodeModels []*CodeModel

func (CodeModels) Codes

func (this CodeModels) Codes() []string

type Codes

type Codes struct {
	*CodesBase
	// contains filtered or unexported fields
}

func NewCodes

func NewCodes(op ...CodesOption) (*Codes, error)

func NewCodesMysql

func NewCodesMysql(dsn string, op ...CodesOption) (*Codes, error)

func NewCodesSqlite

func NewCodesSqlite(op ...CodesOption) (*Codes, error)

func (*Codes) Update

func (this *Codes) Update() error

type CodesBase

type CodesBase struct {
	// contains filtered or unexported fields
}

func NewCodesBase

func NewCodesBase() *CodesBase

func (*CodesBase) Get

func (this *CodesBase) Get(code string) *CodeModel

func (*CodesBase) GetETFCodes

func (this *CodesBase) GetETFCodes(limits ...int) []string

GetETFCodes 获取基金代码,sz159xxx,sh510xxx,sh511xxx

func (*CodesBase) GetETFs

func (this *CodesBase) GetETFs(limits ...int) CodeModels

GetETFs 获取基金代码,sz159xxx,sh510xxx,sh511xxx

func (*CodesBase) GetIndexCodes

func (this *CodesBase) GetIndexCodes(limits ...int) []string

GetIndexCodes 获取基金代码,sz159xxx,sh510xxx,sh511xxx

func (*CodesBase) GetIndexes

func (this *CodesBase) GetIndexes(limits ...int) CodeModels

GetIndexes 获取基金代码,sz159xxx,sh510xxx,sh511xxx

func (*CodesBase) GetName

func (this *CodesBase) GetName(code string) string

GetName 获取股票名称

func (*CodesBase) GetStockCodes

func (this *CodesBase) GetStockCodes(limits ...int) []string

GetStockCodes 获取股票代码,sh6xxx sz0xx sz30xx

func (*CodesBase) GetStocks

func (this *CodesBase) GetStocks(limits ...int) CodeModels

GetStocks 获取股票代码,sh6xxx sz0xx sz30xx

func (*CodesBase) Iter

func (this *CodesBase) Iter() iter.Seq2[string, *CodeModel]

func (*CodesBase) Update

func (this *CodesBase) Update(ls []*CodeModel)

type CodesOption added in v0.0.58

type CodesOption func(*Codes)

func WithCodesClient added in v0.0.58

func WithCodesClient(c *Client) CodesOption

func WithCodesDB added in v0.0.58

func WithCodesDB(db *xorms.Engine) CodesOption

func WithCodesDialClient added in v0.0.58

func WithCodesDialClient(dial DialClientFunc) CodesOption

func WithCodesDialDB added in v0.0.58

func WithCodesDialDB(dial DialDBFunc) CodesOption

func WithCodesOption added in v0.0.58

func WithCodesOption(op ...CodesOption) CodesOption

func WithCodesRetry added in v0.0.58

func WithCodesRetry(retry int) CodesOption

func WithCodesSpec added in v0.0.58

func WithCodesSpec(spec string) CodesOption

type DialClientFunc added in v0.0.58

type DialClientFunc func() (*Client, error)

type DialCodesFunc

type DialCodesFunc func(c *Client) (ICodes, error)

type DialDBFunc added in v0.0.58

type DialDBFunc func() (*xorms.Engine, error)

type DialEquityFunc added in v0.0.58

type DialEquityFunc func(c *Client) (IEquity, error)

type DialPoolFunc added in v0.0.58

type DialPoolFunc = func() (IPool, error)

type DialResult

type DialResult struct {
	Host  string
	Spend time.Duration
}

DialResult 连接结果

func FastHosts

func FastHosts(hosts ...string) []DialResult

FastHosts 通过tcp(ping不可用)连接速度的方式筛选排序可用的地址

type DialWorkdayFunc

type DialWorkdayFunc func(c *Client) (*Workday, error)

type Equity added in v0.0.58

type Equity struct {
	// contains filtered or unexported fields
}

func NewEquity added in v0.0.58

func NewEquity(op ...EquityOption) (*Equity, error)

func (*Equity) Get added in v0.0.58

func (this *Equity) Get(code string, t time.Time) *gbbq.Equity

func (*Equity) Turnover added in v0.0.58

func (this *Equity) Turnover(code string, t time.Time, volume float64) float64

func (*Equity) Update added in v0.0.58

func (this *Equity) Update() error

type EquityOption added in v0.0.58

type EquityOption func(e *Equity)

func WithEquityDialDB added in v0.0.58

func WithEquityDialDB(dial func() (*xorms.Engine, error)) EquityOption

func WithEquityRetry added in v0.0.58

func WithEquityRetry(retry int) EquityOption

func WithEquitySpec added in v0.0.58

func WithEquitySpec(spec string) EquityOption

func WithEquityTempDir added in v0.0.58

func WithEquityTempDir(dir string) EquityOption

type ICodes

type ICodes interface {
	Iter() iter.Seq2[string, *CodeModel]
	Get(code string) *CodeModel
	GetName(code string) string
	GetStocks(limit ...int) CodeModels
	GetStockCodes(limit ...int) []string
	GetETFs(limit ...int) CodeModels
	GetETFCodes(limit ...int) []string
	GetIndexes(limit ...int) CodeModels
	GetIndexCodes(limit ...int) []string
}
var DefaultCodes ICodes

DefaultCodes 增加单例,部分数据需要通过Codes里面的信息计算

type IEquity added in v0.0.58

type IEquity interface {
	Get(code string, t time.Time) *gbbq.Equity
	Turnover(code string, t time.Time, volume float64) float64
}

type IPool added in v0.0.58

type IPool interface {
	Get() (*Client, error)
	Put(c *Client)
	Do(fn func(c *Client) error) error
	Go(fn func(c *Client)) error
}

type Manage

type Manage struct {
	IPool
	Codes   ICodes
	Workday *Workday
	Equity  IEquity
	// contains filtered or unexported fields
}

func NewManage

func NewManage(op ...Option) (m *Manage, err error)

func NewManageMysql

func NewManageMysql(dsn string, op ...Option) (*Manage, error)

func (*Manage) AddWorkdayTask

func (this *Manage) AddWorkdayTask(spec string, f func(m *Manage)) error

AddWorkdayTask 添加工作日任务

func (*Manage) RangeETFs

func (this *Manage) RangeETFs(f func(code string))

RangeETFs 遍历所有ETF

func (*Manage) RangeIndexes

func (this *Manage) RangeIndexes(f func(code string))

RangeIndexes 遍历所有指数

func (*Manage) RangeStocks

func (this *Manage) RangeStocks(f func(code string))

RangeStocks 遍历所有股票

type Option

type Option func(m *Manage)

func WithClients

func WithClients(clients int) Option

func WithCodes

func WithCodes(codes ICodes) Option

func WithDialCodes

func WithDialCodes(dial DialCodesFunc) Option

func WithDialEquity added in v0.0.58

func WithDialEquity(dial DialEquityFunc) Option

func WithDialPool added in v0.0.58

func WithDialPool(dial DialPoolFunc) Option

func WithDialWorkday

func WithDialWorkday(dial DialWorkdayFunc) Option

func WithEquity added in v0.0.58

func WithEquity(equity IEquity) Option

func WithOptions

func WithOptions(op ...Option) Option

func WithPool added in v0.0.58

func WithPool(pool IPool) Option

func WithWorkday

func WithWorkday(w *Workday) Option

type Pool

type Pool struct {
	*safe.Closer
	// contains filtered or unexported fields
}

func NewPool

func NewPool(dial func() (*Client, error), number int) (*Pool, error)

NewPool 简易版本的连接池

func (*Pool) Do

func (this *Pool) Do(fn func(c *Client) error) error

func (*Pool) Get

func (this *Pool) Get() (*Client, error)

func (*Pool) Go

func (this *Pool) Go(fn func(c *Client)) error

func (*Pool) Put

func (this *Pool) Put(c *Client)

type UpdateModel

type UpdateModel struct {
	Key  string
	Time int64 //更新时间
}

func (*UpdateModel) TableName

func (*UpdateModel) TableName() string

type Updated added in v0.0.58

type Updated struct {
	// contains filtered or unexported fields
}

func NewUpdated added in v0.0.58

func NewUpdated(key string, db *xorm.Engine) (*Updated, error)

func (*Updated) Update added in v0.0.58

func (this *Updated) Update() error

func (*Updated) Updated added in v0.0.58

func (this *Updated) Updated() (bool, error)

type Workday

type Workday struct {
	// contains filtered or unexported fields
}

func NewWorkday

func NewWorkday(op ...WorkdayOption) (*Workday, error)

func NewWorkdayMysql

func NewWorkdayMysql(dsn string, op ...WorkdayOption) (*Workday, error)

func NewWorkdaySqlite

func NewWorkdaySqlite(op ...WorkdayOption) (*Workday, error)

func (*Workday) Is

func (this *Workday) Is(t time.Time) bool

Is 是否是工作日

func (*Workday) Iter

func (this *Workday) Iter(start, end time.Time, desc ...bool) iter.Seq[time.Time]

Iter 遍历指定范围的工作日,推荐start带上时间15:00,这样当天小于15点不会触发

func (*Workday) IterYear

func (this *Workday) IterYear(year int, desc ...bool) iter.Seq[time.Time]

func (*Workday) Range

func (this *Workday) Range(start, end time.Time, f func(t time.Time) bool)

Range 遍历指定范围的工作日,推荐start带上时间15:00,这样当天小于15点不会触发

func (*Workday) RangeYear

func (this *Workday) RangeYear(year int, f func(t time.Time) bool)

RangeYear 遍历一年的所有工作日

func (*Workday) TodayIs

func (this *Workday) TodayIs() bool

TodayIs 今天是否是工作日

func (*Workday) Update

func (this *Workday) Update() error

Update 更新

type WorkdayModel

type WorkdayModel struct {
	ID   int64  `json:"id"`   //主键
	Unix int64  `json:"unix"` //时间戳
	Date string `json:"date"` //日期
}

WorkdayModel 工作日

func (*WorkdayModel) TableName

func (this *WorkdayModel) TableName() string

type WorkdayOption added in v0.0.58

type WorkdayOption func(w *Workday)

func WithWorkdayClient added in v0.0.58

func WithWorkdayClient(c *Client) WorkdayOption

func WithWorkdayDB added in v0.0.58

func WithWorkdayDB(db *xorms.Engine) WorkdayOption

func WithWorkdayDialClient added in v0.0.58

func WithWorkdayDialClient(dial DialClientFunc) WorkdayOption

func WithWorkdayDialDB added in v0.0.58

func WithWorkdayDialDB(dial DialDBFunc) WorkdayOption

func WithWorkdayOption added in v0.0.58

func WithWorkdayOption(op ...WorkdayOption) WorkdayOption

func WithWorkdayRetry added in v0.0.58

func WithWorkdayRetry(retry int) WorkdayOption

func WithWorkdaySpec added in v0.0.58

func WithWorkdaySpec(spec string) WorkdayOption

Directories

Path Synopsis
example
CheckHosts command
Codes2 command
CodesHTTP command
Connect command
DecodeGBBQ command
DialHostsRange command
FastHosts command
GetBjCodes command
GetCallauction command
GetCode command
GetCodeAll command
GetCount command
GetHistoryTrade command
GetIndex command
GetKlineDay command
GetKlineDayAll command
GetKlineMinute command
GetKlineUntil command
GetKlineYear command
GetMinute command
GetMinuteTrade command
GetQuote command
GetStockCodeAll command
GetTrade command
Income command
Manage command
ManageMysql command
PullKline command
PullTrade command
TradesToKlines command
WorkdayAndCodes command
lib
bse
zip

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL