Documentation
¶
Index ¶
Constants ¶
View Source
const ( EastMoney80Push2ApiBase = "http://80.push2.eastmoney.com" EastMoneyPush2ApiBase = "http://push2.eastmoney.com" EastMoneyPush2HisApiBase = "https://push2his.eastmoney.com" QuoteFQTDefault = 0 // 不复权 QuoteFQTFront = 1 // 前复权 QuoteFQTPost = 2 // 后复权 )
View Source
const ( EfinanceStockQuoteURL = "http://push2his.eastmoney.com/api/qt/stock/kline/get" // 东方财富 kline 返回数据按逗号拆分后的长度 "2023-11-14,29.87,30.20,30.20,29.86,448343,1347710790.00,1.14,1.27,0.38,0.22" EfinanceKlineLen = 11 EfinancePeriodDaily = "daily" EfinancePeriodWeekly = "weekly" EfinancePeriodMonthly = "monthly" EfinanceAdjustQfq = "qfq" // 前复权 EfinanceAdjustHfq = "hfq" // 后复权 EfinanceAdjustNone = "" // 不复权 )
Variables ¶
View Source
var ( EfinancePeriodMap = map[string]string{ "daily": "101", "weekly": "102", "monthly": "103", } EfinanceAdjustMap = map[string]string{ "qfq": "1", "hfq": "2", "": "0", } )
View Source
var ErrInvalidKLine = errors.New("invalid kline data")
View Source
var ErrSkipValue = errors.New("skip value")
Functions ¶
This section is empty.
Types ¶
type CurrentStockInfoData ¶
type CurrentStockInfoDiff ¶
type CurrentStockInfoDiff struct {
F2 float64 `json:"f2"` // 最新价格
F3 float64 `json:"f3"` // 涨跌幅
F4 float64 `json:"f4"` // 涨跌额
F5 float64 `json:"f5"` // 成交量
F6 float64 `json:"f6"` // 成交额
F7 float64 `json:"f7"` // 振幅
F8 float64 `json:"f8"` // 换手率
F9 float64 `json:"f9"` // 动态市盈率
F10 float64 `json:"f10"` // 量比
F12 string `json:"f12"` // 证券代码
F13 int `json:"f13"` // 市场编号 0深证 1上证
F14 string `json:"f14"` // 证券名称
F15 float64 `json:"f15"` // high
F16 float64 `json:"f16"` // low
F17 float64 `json:"f17"` // open
F18 float64 `json:"f18"` // yclose
F20 float64 `json:"f20"` // 总市值 "-" 表示非股票
F21 float64 `json:"f21"` // 流通市值 "-" 表示非股票
F23 float64 `json:"f23"` // 市净率
F37 float64 `json:"f37"` // 净资产收益率
F38 float64 `json:"f38"` // 总股本
F39 float64 `json:"f39"` // 流通股本
F124 int64 `json:"f124"` // 更新时间戳
F297 int64 `json:"f297"` // 最新交易日 20241227
}
func ParseCurrentStockInfoDiff ¶
func ParseCurrentStockInfoDiff(in map[string]interface{}) (out *CurrentStockInfoDiff, err error)
ParseCurrentStockInfoDiff 解析返回结果
type CurrentStockInfoResp ¶
type CurrentStockInfoResp struct {
Rc int `json:"rc"`
Rt int `json:"rt"`
Svr int64 `json:"svr"`
Lt int `json:"lt"`
Full int `json:"full"`
Dlmkts string `json:"dlmkts"`
Data *CurrentStockInfoData `json:"data"`
}
func GetCurrentStockInfo ¶
func GetCurrentStockInfo() (resp *CurrentStockInfoResp, err error)
获取当前所有股票信息
func GetRealtimeQuotes ¶
func GetRealtimeQuotes() (resp *CurrentStockInfoResp, err error)
获取当前所有股票信息
type EfinanceStockItem ¶
type EfinanceStockItem struct {
Code string `json:"code"`
Market int `json:"market"`
Name string `json:"name"`
Decimal int `json:"decimal"`
Dktotal int `json:"dktotal"`
PreKPrice float64 `json:"preKPrice"`
PrePrice float64 `json:"prePrice"`
QtMiscType int `json:"qtMiscType"`
Klines []string `json:"klines"`
}
type EfinanceStockResp ¶
type GetQuoteHistoryReq ¶
type KLineQuote ¶
type KLineQuote struct {
Date time.Time
Open float64
Close float64
High float64
Low float64
Volume int64 // 成交量
TurnOver float64 // 成交额
Amplitude float64 // 振幅
ChangeRate float64 // 涨跌幅
Change float64 // 涨跌额
Velocity float64 // TurnOver Rate 换手率
}
KLineQuote K 线结构体
func ParseKlineItem ¶
func ParseKlineItem(line string) (kline KLineQuote, err error)
ParseKlineItem 解析单条 k 线数据 "2024-12-26,39.40,39.48,39.54,39.01,539252,2125139425.00,1.35,0.20,0.08,0.26"
type MarketType ¶
type MarketType int
MarketType 交易所类型
const ( MarketTypeSzSe MarketType = 0 // 深圳证券交易所 MarketTypeSse MarketType = 1 // 上海证券交易所 )
type Quote ¶
type Quote struct {
Date time.Time `json:"date"` // 交易日期
Code string `json:"code"` // 证券代码
Name string `json:"name"` // 证券名称
Market int `json:"market"` // 证券市场
Open float64 `json:"open"` // 开盘价
Close float64 `json:"close"` // 收盘价
High float64 `json:"high"` // 最高价
Low float64 `json:"low"` // 最低价
Volume int64 `json:"volume"` // 成交量
TurnOver float64 `json:"turn_over"` // 成交额
Amplitude float64 `json:"amplitude"` // 振幅
ChangeRate float64 `json:"change_rate"` // 涨跌幅
Change float64 `json:"change"` // 涨跌额
Velocity float64 `json:"velocity"` // TurnOver Rate 换手率
Fqt int `json:"fqt"` // 复权类型
}
Quote 基本行情
func ParseQuoteHistoryResp ¶
func ParseQuoteHistoryResp(resp *QuoteHistoryResp) ([]*Quote, error)
ParseQuoteHistoryResp 解析数据结构到标准结构体
type QuoteHistoryData ¶
type QuoteHistoryData struct {
Code string `json:"code"`
Market int `json:"market"`
Name string `json:"name"`
Decimal int `json:"decimal"` // 小数点精确度
Dktotal int `json:"dktotal"` // 总数据条数
PreKPrice float64 `json:"preKPrice"`
PrePrice float64 `json:"prePrice"`
QtMiscType int `json:"qtMiscType"`
Version int `json:"version"`
Klines []string `json:"klines"`
}
QuoteHistoryData 东方财富 K 线历史接口中 data 字段结构体
type QuoteHistoryResp ¶
type QuoteHistoryResp struct {
Rc int `json:"rc"`
Rt int `json:"rt"`
Svr int64 `json:"svr"`
Lt int `json:"lt"`
Full int `json:"full"`
Dlmkts string `json:"dlmkts"`
Data *QuoteHistoryData `json:"data"`
}
QuoteHistoryResp 东方财富 K 线历史接口返回数据结构
func GetQuoteHistory ¶
func GetQuoteHistory(req *GetQuoteHistoryReq) (resp *QuoteHistoryResp, err error)
GetQuoteHistory 获取证券天级别历史行情信息 api: https://efinance.readthedocs.io/en/latest/api.html#efinance.stock.get_quote_history
type SecurityBasic ¶
type SecurityBasic struct {
ID int64 `json:"id"` // 主键
Code string `json:"code"` // 证券代码
Name string `json:"name"` // 证券简称
ListDate time.Time `json:"list_date"` // 上市日期
Market MarketType `json:"market"` // 交易所 0深证 1上证
Ctime time.Time `json:"ctime"`
Mtime time.Time `json:"mtime"`
Dtime int64 `json:"dtime"` // 软删除标识
}
SecurityBasic 证券基本信息
func GetSecurityBasic ¶
func GetSecurityBasic() ([]*SecurityBasic, error)
GetSecurityBasic 从东方财富接口,获取基本证券信息 这里不是全的,但是存放在 MySQL 中,可以先存部分数据
type StockQuote ¶
type StockQuote struct {
Date time.Time `json:"date"` // 交易日期 "2023-06-02"
Code string `json:"code"` // 证券代码
Name string `json:"name"` // 证券简称
Exchange string `json:"exchange"` // 交易所
Open float64 `json:"open"` // 今日开盘价 单位:元
Close float64 `json:"close"` // 最近成交价 单位:元,对于天级别数据来说,指收盘价
YClose float64 `json:"yclose"` // 昨日收盘价 单位:元
High float64 `json:"high"` // 最高成交价 单位:元
Low float64 `json:"low"` // 最低成交价 单位:元
Volume int64 `json:"volume"` // 成交数量 单位:股
Amount int64 `json:"amount"` // 总笔数 单位:笔
Money float64 `json:"money"` // 成交金额 单位:元
PriceChg float64 `json:"price_change"` // 涨跌 单位:元
PctChg float64 `json:"percent_change"` // 涨跌幅 单位:%
Amplitude float64 `json:"amplitude"` // 振幅 单位:%
Turn float64 `json:"turn"` // 换手率
}
func GetEfinanceStockQuote ¶
func GetEfinanceStockQuote(code, start, end, period, adjust string) ([]*StockQuote, error)
通过 efinance 的接口获取单个股票的天级别行情
{
"rc": 0,
"rt": 17,
"svr": 181669475,
"lt": 1,
"full": 0,
"dlmkts": "",
"data": {
"code": "600036",
"market": 1,
"name": "招商银行",
"decimal": 2,
"dktotal": 5186,
"preKPrice": 30.16,
"prePrice": 28.79,
"qtMiscType": 7,
"klines": [
"2023-11-13,30.17,29.82,30.27,29.61,634243,1891693842.00,2.19,-1.13,-0.34,0.31",
"2023-11-14,29.87,30.20,30.20,29.86,448343,1347710790.00,1.14,1.27,0.38,0.22"
]
}
}
func ParseEfinanceKline ¶
func ParseEfinanceKline(kline string) (res *StockQuote, err error)
Click to show internal directories.
Click to hide internal directories.