global

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_SPEC_YEAR   = "year"
	KEY_SPEC_MONTH  = "month"
	KEY_SPEC_DAY    = "day"
	KEY_SPEC_HOUR   = "hour"
	KEY_SPEC_MINUTE = "minute"
	KEY_SPEC_SECOND = "second"
)
View Source
const (
	LOG_LEVEL_DEBUG = "DEBUG"
	LOG_LEVEL_INFO  = "INFO"
	LOG_LEVEL_WARN  = "WARN"
	LOG_LEVEL_ERROR = "ERROR"
	LOG_LEVEL_FATAL = "FATAL"
	LOG_LEVEL_PANIC = "PANIC"
)

基础日志级别

View Source
const (
	PLATFORM_ID_MASTER = iota + 1000 + 1
	PLATFORM_ID_EXSERVICE
	PLATFORM_ID_HUOBIPRO
	PLATFORM_ID_BINANCE
	PLATFORM_ID_OKEX
	PLATFORM_ID_AOFEX
)

数据源平台(交易所,数据源)ID

View Source
const (
	PLATFORM_NAME_MASTER    = "master"
	PLATFORM_NAME_EXSERVICE = "exservice"
	PLATFORM_NAME_HUOBIPRO  = "huobipro"
	PLATFORM_NAME_BINANCE   = "binance"
	PLATFORM_NAME_OKEX      = "okex"
	PLATFORM_NAME_AOFEX     = "aofex"
)

数据源平台名称(交易所,数据源)ID

View Source
const (
	ACTION_TRADE = "trade"
	ACTION_KLINE = "kline"
	ACTION_DEPTH = "depth"
	ACTION_ASSET = "asset"
	ACTION_ORDER = "order"
)

数据类型

View Source
const (
	DATA_STORAGE_LEVEL_YEAR   = "year"
	DATA_STORAGE_LEVEL_MONTH  = "month"
	DATA_STORAGE_LEVEL_DAY    = "day"
	DATA_STORAGE_LEVEL_HOUR   = "hour"
	DATA_STORAGE_LEVEL_MINUTE = "minute"
	DATA_STORAGE_LEVEL_SECOND = "second"
)

数据存储级别,单文件最小存储单位,年,月,日,小时,分钟,秒

