github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/tradeexecutionupdate/tradeexecutionupdate_test.go (about) 1 package tradeexecutionupdate_test 2 3 import ( 4 "testing" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/tradeexecutionupdate" 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestNewTradeExecutionUpdateFromRaw(t *testing.T) { 12 t.Run("invalid arguments", func(t *testing.T) { 13 payload := []interface{}{402088407} 14 15 got, err := tradeexecutionupdate.FromRaw(payload) 16 require.NotNil(t, err) 17 require.Nil(t, got) 18 }) 19 20 t.Run("valid trading arguments", 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 -0.061668, 32 "USD", 33 } 34 35 got, err := tradeexecutionupdate.FromRaw(payload) 36 require.Nil(t, err) 37 38 expected := &tradeexecutionupdate.TradeExecutionUpdate{ 39 ID: 402088407, 40 Pair: "tETHUST", 41 MTS: 1574963975602, 42 OrderID: 34938060782, 43 ExecAmount: -0.2, 44 ExecPrice: 153.57, 45 OrderType: "MARKET", 46 OrderPrice: 0, 47 Maker: -1, 48 Fee: -0.061668, 49 FeeCurrency: "USD", 50 } 51 52 assert.Equal(t, expected, got) 53 }) 54 } 55 56 func TestTradeExecutionUpdateSnapshotFromRaw(t *testing.T) { 57 t.Run("invalid arguments", func(t *testing.T) { 58 payload := []interface{}{} 59 got, err := tradeexecutionupdate.SnapshotFromRaw(payload) 60 require.NotNil(t, err) 61 require.Nil(t, got) 62 }) 63 64 t.Run("partially valid arguments", func(t *testing.T) { 65 payload := []interface{}{ 66 []interface{}{ 67 402088407, 68 "tETHUST", 69 1574963975602, 70 34938060782, 71 -0.2, 72 153.57, 73 "MARKET", 74 0, 75 -1, 76 -0.061668, 77 "USD", 78 }, 79 []interface{}{402088408}, 80 } 81 got, err := tradeexecutionupdate.SnapshotFromRaw(payload) 82 require.NotNil(t, err) 83 require.Nil(t, got) 84 }) 85 86 t.Run("valid arguments", func(t *testing.T) { 87 payload := []interface{}{ 88 []interface{}{ 89 402088407, 90 "tETHUST", 91 1574963975602, 92 34938060782, 93 -0.2, 94 153.57, 95 "MARKET", 96 0, 97 -1, 98 -0.061668, 99 "USD", 100 }, 101 []interface{}{ 102 402088408, 103 "tETHUST", 104 1574963975602, 105 34938060782, 106 -0.2, 107 153.57, 108 "MARKET", 109 0, 110 -1, 111 -0.061668, 112 "USD", 113 }, 114 } 115 116 got, err := tradeexecutionupdate.SnapshotFromRaw(payload) 117 require.Nil(t, err) 118 119 expected := &tradeexecutionupdate.Snapshot{ 120 Snapshot: []*tradeexecutionupdate.TradeExecutionUpdate{ 121 { 122 ID: 402088407, 123 Pair: "tETHUST", 124 MTS: 1574963975602, 125 OrderID: 34938060782, 126 ExecAmount: -0.2, 127 ExecPrice: 153.57, 128 OrderType: "MARKET", 129 OrderPrice: 0, 130 Maker: -1, 131 Fee: -0.061668, 132 FeeCurrency: "USD", 133 }, 134 { 135 ID: 402088408, 136 Pair: "tETHUST", 137 MTS: 1574963975602, 138 OrderID: 34938060782, 139 ExecAmount: -0.2, 140 ExecPrice: 153.57, 141 OrderType: "MARKET", 142 OrderPrice: 0, 143 Maker: -1, 144 Fee: -0.061668, 145 FeeCurrency: "USD", 146 }, 147 }, 148 } 149 150 assert.Equal(t, expected, got) 151 }) 152 }