github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/tickerhist/tickerhist.go (about) 1 package tickerhist 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 type TickerHist struct { 10 Symbol string 11 Bid float64 12 // PLACEHOLDER, 13 Ask float64 14 // PLACEHOLDER, 15 // PLACEHOLDER, 16 // PLACEHOLDER, 17 // PLACEHOLDER, 18 // PLACEHOLDER, 19 // PLACEHOLDER, 20 // PLACEHOLDER, 21 // PLACEHOLDER, 22 MTS int64 23 } 24 25 var tickerHistFields = map[string]int{ 26 "Symbol": 0, 27 "Bid": 1, 28 "Ask": 3, 29 "Mts": 12, 30 } 31 32 type Snapshot struct { 33 Snapshot []TickerHist 34 } 35 36 func SnapshotFromRaw(raw [][]interface{}) (ss Snapshot) { 37 if len(raw) == 0 { 38 return 39 } 40 41 snap := make([]TickerHist, 0) 42 for _, r := range raw { 43 th, err := FromRaw(r) 44 if err != nil { 45 continue 46 } 47 snap = append(snap, th) 48 } 49 50 return Snapshot{Snapshot: snap} 51 } 52 53 func FromRaw(raw []interface{}) (t TickerHist, err error) { 54 // to avoid index out of range issue 55 if len(raw) < 13 { 56 err = fmt.Errorf("data slice too short for ticker history, data:%#v", raw) 57 return 58 } 59 60 t = TickerHist{ 61 Symbol: convert.SValOrEmpty(raw[tickerHistFields["Symbol"]]), 62 Bid: convert.F64ValOrZero(raw[tickerHistFields["Bid"]]), 63 Ask: convert.F64ValOrZero(raw[tickerHistFields["Ask"]]), 64 MTS: convert.I64ValOrZero(raw[tickerHistFields["Mts"]]), 65 } 66 return 67 }