trading

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 15 Imported by: 8

Documentation

Index

Constants

View Source
const (
	CN_TransactionTimeFormat   = "15:04"        // 分笔成交时间格式
	CN_SERVERTIME_FORMAT       = "15:04:05.000" // 服务器时间格式
	CN_SERVERTIME_SHORT_FORMAT = "15:04:05"     // 服务器时间格式
)
View Source
const (
	CN_MarketInitTime          = "09:00:00.000" // A股数据初始化时间
	CN_TradingStartTime        = "09:15:00.000" // A股数据开始时间
	CN_TradingSuspendBeginTime = "11:30:00.000" // A股午间休市开始时间
	CN_TradingSuspendEndTime   = "12:59:59.999" // A股午间休市结束时间
	CN_TradingStopTime         = "15:00:00.000" // A股数据结束时间
	CN_CallAuctionAmBegin      = "09:15:00.000" // 早盘集合竞价开始时间
	CN_CallAuctionAmEnd        = "09:27:59.999" // 早盘集合竞价结束时间
	CN_CallAuctionPmBegin      = "14:57:00.000" // 尾盘集合竞价开始时间
	CN_CallAuctionPmEnd        = "15:01:59.999" // 尾盘集合竞价结束时间
)

交易日时间相关常量

View Source
const (
	BEGIN_A_AUCTION   = "09:15:00" // A股上午集合竞价开始时间
	END_A_AUCTION     = "09:25:00" // A股上午集合竞价结束时间
	END_A_AUCTION_SPE = "09:26:00" // A股上午集合竞价结束时间过一分钟
	BEGIN_P_AUCTION   = "14:57:00" // A股下午集合竞价开始时间
	END_P_AUCTION     = "15:01:00" // A股下午集合竞价结束时间
	END_P_AUCTION_SPE = "15:02:00" // A股下午集合竞价结束时间过一分钟
)

集合竞价时间相关常量

View Source
const (
	CN_DEFAULT_TOTALFZNUM = 240 // A股默认全天交易240分钟
	BEGIN_A_AM_HOUR       = 9   // A股开市-时
	BEGIN_A_AM_MINUTE     = 30  // A股开市-分
	END_A_AM_HOUR         = 11  // A股休市-时
	END_A_AM_MINUTE       = 30  // A股休市-分
	BEGIN_A_PM_HOUR       = 13  // A股开市-时
	BEGIN_A_PM_MINUTE     = 0   // A股开市-分
	END_A_PM_HOUR         = 15  // A股休市-时
	END_A_PM_MINUTE       = 0   // A股休市-分
)

分时数据相关常量

View Source
const (
	TimeOnly = time.TimeOnly // 时分秒的格式
)
View Source
const (
	TradingDayDateFormat = "2006-01-02" // 交易日历日期格式

)

Variables

View Source
var (
	CN_TOTALFZNUM = 0 // A股全天交易的分钟数
)
View Source
var (
	ErrNoUpdateRequired = errors.New("No update required")
)

Functions

func CanInitialize

func CanInitialize(lastModified ...time.Time) (toInit bool)

CanInitialize 数据是否初始化(One-time update)

func CanUpdate

func CanUpdate(lastModified ...time.Time) (updated bool)

CanUpdate 数据是否可以更新

func CanUpdateInRealtime

func CanUpdateInRealtime(lastModified ...time.Time) (updateInRealTime bool, status int)

CanUpdateInRealtime 能否实时更新

func CheckCallAuctionClose

func CheckCallAuctionClose(timestamp time.Time) (canUpdate bool)

CheckCallAuctionClose 检查当前时间是否集合竞价阶段

func CheckCallAuctionOpen

func CheckCallAuctionOpen(timestamp time.Time) (canUpdate bool)

CheckCallAuctionOpen 检查当前时间是否集合竞价阶段

func CheckCallAuctionTime

func CheckCallAuctionTime(timestamp time.Time) (canUpdate bool)

CheckCallAuctionTime 检查当前时间是否集合竞价阶段

func CompareTime

func CompareTime(t1, t2 string) (bool, error)

CompareTime 比较两个时间字符串大小 如果t1 <= t2 返回true,否则返回false 如果格式不正确或转换错误,返回错误

func CurrentlyTrading

func CurrentlyTrading(date ...string) bool

CurrentlyTrading 今天的交易是否已经开始

func DateIsTradingDay

func DateIsTradingDay(date ...string) bool

DateIsTradingDay date是否交易日?默认是今天

func FixTradeDate

func FixTradeDate(datetime string, format ...string) string

FixTradeDate 强制修正交易日字符串

默认格式 YYYY-MM-DD, 支持其它格式

func GetCurrentDate

func GetCurrentDate() (currentDate string)

GetCurrentDate 获取数据有效的最后一个交易日, 以9点整划分

func GetCurrentlyDay

func GetCurrentlyDay() (currentlyDay string)

GetCurrentlyDay 获取数据有效的最后一个交易日, 以9点15分划分

func GetFrontTradeDay

func GetFrontTradeDay() string

GetFrontTradeDay 获取上一个交易日

func GetLastDayForUpdate

func GetLastDayForUpdate() string

GetLastDayForUpdate 获取可以更新数据的最后一个交易日

func GetTodayTimeByString

func GetTodayTimeByString(timeStr string) (time.Time, error)

GetTodayTimeByString 返回当天指定时刻的时间

func IndexToday

func IndexToday() string

IndexToday 当天

func IsHoliday

func IsHoliday(date string) bool

IsHoliday 是否节假日

func IsTimeInRange

func IsTimeInRange(timeStr, startStr, endStr string) (bool, error)

func IsTrading

func IsTrading(date ...string) bool

func LastNDate

func LastNDate(date string, n ...int) []string

LastNDate 获得指定日期前的N个交易日期数组

func LastTradeDate

func LastTradeDate() string

LastTradeDate 获得最后一个交易日

func Minutes

func Minutes(date ...string) int

Minutes 分钟数

func NextTradeDate

func NextTradeDate(date string) string

NextTradeDate 获取指定日期的下一个交易日

func Today

func Today() string

Today 当日, 区别于IndexToday, IndexToday可能存在调整

func TradeRange

func TradeRange(start, end string) []string

TradeRange 输出交易日范围

Types

type Calendar

type Calendar struct {
	Date   string `dataframe:"date"`
	Source string `dataframe:"source"`
}

type TimeRange

type TimeRange struct {
	Begin time.Time
	End   time.Time
}

type TimeStatus

type TimeStatus = int
const (

	//ExchangeLastClosing TimeStatus = -2 // 隔日收盘收, 交易停止
	ExchangePreMarket   TimeStatus = -1 // 盘前
	ExchangeSuspend     TimeStatus = 0  // 休市中, 交易暂停
	ExchangeTrading     TimeStatus = 1  // 交易中
	ExchangeCallAuction TimeStatus = 2  // 交易中, 集合竞价
	ExchangeClosing     TimeStatus = 3  // 当日收盘, 交易停止
)

Jump to

Keyboard shortcuts

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