github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/tradeexecution/tradeexecution_test.go (about) 1 package tradeexecution_test 2 3 import ( 4 "testing" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/tradeexecution" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestNewTradeExecutionFromRaw(t *testing.T) { 12 t.Run("invalid arguments", func(t *testing.T) { 13 payload := []interface{}{402088407} 14 15 got, err := tradeexecution.FromRaw(payload) 16 require.NotNil(t, err) 17 require.Nil(t, got) 18 }) 19 20 t.Run("valid trading arguments #1", func(t *testing.T) { 21 payload := []interface{}{ 22 402088407, 23 "tETHUST", 24 1574963975602, 25 34938060782, 26 -0.2, 27 153.57, 28 "MARKET", 29 0, 30 -1, 31 nil, 32 nil, 33 0, 34 } 35 36 got, err := tradeexecution.FromRaw(payload) 37 require.Nil(t, err) 38 39 expected := &tradeexecution.TradeExecution{ 40 ID: 402088407, 41 Pair: "tETHUST", 42 MTS: 1574963975602, 43 OrderID: 34938060782, 44 ExecAmount: -0.2, 45 ExecPrice: 153.57, 46 OrderType: "MARKET", 47 OrderPrice: 0, 48 Maker: -1, 49 } 50 51 assert.Equal(t, expected, got) 52 }) 53 54 t.Run("valid trading arguments #2", func(t *testing.T) { 55 payload := []interface{}{ 56 402088407, 57 "tETHUST", 58 1574963975602, 59 34938060782, 60 -0.2, 61 153.57, 62 } 63 64 got, err := tradeexecution.FromRaw(payload) 65 require.Nil(t, err) 66 67 expected := &tradeexecution.TradeExecution{ 68 ID: 402088407, 69 Pair: "tETHUST", 70 MTS: 1574963975602, 71 OrderID: 34938060782, 72 ExecAmount: -0.2, 73 ExecPrice: 153.57, 74 } 75 76 assert.Equal(t, expected, got) 77 }) 78 }