View Source
const (
	BUY_MARKET  = "buy-market"  // 市价买
	SELL_MARKET = "sell-market" // 市价卖
	BUY_LIMIT   = "buy-limit"   // 限价买
	SELL_LIMIT  = "sell-limit"  // 限价卖
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action = string

铁三项

type ApiKey

type ApiKey = string

type AssetsData

type AssetsData struct {
	ID int64 // 时间(K线棒id)
}

资产数据类型

type AssetsService

type AssetsService struct {
}

func NewAssetsService

func NewAssetsService() (os *AssetsService, err error)

创建Order服务

type AssignUpdateInfo

type AssignUpdateInfo struct {
	StartTime    Timestamp    // 开始更新的时间戳,默认为0时,从最开始的时间更新
	EndTime      Timestamp    // 结束更新的时间戳,默认为0时,更新到最新时间
	DataSourceID DataSourceID // 数据源ID号(数据源唯一ID),更新时使用该数据源进行更新数据
}

指定更新的币种信息的详情

type Config

type Config struct {
	DataServiceName string                         // 给数据服务起一个独立的名字
	LogLevel        string                         // 日志级别
	DataStoragePath string                         // 文件缓存的保存路径,如:"./"即为当前项目执行目录
	DataSource      map[DataSourceID]DataSource    // 数据源信息,TAG字段必须按照标准常量输出赋值,否则出错
	UserSecret      UserSecret                     // 托管账户和秘钥
	AssignUpdate    map[DataIndex]AssignUpdateInfo // 指定更新的币种信息,如果为空就是不指定,如果指定了系统只更新指定的币种信息
}

全局服务配置

type DataIndex

type DataIndex struct {
	Action   string // 类型,Kline,Trade,Depth,Assets,Order
	Platform string // 交易所,数据源
	Symbol   string // 交易对
}

数据索引

func (*DataIndex) ToFilePath

func (this *DataIndex) ToFilePath(cachePath string, dt DateTimeDay) (str string)

func (*DataIndex) ToPath

func (this *DataIndex) ToPath(cachePath string) (str string)

func (*DataIndex) ToString

func (this *DataIndex) ToString() (str string)

type DataSource

type DataSource struct {
	// 数据源的唯一标识,对应数据源的名称,
	Tag string

	// 方便人类查看的数据源名称
	Name string

	// 当前数据源是否开启状态
	EnableSource bool

	// 数据源的基础连接地址
	Urls Urls

	// 连接该数据源所需要的密码,例如连接master需要密码验证登录
	Password string

	// 数据源公共接口方法
	DSAction DataSourceAction
}

数据源的类型

type DataSourceAction

type DataSourceAction interface {
	// 设置每个数据源的配置信息
	SetConfig(conf Config)

	// 获取数据源提供的所有交易对列表
	GetSymbolList(dsID DataSourceID) (ss []Symbol, err error)

	// UpdataKlineFileCache 更新K线数据的文件缓存 (Kline,Trade,Depth)
	/*
		参数: di 数据索引
		参数: sTime 更新的开始时间
		参数: eTime 更新的截止时间
		返回值: kbs 返回KlineBar指针的Slice
	*/
	UpdataKlineFileCache(uParam UpdataFileCacheParam, sTime, eTime Timestamp, upStatus chan bool)

	// UpdataKlineFileCache 更新K线数据的文件缓存 (Kline,Trade,Depth)
	/*
		参数: di 数据索引
		参数: sTime 更新的开始时间
		参数: eTime 更新的截止时间
		返回值: kbs 返回KlineBar指针的Slice
	*/
	UpdataTradeFileCache(uParam UpdataFileCacheParam, sTime, eTime Timestamp) (err error)

	// GetKlineBarSlice 获取K线数据列表 (Kline,Trade,Depth)
	/*
		参数: di 数据索引
		参数: sTime 更新的开始时间
		参数: eTime 更新的截止时间
		返回值: kbs 返回KlineBar指针的Slice
	*/
	GetKlineBarSlice(di DataIndex, sTime, eTime Timestamp) (kbs KlineBarSlice, err error)

	// GetTradeSlice 获取K线数据列表 (Kline,Trade,Depth)
	/*
		参数: di 数据索引
		参数: sTime 更新的开始时间
		参数: eTime 更新的截止时间
		返回值: kbs 返回KlineBar指针的Slice
	*/
	GetTradeSlice(di DataIndex, sTime, eTime Timestamp) (kbs KlineBarSlice, err error)

	// KlineRealTimeLine 创建长链接持续提供Kline数据(数据类型为:Kline,Trade,Depth)
	/*
		参数: kp 只能传入一个数据源(当前的数据源),多个币种可同时返回数据
		参数: rsDataChan 返回数据的接收管道,当有数据返回时会给该管道输出数据
	*/
	KlineRealTimeLine(kp RealTimeDataParam, rsData chan KlineRealTimeData)

	// TradeRealTimeLink 创建长链接持续提供Trade数据(数据类型为:Kline,Trade,Depth)
	/*
		参数: kp 只能传入一个数据源(当前的数据源),多个币种可同时返回数据
		参数: rsDataChan 返回数据的接收管道,当有数据返回时会给该管道输出数据
	*/
	TradeRealTimeLink(kp RealTimeDataParam, rsData chan TradeRealTimeData)

	// DepthRealTimeLink 创建长链接持续提供Depth数据(数据类型为:Kline,Trade,Depth)
	/*
		参数: kp 只能传入一个数据源(当前的数据源),多个币种可同时返回数据
		参数: rsDataChan 返回数据的接收管道,当有数据返回时会给该管道输出数据
	*/
	DepthRealTimeLink(kp RealTimeDataParam, rsData chan DepthRealTimeData)
}

数据源公共接口

type DataSourceID

type DataSourceID = uint64

type DateTimeDay

type DateTimeDay = string // 日的日期格式,如: "20060102"

type DateTimeHour

type DateTimeHour = string // 小时的日期格式,如: "2006010215"

type DateTimeMinute

type DateTimeMinute = string // 分钟的日期格式,如: "200601021504"

type DateTimeMonth

type DateTimeMonth = string // 月的日期格式,如: "200601"

type DateTimeSecond

type DateTimeSecond = string // 秒钟的日期格式,如: "20060102150405"

type DateTimeYear

type DateTimeYear = string // 年的日期格式,如: "2006"

type DepthData

type DepthData struct {
	Asks []*DepthInfo // 卖方深度列表
	Bids []*DepthInfo // 买方深度列表
}

深度信息数据

type DepthInfo

type DepthInfo struct {
	Price  float64 // 价格
	Amount float64 // 数量
}

深度信息

type DepthRealTimeData

type DepthRealTimeData struct {
	Ts    Timestamp
	Items map[Platform]map[Symbol]DepthData
}

type DepthRealTimeDataParam

type DepthRealTimeDataParam struct {
	Platforms Platform
	Symbols   []Symbol
}

type KlineBar

type KlineBar struct {
	Ts    Timestamp // 时间戳(单位:秒)
	Open  float64   // 开盘价
	High  float64   // 最高价
	Low   float64   // 最低价
	Close float64   // 收盘价,当K线为最晚的一根时,是最新成交价
	Vol   float64   // 以基础币种计量的交易量
}

K线数据类型

type KlineBarList

type KlineBarList struct {
	sync.Mutex
	// contains filtered or unexported fields
}

K线数据列表类型,按时间可排序

func NewKlineBarList

func NewKlineBarList() (kbl *KlineBarList)

func (*KlineBarList) GetAllKlineBar

func (this *KlineBarList) GetAllKlineBar() (kbs KlineBarSlice)

获取所有K线数据

func (*KlineBarList) GetAllKlineBarSort

func (this *KlineBarList) GetAllKlineBarSort() (kbs KlineBarSlice)

获取所有K线数据,并按时间排序,默认从小到大

func (*KlineBarList) GetKlineBar

func (this *KlineBarList) GetKlineBar(id Timestamp) (kb *KlineBar)

获取单个K线数据

func (*KlineBarList) GetKlineBarLen

func (this *KlineBarList) GetKlineBarLen() (l int64)

获取K线数据的总长度

func (*KlineBarList) GetKlineBars

func (this *KlineBarList) GetKlineBars(fromTime, toTime Timestamp) (kbs KlineBarSlice)

获取多条K线,按开始时间结束时间,fromTime是不包含在内的,但是toTime是包含在内的

func (*KlineBarList) GetLastItems

func (this *KlineBarList) GetLastItems() (kb *KlineBar)

获取最后一条K线数据

func (*KlineBarList) GetTodayKlineBars

func (this *KlineBarList) GetTodayKlineBars() (kbs KlineBarSlice)

获取多条K线,按开始时间结束时间,fromTime是不包含在内的,但是toTime是包含在内的

func (*KlineBarList) SetKlineBar

func (this *KlineBarList) SetKlineBar(val *KlineBar)

设置单条数据到缓存

type KlineBarSlice

type KlineBarSlice []*KlineBar

K线Slice数据列表

func (*KlineBarSlice) Rolling

func (this *KlineBarSlice) Rolling(frequency Timestamp) (rkb KlineBarSlice)

滚动一下,返回指定频率的K线...把基础1分钟频率的K线转换为指定频率的K线

type KlineData

type KlineData struct {
	sync.Mutex
	// contains filtered or unexported fields
}

K线数据类型

func NewKlineData

func NewKlineData() (kd *KlineData)

func (*KlineData) CacheAddToFile

func (this *KlineData) CacheAddToFile(di DataIndex) error

从缓存写到文件,追加最新数据

func (*KlineData) GetFirstItems

func (this *KlineData) GetFirstItems(di DataIndex) (kb *KlineBar)

获取K线缓存的第一条数据

func (*KlineData) GetKineBarSlice

func (this *KlineData) GetKineBarSlice(di DataIndex, st, et, kf int64) (kbs KlineBarSlice)

获取指定频率的KlineBar的Slice数据

参数1: di 数据索引
参数2: st 开始时间戳
参数3: et 结束时间戳
参数4: kf K线频率,最小60秒,1分钟,5分钟,30分钟...

func (*KlineData) GetKlineBarByID

func (this *KlineData) GetKlineBarByID(di DataIndex, id int64) (kb *KlineBar)

获取指定ID的KlineBar

参数1: di 数据索引
参数2: id KlineBar的ID(时间戳)
参数4: kf K线频率,最小60秒,1分钟,5分钟,30分钟...

func (*KlineData) GetKlineData

func (this *KlineData) GetKlineData(di DataIndex) (kbl *KlineBarList)

获取KlineData数据

func (*KlineData) GetKlineDataCount

func (this *KlineData) GetKlineDataCount(di DataIndex) int64

获取KlineData的条数

func (*KlineData) GetLastItems

func (this *KlineData) GetLastItems(di DataIndex) (kb *KlineBar)

获取K线缓存的最后(最新)一条数据

func (*KlineData) ReadFileContent

func (this *KlineData) ReadFileContent(di DataIndex) error

获取K线缓存文件内容,通过DataIndex

func (*KlineData) SetKlineBar

func (this *KlineData) SetKlineBar(di DataIndex, val *KlineBar)

设置KlineBar的数据

func (*KlineData) SetKlineBarList

func (this *KlineData) SetKlineBarList(di DataIndex, val *KlineBarList)

设置KlineBarList的缓存数据

type KlineRealTimeData

type KlineRealTimeData struct {
	Ts    Timestamp
	Items map[Platform]map[Symbol]KlineBar
}

K线实时数据类型

type KlineToFileCache

type KlineToFileCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

KlineBarToFile 把Slice类型的KlineBar转换为日期为索引的Map类型

func NewKlineToFileCache

func NewKlineToFileCache() (kbl *KlineToFileCache)

func (*KlineToFileCache) GetKlineBarList

func (this *KlineToFileCache) GetKlineBarList(dt DateTimeDay) (kbl *KlineBarList)

获取数据

func (*KlineToFileCache) SetKlineBar

func (this *KlineToFileCache) SetKlineBar(dt DateTimeDay, bar *KlineBar)

添加数据

func (*KlineToFileCache) WriteFileCache

func (this *KlineToFileCache) WriteFileCache(di DataIndex, cachePath string) (err error)

type OrderData

type OrderData struct {
	ID int64 // 时间(K线棒id)
}

订单数据类型

type OrderService

type OrderService struct {
}

func NewOrderService

func NewOrderService() (os *OrderService, err error)

创建Order服务

func (*OrderService) BuildOrder

func (this *OrderService) BuildOrder(di DataIndex, ty string, price, amount float64)

ty 类型,buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖 price 价格 amount 买卖数量

type Platform

type Platform = string

type RealTimeDataParam

type RealTimeDataParam struct {
	Platforms Platform
	Symbols   []Symbol
}

type SecretKey

type SecretKey = string

type SupplySymbol

type SupplySymbol map[Platform][]SymbolInfo

type Symbol

type Symbol = string

type SymbolInfo

type SymbolInfo struct {
	Symbol        string // 交易对名称
	BaseCurrency  string // 交易基础币名称
	QuoteCurrency string // 计价币名称

	MinSize float64 // 最小交易数量
	MaxSize float64 // 最大交易数量

	PricePrecision  uint // 基础币种报价精度
	AmountPrecision uint // 计价币种报价精度

	MinOrderValue float64 // 最小订单金额=最小交易额*最小交易量
	MaxOrderValue float64 // 最大下单金额=最大交易额*最大交易量

	TickSize uint // 交易价格精度(小数点后位数,默认为10位)
}

交易对

type Timestamp

type Timestamp = int64

type TradeData

type TradeData struct {
	sync.Mutex
	// contains filtered or unexported fields
}

type TradeInfo

type TradeInfo struct {
	ID     int64   // 成交id(唯一)
	Ts     int64   // 成交时间(毫秒)
	Side   string  // 交易方向 buy,shell
	Price  float64 // 成交价格
	Amount float64 // 成交数量
}

成交信息类型

type TradeRealTimeData

type TradeRealTimeData struct {
	Ts    Timestamp
	Items map[Platform]map[Symbol]TradeInfo
}

type TradeRealTimeDataParam

type TradeRealTimeDataParam struct {
	Platforms Platform
	Symbols   []Symbol
}

type UpdataFileCacheParam

type UpdataFileCacheParam struct {
	Platform Platform
	Symbol   Symbol
}

type Urls

type Urls struct {
	Http string // RestAPI 访问地址
	WS   string // WebSocket 访问地址
}

type UserSecret

type UserSecret map[Platform]map[ApiKey]struct {

	// 人类能看懂的名字
	Name string

	// 私有接口的ApiKey
	ApiKey ApiKey

	// 私有接口的ApiKey
	SecretKey SecretKey

	// 是否启用
	Enable bool
}

托管账户秘钥

Jump to

Keyboard shortcuts

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