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

     1  package order_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/order"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestOrderNewRequest(t *testing.T) {
    12  	t.Run("MarshalJSON", func(t *testing.T) {
    13  		our := order.NewRequest{
    14  			CID:    987,
    15  			GID:    876,
    16  			Type:   "EXCHANGE LIMIT",
    17  			Symbol: "tBTCUSD",
    18  			Price:  13,
    19  			Amount: 0.001,
    20  		}
    21  
    22  		got, err := our.MarshalJSON()
    23  		require.Nil(t, err)
    24  
    25  		expected := "[0, \"on\", null, {\"gid\":876,\"cid\":987,\"type\":\"EXCHANGE LIMIT\",\"symbol\":\"tBTCUSD\",\"amount\":\"0.001\",\"price\":\"13\"}]"
    26  		assert.Equal(t, expected, string(got))
    27  	})
    28  
    29  	t.Run("MarshalJSON with extra props", func(t *testing.T) {
    30  		our := order.NewRequest{
    31  			CID:           987,
    32  			GID:           876,
    33  			Type:          "EXCHANGE LIMIT",
    34  			Symbol:        "tBTCUSD",
    35  			Price:         13,
    36  			Amount:        0.001,
    37  			Hidden:        true,
    38  			PostOnly:      true,
    39  			OcoOrder:      true,
    40  			Close:         true,
    41  			AffiliateCode: "abc",
    42  		}
    43  
    44  		got, err := our.MarshalJSON()
    45  		require.Nil(t, err)
    46  
    47  		expected := "[0, \"on\", null, {\"gid\":876,\"cid\":987,\"type\":\"EXCHANGE LIMIT\",\"symbol\":\"tBTCUSD\",\"amount\":\"0.001\",\"price\":\"13\",\"flags\":21056,\"meta\":{\"aff_code\":\"abc\"}}]"
    48  		assert.Equal(t, expected, string(got))
    49  	})
    50  }
    51  
    52  func TestOrderUpdateRequest(t *testing.T) {
    53  	t.Run("MarshalJSON", func(t *testing.T) {
    54  		our := order.UpdateRequest{
    55  			ID:     123456,
    56  			GID:    234567,
    57  			Price:  15.1234,
    58  			Amount: 0.002,
    59  			Hidden: false,
    60  		}
    61  
    62  		got, err := our.MarshalJSON()
    63  		require.Nil(t, err)
    64  
    65  		expected := "[0, \"ou\", null, {\"id\":123456,\"gid\":234567,\"price\":\"15.1234\",\"amount\":\"0.002\"}]"
    66  		assert.Equal(t, expected, string(got))
    67  	})
    68  
    69  	t.Run("MarshalJSON hidden", func(t *testing.T) {
    70  		our := order.UpdateRequest{
    71  			ID:     123456,
    72  			GID:    234567,
    73  			Price:  15.1234,
    74  			Amount: 0.002,
    75  			Hidden: true,
    76  		}
    77  
    78  		got, err := our.MarshalJSON()
    79  		require.Nil(t, err)
    80  
    81  		expected := "[0, \"ou\", null, {\"id\":123456,\"gid\":234567,\"price\":\"15.1234\",\"amount\":\"0.002\",\"flags\":64}]"
    82  		assert.Equal(t, expected, string(got))
    83  	})
    84  
    85  	t.Run("MarshalJSON PostOnly", func(t *testing.T) {
    86  		our := order.UpdateRequest{
    87  			ID:       123456,
    88  			GID:      234567,
    89  			Price:    15.1234,
    90  			Amount:   0.002,
    91  			PostOnly: true,
    92  		}
    93  
    94  		got, err := our.MarshalJSON()
    95  		require.Nil(t, err)
    96  
    97  		expected := "[0, \"ou\", null, {\"id\":123456,\"gid\":234567,\"price\":\"15.1234\",\"amount\":\"0.002\",\"flags\":4096}]"
    98  		assert.Equal(t, expected, string(got))
    99  	})
   100  
   101  	t.Run("MarshalJSON hidden and PostOnly", func(t *testing.T) {
   102  		our := order.UpdateRequest{
   103  			ID:       123456,
   104  			GID:      234567,
   105  			Price:    15.1234,
   106  			Amount:   0.002,
   107  			PostOnly: true,
   108  			Hidden:   true,
   109  		}
   110  
   111  		got, err := our.MarshalJSON()
   112  		require.Nil(t, err)
   113  
   114  		expected := "[0, \"ou\", null, {\"id\":123456,\"gid\":234567,\"price\":\"15.1234\",\"amount\":\"0.002\",\"flags\":4160}]"
   115  		assert.Equal(t, expected, string(got))
   116  	})
   117  }
   118  
   119  func TestOrderCancelRequest(t *testing.T) {
   120  	t.Run("MarshalJSON", func(t *testing.T) {
   121  		ocr := order.CancelRequest{
   122  			ID:      123456,
   123  			CID:     234567,
   124  			CIDDate: "2020-10-10",
   125  		}
   126  		got, err := ocr.MarshalJSON()
   127  
   128  		require.Nil(t, err)
   129  
   130  		expected := "[0, \"oc\", null, {\"id\":123456,\"cid\":234567,\"cid_date\":\"2020-10-10\"}]"
   131  		assert.Equal(t, expected, string(got))
   132  	})
   133  }