trading

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package trading 包含交易中的日历和时段相关的功能函数

Index

Constants

View Source
const (
	CN_TransactionTimeFormat   = "15:04"        // 分笔成交时间格式
	CN_SERVERTIME_FORMAT       = "15:04:05.000" // 服务器时间格式
	CN_SERVERTIME_SHORT_FORMAT = "15:04:05"     // 服务器时间格式
	TimeStampMilli             = "2006-01-02 15:04:05.000"
	TimeStampMicro             = "2006-01-02 15:04:05.000000"
	TimeStampNano              = "2006-01-02 15:04:05.000000000"
)
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:59.999" // A股数据结束时间
	CN_CallAuctionAmBegin      = "09:15:00.000" // 集合竞价-早盘-开始时间
	CN_CallAuctionAmEnd        = "09:27:59.999" // 集合竞价-早盘-结束时间
	CN_CallAuctionAmFinished   = "09:27:00.000" // 集合竞价-早盘-数据结束时间
	CN_CallAuctionTailBegin    = "14:30:00.000" // 尾盘时段-开始
	CN_CallAuctionTailEnd      = "15:01:59.999" // 尾盘时段-结束
	CN_CallAuctionPmBegin      = "14:57:00.000" // 集合竞价-尾盘-开始时间
	CN_CallAuctionPmEnd        = "15:01:59.999" // 集合竞价-尾盘-结束时间
	CN_CallAuctionPmFinished   = "15:01:00.000" // 集合竞价-尾盘-数据结束时间
)

交易日时间相关常量

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 added in v1.9.0

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

CanUpdateInRealtime 能否实时更新

func CheckCallAuctionClose added in v1.10.2

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

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

func CheckCallAuctionCloseFinished added in v1.13.0

func CheckCallAuctionCloseFinished(timestamp time.Time) (finished bool)

CheckCallAuctionCloseFinished 检查当前时间是否集合竞价阶段-结束

func CheckCallAuctionOpen added in v1.10.2

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

CheckCallAuctionOpen 检查当前时间是否集合竞价阶段-进行中

func CheckCallAuctionOpenFinished added in v1.13.0

func CheckCallAuctionOpenFinished(timestamp time.Time) (finished bool)

CheckCallAuctionOpenFinished 检查当前时间是否集合竞价阶段-结束

func CheckCallAuctionTail added in v1.15.2

func CheckCallAuctionTail(timestamp time.Time) (finished bool)

CheckCallAuctionTail 检查当前时间是否集合竞价阶段-结束

func CheckCallAuctionTime added in v1.10.1

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

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

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 added in v1.11.7

func GetCurrentDate(date ...string) (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, threadSafe ...bool) []string

TradeRange 输出交易日范围

默认是线程安全

Types

type DateTimeRange added in v1.17.0

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

func (*DateTimeRange) Minutes added in v1.17.0

func (tr *DateTimeRange) Minutes() int

type FinancialHoliday added in v1.18.3

type FinancialHoliday struct {
	Date     string `name:"日期" array:"0"`
	Holiday  string `name:"节日" array:"1"`
	Country  string `name:"地区" array:"2"`
	Exchange string `name:"交易所" array:"3"`
}

FinancialHoliday 金融假日

type TimeStatus added in v1.9.9

type TimeStatus = int
const (
	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