order: Add Side type MarshalJSON method (#1726)

* Add side MarshalJSON

* glorious: nits

* more removal

* Update exchanges/order/order_test.go

Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>

---------

Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io>
Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
Ryan O'Hara-Reid
2024-11-26 11:19:13 +11:00
committed by GitHub
parent d8de945ee6
commit 3c73d973f6
2 changed files with 15 additions and 0 deletions

View File

@@ -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

View File

@@ -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) {