diff --git a/exchanges/order/order_test.go b/exchanges/order/order_test.go index 2f2b8190..b01d62ae 100644 --- a/exchanges/order/order_test.go +++ b/exchanges/order/order_test.go @@ -2123,6 +2123,16 @@ func TestSideUnmarshal(t *testing.T) { assert.ErrorAs(t, s.UnmarshalJSON([]byte(`14`)), &jErr, "non-string valid json is rejected") } +func TestSideMarshalJSON(t *testing.T) { + t.Parallel() + b, err := Buy.MarshalJSON() + assert.NoError(t, err) + assert.Equal(t, `"BUY"`, string(b)) + b, err = UnknownSide.MarshalJSON() + assert.NoError(t, err) + assert.Equal(t, `"UNKNOWN"`, string(b)) +} + func TestGetTradeAmount(t *testing.T) { t.Parallel() var s *Submit diff --git a/exchanges/order/orders.go b/exchanges/order/orders.go index 5f92b802..ad09ba5d 100644 --- a/exchanges/order/orders.go +++ b/exchanges/order/orders.go @@ -1115,6 +1115,11 @@ func (s *Side) UnmarshalJSON(data []byte) (err error) { return } +// MarshalJSON returns the JSON-encoded order side +func (s Side) MarshalJSON() ([]byte, error) { + return []byte(`"` + s.String() + `"`), nil +} + // StringToOrderType for converting case insensitive order type // and returning a real Type func StringToOrderType(oType string) (Type, error) {