exchanges/margin: Fix marshalling issue (#1812)

* Fixes issue with marshalling margin types

* Update exchanges/order/order_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/margin/margin.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update exchanges/order/order_test.go

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>

* Update test name

---------

Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com>
This commit is contained in:
Scott
2025-03-06 15:17:05 +11:00
committed by GitHub
parent 7a6d6cc002
commit 6ee26a7da1
3 changed files with 53 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/encoding/json"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
"github.com/thrasher-corp/gocryptotrader/exchanges/margin"
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
"github.com/thrasher-corp/gocryptotrader/exchanges/validate"
)
@@ -2192,3 +2193,23 @@ func TestTrackingModeString(t *testing.T) {
require.Equal(t, v, k.String())
}
}
func TestMarshalOrder(t *testing.T) {
t.Parallel()
btx := currency.NewBTCUSDT()
btx.Delimiter = "-"
orderSubmit := Submit{
Exchange: "test",
Pair: btx,
AssetType: asset.Spot,
MarginType: margin.Multi,
Side: Buy,
Type: Market,
Amount: 1,
Price: 1000,
}
j, err := json.Marshal(orderSubmit)
require.NoError(t, err, "json.Marshal must not error")
exp := []byte(`{"Exchange":"test","Type":4,"Side":"BUY","Pair":"BTC-USDT","AssetType":"spot","ImmediateOrCancel":false,"FillOrKill":false,"PostOnly":false,"ReduceOnly":false,"Leverage":0,"Price":1000,"Amount":1,"QuoteAmount":0,"TriggerPrice":0,"TriggerPriceType":0,"ClientID":"","ClientOrderID":"","AutoBorrow":false,"MarginType":"multi","RetrieveFees":false,"RetrieveFeeDelay":0,"RiskManagementModes":{"Mode":"","TakeProfit":{"Enabled":false,"TriggerPriceType":0,"Price":0,"LimitPrice":0,"OrderType":0},"StopLoss":{"Enabled":false,"TriggerPriceType":0,"Price":0,"LimitPrice":0,"OrderType":0},"StopEntry":{"Enabled":false,"TriggerPriceType":0,"Price":0,"LimitPrice":0,"OrderType":0}},"Hidden":false,"Iceberg":false,"TrackingMode":0,"TrackingValue":0}`)
assert.Equal(t, exp, j)
}