github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/status/liquidations.go (about) 1 package status 2 3 import ( 4 "fmt" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/convert" 7 ) 8 9 type LiquidationsSnapshot struct { 10 Snapshot []*Liquidation 11 } 12 13 type Liquidation struct { 14 Symbol string 15 PositionID int64 16 MTS int64 17 Amount float64 18 BasePrice float64 19 IsMatch int 20 IsMarketSold int 21 PriceAcquired float64 22 } 23 24 func LiqFromRaw(raw []interface{}) (*Liquidation, error) { 25 if len(raw) < 12 { 26 return nil, fmt.Errorf("data slice too short for liquidation status: %#v", raw) 27 } 28 29 return &Liquidation{ 30 PositionID: convert.I64ValOrZero(raw[1]), 31 MTS: convert.I64ValOrZero(raw[2]), 32 Symbol: convert.SValOrEmpty(raw[4]), 33 Amount: convert.F64ValOrZero(raw[5]), 34 BasePrice: convert.F64ValOrZero(raw[6]), 35 IsMatch: convert.ToInt(raw[8]), 36 IsMarketSold: convert.ToInt(raw[9]), 37 PriceAcquired: convert.F64ValOrZero(raw[11]), 38 }, nil 39 } 40 41 func LiqSnapshotFromRaw(raw [][]interface{}) (*LiquidationsSnapshot, error) { 42 if len(raw) == 0 { 43 return nil, fmt.Errorf("empty data slice") 44 } 45 46 snapshot := make([]*Liquidation, len(raw)) 47 for i, r := range raw { 48 l, err := LiqFromRaw(r) 49 if err != nil { 50 return nil, err 51 } 52 snapshot[i] = l 53 } 54 return &LiquidationsSnapshot{Snapshot: snapshot}, nil 55 }