Documentation ¶
Index ¶
- Constants
- Variables
- func Begin(date time.Time, interval time.Duration) time.Time
- func DecBalanceFunc() func(bs []byte) *Balance
- func DecBarFunc() func(bs []byte) Bar
- func DecOrderFunc() func(bs []byte) *Order
- func DecTickFunc() func(bs []byte) Tick
- func EncFunc() func(interface{}) []byte
- func GenTickBarFunc(begin BeginFunc, interval time.Duration) func(Tick) []Bar
- func Limit(side OrderSide, quantity, price float64) func(*Order)
- func Market(side OrderSide, quantity float64) func(*Order)
- type Asset
- type Balance
- type Bar
- type BeginFunc
- type Name
- type Order
- type OrderSide
- type OrderType
- type Tick
Constants ¶
const ( // Special Function LOCAL Name = "LOCAL" // For local generated data // CryptoCurrency BITMEX = "BITMEX" OKEX = "OKEX" HUOBI = "HUOBI" BITFINEX = "BITFINEX" BINANCE = "BINANCE" BYBIT = "BYBIT" // bybit.com COINBASE = "COINBASE" DERIBIT = "DERIBIT" GATEIO = "GATEIO" BITSTAMP = "BITSTAMP" // China CFFEX = "CFFEX" // China Financial Futures Exchange SHFE = "SHFE" // Shanghai Futures Exchange CZCE = "CZCE" // Zhengzhou Commodity Exchange DCE = "DCE" // Dalian Commodity Exchange INE = "INE" // Shanghai International Energy Exchange SSE = "SSE" // Shanghai Stock Exchange SZSE = "SZSE" // Shenzhen Stock Exchange SGE = "SGE" // Shanghai Gold Exchange WXE = "WXE" // Wuxi Steel Exchange CFETS = "CFETS" // China Foreign Exchange Trade System // Global SMART = "SMART" // Smart Router for US stocks NYSE = "NYSE" // New York Stock Exchange NASDAQ = "NASDAQ" // Nasdaq Exchange NYMEX = "NYMEX" // New York Mercantile Exchange COMEX = "COMEX" // a division of theNew York Mercantile Exchange GLOBEX = "GLOBEX" // Globex of CME IDEALPRO = "IDEALPRO" // Forex ECN of Interactive Brokers CME = "CME" // Chicago Mercantile Exchange ICE = "ICE" // Intercontinental Exchange SEHK = "SEHK" // Stock Exchange of Hong Kong HKFE = "HKFE" // Hong Kong Futures Exchange HKSE = "HKSE" // Hong Kong Stock Exchange SGX = "SGX" // Singapore Global Exchange CBOT = "CBT" // Chicago Board of Trade CBOE = "CBOE" // Chicago Board Options Exchange CFE = "CFE" // CBOE Futures Exchange DME = "DME" // Dubai Mercantile Exchange EUREX = "EUX" // Eurex Exchange APEX = "APEX" // Asia Pacific Exchange LME = "LME" // London Metal Exchange BMD = "BMD" // Bursa Malaysia Derivatives TOCOM = "TOCOM" // Tokyo Commodity Exchange EUNX = "EUNX" // Euronext Exchange KRX = "KRX" // Korean Exchange OANDA = "OANDA" // oanda.com )
交易所的代号
Variables ¶
var NilTick = Tick{}
NilTick 只是一个标志
Functions ¶
func Begin ¶
Begin 会根据 time 和 interval 计算 time 所在周期的开始时间 当 interval 的单位
为分钟或秒时,推荐值为 1,2,3,4,5,6,10,12,15,20,30,60 为小时时, 推荐值为 1,2,3,4,6,8,12,24
NOTICE: 由于每个月的时间长度不一致,无法计算月线的起始日期。年线同理。
func DecBalanceFunc ¶
DecBalanceFunc 返回的函数会把序列化成 []byte 的 Balances 值转换回来
func DecOrderFunc ¶
DecOrderFunc 返回的函数会把序列化成 []byte 的 Order 值转换回来
func DecTickFunc ¶
DecTickFunc 返回的函数会把序列化成 []byte 的 Balances 值转换回来
func EncFunc ¶
func EncFunc() func(interface{}) []byte
EncFunc 返回的函数能够将输入转换成 []byte 这些写成闭包的形式,而不是 enc 是为了提高速度 运行压力测试即可知道,提速了 6 倍
func GenTickBarFunc ¶
GenTickBarFunc 会返回一个接收 tick 并生成 bar 的闭包函数 有以下情况需要处理
- 接收第一个 tick, 不返回 bar
- 接收到当前的 interval 的 tick 不返回 bar
- 接收到下一个 interval 的 tick 返回上一个 bar
- 接收到下一个 interval 后面的 interval 的 tick,市场冷清,长时间没有交易 返回多个 bar
Types ¶
type Asset ¶
Asset 代表了交易所中,某一项资产的状态和数目 Asset 是一个值对象 value object
type Bar ¶
type Bar struct { Begin time.Time Interval time.Duration Open, High, Low, Close float64 // Price Volume float64 }
Bar 实现了 k 线的相关方法
type Order ¶
type Order struct { Symbol string AssetName string CapitalName string // if ID is negative value, means unset // ID is time.Now().Unix() ID int64 Side OrderSide Type OrderType // 根据 Type 的不同,以下 3 个属性不是全都必须的 AssetQuantity float64 AssetPrice float64 CapitalQuantity float64 }
Order 是下单的格式
func NewOrder ¶
NewOrder returns a order with default Symbol, Asset, Capital. return value is INCOMPLETE. It need run 'With' method to make a complete copy.
func (*Order) IsLessThan ¶
IsLessThan return true if o < a
type OrderSide ¶
type OrderSide int8
OrderSide is side of order
type OrderType ¶
type OrderType uint8
OrderType is type of order
const ( MARKET OrderType = iota + 1 LIMIT // 以下类型是从 binance 抄过来的 // https://binance-docs.github.io/apidocs/spot/cn/#trade STOPloss STOPlossLIMIT TAKEprofit TAKEprofitLIMIT LIMITmaker )
OrderType is type of order 类型值从 iota+1 也就是 1 开始 是为了避开默认的 0 值 OrderType 也代表了 match 时的优先顺序