Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json.Marshal order.Submit json.Unmarshal marginType error #1810

Open
dazi005 opened this issue Feb 22, 2025 · 3 comments · May be fixed by #1812
Open

json.Marshal order.Submit json.Unmarshal marginType error #1810

dazi005 opened this issue Feb 22, 2025 · 3 comments · May be fixed by #1812
Labels

Comments

@dazi005
Copy link

dazi005 commented Feb 22, 2025

Image
@gloriousCode
Copy link
Collaborator

Thank you for highlighting this issue!
I can confirm through recreation that the issue is a result of the lack of implementation of func (t Type) MarshalJSON() ([]byte, error) { so that a marshalled margin.Type cannot be unmarshalled as there is a custom Unmarshal that parses via string.

Adding

func (t Type) MarshalJSON() ([]byte, error) {
	return json.Marshal(t.String())
}

would likely fix the issue and I'll look to open a PR for that soon

@dazi005
Copy link
Author

dazi005 commented Feb 24, 2025

func TestMarshalOrder(t *testing.T) {
t.Parallel()
orderSubmit := &Submit{
Exchange: "test",
Pair: currency.NewPair(currency.BTC, currency.LTC),
AssetType: asset.Spot,
Type: Limit,
Amount: 1,
Side: Buy,
MarginType: 1,
}
byteJson, err := json.Marshal(orderSubmit)
if err != nil {
t.Error(err)
}
var orderSubmit2 = &Submit{}
err = json.Unmarshal(byteJson, orderSubmit2)
if err != nil {
t.Error(err)
}
fmt.Println(*orderSubmit2 == *orderSubmit)
}

I added the method in margin.go according to your method, but the test still failed. I don't know why!

@gloriousCode gloriousCode linked a pull request Feb 24, 2025 that will close this issue
13 tasks
@gloriousCode
Copy link
Collaborator

gloriousCode commented Feb 24, 2025

One of the errors I encountered locally was about parsing currencies without delimiters.
cannot create currency pair from BTCUSD cannot ensure pair is in correct format, please use exchange method MatchSymbolWithAvailablePairs
Adding a delimiter resolved it. I am unsure if that is an actual issue though.

I have opened a pull request: #1812 It includes an order submit marshalling test. Feel free to verify

@gloriousCode gloriousCode linked a pull request Feb 24, 2025 that will close this issue
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants