adshao / go-binance

A Go SDK for Binance API
MIT License
1.48k stars 664 forks source link

Add MultiAssetModeService for Future #487

Closed jeonghoyeo7 closed 1 year ago

jeonghoyeo7 commented 1 year ago

I found the endpoint /fapi/v1/multiAssetsMargin is not supported yet to get or change the multi-asset mode of a user. I added the related services accordingly in the following files in v2/futures.

jeonghoyeo7 commented 1 year ago

Hello @adshao . Could you take a time to review this PR? Thank you!

adshao commented 1 year ago

Hello @adshao . Could you take a time to review this PR? Thank you!

Thank you for the work, please check my review comments.

jeonghoyeo7 commented 1 year ago

Thank you for your review and comments.

In summary, from https://binance-docs.github.io/apidocs/futures/en/#change-multi-assets-mode-trade, where it is seen as POST /fapi/v1/multiAssetsMargin (HMAC SHA256) has the parameter as below. multiAssetsMargin | STRING | YES | "true": Multi-Assets Mode; "false": Single-Asset Mode

Following the above link, it seems multiAssetsMargin, which will become s.multiAssetsMargin, should be a string.

adshao commented 1 year ago

Thank you for your review and comments.

In summary, from https://binance-docs.github.io/apidocs/futures/en/#change-multi-assets-mode-trade, where it is seen as POST /fapi/v1/multiAssetsMargin (HMAC SHA256) has the parameter as below. multiAssetsMargin | STRING | YES | "true": Multi-Assets Mode; "false": Single-Asset Mode

Following the above link, it seems multiAssetsMargin, which will become s.multiAssetsMargin, should be a string.

setFormParams will automatically convert bool to string before submitting the form.

jeonghoyeo7 commented 1 year ago

Thanks for further explanation.

As I reviewed ChangePositionModeService and DualSide function, ChangePositionModeService has the same case as MultiAssetModeService in that they have the same type parameter of string.

Is setFormParams applied only to MultiAssetModeService or both cases? Then, does the following code need to be modified from

func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeService {
    if dualSide {
        s.dualSide = "true"
    } else {
        s.dualSide = "false"
    }
    return s
}

to

func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeService {
    s.dualSide = dualSide
    return s
}

? But, after reviewing

r.setFormParams(params{
        "dualSidePosition": s.dualSide,
    })
```,
the existing part related to ChangePositionModeService looks correct.

It seems because of the following part,

r.setFormParams(params{ "multiAssetsMargin": s.multiAssetsMargin, })


`s.multiAssetsMargin` seems to be required to be string.
adshao commented 1 year ago

Thanks for further explanation.

As I reviewed ChangePositionModeService and DualSide function, ChangePositionModeService has the same case as MultiAssetModeService in that they have the same type parameter of string.

Is setFormParams applied only to MultiAssetModeService or both cases? Then, does the following code need to be modified from

func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeService {
  if dualSide {
      s.dualSide = "true"
  } else {
      s.dualSide = "false"
  }
  return s
}

to

func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeService {
  s.dualSide = dualSide
  return s
}

? But, after reviewing

r.setFormParams(params{
      "dualSidePosition": s.dualSide,
  })
```,
the existing part related to ChangePositionModeService looks correct.

It seems because of the following part,

r.setFormParams(params{ "multiAssetsMargin": s.multiAssetsMargin, })

`s.multiAssetsMargin` seems to be required to be string.

I think DualSide was added before setFormParams supporting bool directly. You can just verify it in your unit tests.

jeonghoyeo7 commented 1 year ago

@adshao Thanks a lot for your comment. I revised the multiAssetMode related as your suggestion. And also, I further changed ChangePositionModeService for DualSide similarly.

type ChangePositionModeService struct {
    c        *Client
    dualSide bool
}

// Change user's position mode: true - Hedge Mode, false - One-way Mode
func (s *ChangePositionModeService) DualSide(dualSide bool) *ChangePositionModeService {
    s.dualSide = dualSide
    return s
}

I found setFormParams is also applied to this by

r.setFormParams(params{
    "dualSidePosition": s.dualSide,
})

I checked the related unit tests are all passed.