You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
2.0 KiB

package types
import (
"sig-pub/api/pb"
"github.com/govalues/decimal"
)
// 时序数据 k线
type Kline struct {
// InstId string `json:"instId"` // 交易产品id
// Tid int64 `json:"tid"` // ts除interval
// Exchange string `json:"exchange"` // 交易所
Interval Interval `json:"interval"` // 周期
Ts int64 `json:"ts"` // k线时间戳ms
Open decimal.Decimal `json:"open"` // 开盘
High decimal.Decimal `json:"high"` // 最高
Low decimal.Decimal `json:"low"` // 最低
Close decimal.Decimal `json:"close"` // 收盘
Vol decimal.Decimal `json:"vol"` // 交易量 如果是币币,数值为交易货币的数量。
VolQuote decimal.Decimal `json:"volQuote"` // 交易额 (交易量,以计价货币为单位)
Confirm bool `json:"confirm"` // k线是否完结
}
// okx.CandleData{[]string{"1746842757000", "0.20545", "0.20545", "0.2054", "0.2054", "7.57", "7570", "1555.2542", "1"}}
func (k *Kline) ParsePBKline(exchange pb.Exchange, kline *pb.Kline) {
// k.Exchange = exchange.String()
k.Interval = Interval(kline.Interval)
k.Ts = kline.Ts
k.Open = decimal.MustParse(kline.Open)
k.High = decimal.MustParse(kline.High)
k.Low = decimal.MustParse(kline.Low)
k.Close = decimal.MustParse(kline.Close)
k.Vol = decimal.MustParse(kline.Vol)
k.VolQuote = decimal.MustParse(kline.VolQuote)
k.Confirm = kline.Confirm
}
func (k *Kline) ToPBKline() (kline *pb.Kline) {
kline = &pb.Kline{
Ts: k.Ts,
Interval: string(k.Interval),
Open: k.Open.String(),
High: k.High.String(),
Low: k.Low.String(),
Close: k.Close.String(),
Vol: k.Vol.String(),
VolQuote: k.VolQuote.String(),
Confirm: k.Confirm,
}
return
}
// ChannelKline k线订阅消息
type ChannelKline struct {
ExgInstId string `json:"instId"` // 交易所交易产品id,如 BTC_USDT_SWAP
Exchange Exchange `json:"exchange"` // 交易所
Klines []*Kline `json:"klines"`
}