github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/tradeexecution/tradeexecution.go (about)

     1  package tradeexecution
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/convert"
     7  )
     8  
     9  // TradeExecution represents the first message receievd for a trade on the private data feed.
    10  type TradeExecution struct {
    11  	ID         int64
    12  	Pair       string
    13  	MTS        int64
    14  	OrderID    int64
    15  	ExecAmount float64
    16  	ExecPrice  float64
    17  	OrderType  string
    18  	OrderPrice float64
    19  	Maker      int
    20  }
    21  
    22  func FromRaw(raw []interface{}) (te *TradeExecution, err error) {
    23  	if len(raw) < 6 {
    24  		return te, fmt.Errorf("data slice too short for trade execution: %#v", raw)
    25  	}
    26  
    27  	// trade executions sometimes omit order type, price, and maker flag
    28  	te = &TradeExecution{
    29  		ID:         convert.I64ValOrZero(raw[0]),
    30  		Pair:       convert.SValOrEmpty(raw[1]),
    31  		MTS:        convert.I64ValOrZero(raw[2]),
    32  		OrderID:    convert.I64ValOrZero(raw[3]),
    33  		ExecAmount: convert.F64ValOrZero(raw[4]),
    34  		ExecPrice:  convert.F64ValOrZero(raw[5]),
    35  	}
    36  
    37  	if len(raw) >= 9 {
    38  		te.OrderType = convert.SValOrEmpty(raw[6])
    39  		te.OrderPrice = convert.F64ValOrZero(raw[7])
    40  		te.Maker = convert.ToInt(raw[8])
    41  	}
    42  
    43  	return
    44  }