github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/trades/trades.go (about) 1 package trades 2 3 import ( 4 "errors" 5 "strings" 6 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 8 ) 9 10 // FromWSRaw acts as a relay for public trades channel to abstract complexity from msg. 11 // Data arrives under "trades" channel and then splits into sub types: 12 // ["tu", "te", "ftu", "fte"] and can also be a snapshot. 13 func FromWSRaw(pair string, raw, data []interface{}) (interface{}, error) { 14 if len(data) == 0 { 15 return nil, errors.New("empty data slice for trade") 16 } 17 18 _, isSnapshot := data[0].([]interface{}) 19 hasType := len(raw) == 3 20 21 if isSnapshot && strings.HasPrefix(pair, "f") { 22 return FTSnapshotFromRaw(pair, convert.ToInterfaceArray(data)) 23 } 24 25 if isSnapshot && strings.HasPrefix(pair, "t") { 26 return TSnapshotFromRaw(pair, convert.ToInterfaceArray(data)) 27 } 28 29 if hasType { 30 opType, _ := raw[1].(string) 31 32 switch opType { 33 case "tu": 34 return TEUFromRaw(pair, data) 35 case "te": 36 return TEFromRaw(pair, data) 37 case "fte": 38 return FTEFromRaw(pair, data) 39 case "ftu": 40 return FTEUFromRaw(pair, data) 41 } 42 } 43 44 return TFromRaw(pair, data) 45 }