-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add TransferToSubAccountService * fix type * remove test method Co-authored-by: adshao <tjusgj@gmail.com>
- Loading branch information
1 parent
06aa4e0
commit db2e228
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package binance | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
// TransferToSubAccountService transfer to subaccount | ||
type TransferToSubAccountService struct { | ||
c *Client | ||
toEmail string | ||
asset string | ||
amount string | ||
} | ||
|
||
// ToEmail set toEmail | ||
func (s *TransferToSubAccountService) ToEmail(toEmail string) *TransferToSubAccountService { | ||
s.toEmail = toEmail | ||
return s | ||
} | ||
|
||
// Asset set asset | ||
func (s *TransferToSubAccountService) Asset(asset string) *TransferToSubAccountService { | ||
s.asset = asset | ||
return s | ||
} | ||
|
||
// Amount set amount | ||
func (s *TransferToSubAccountService) Amount(amount string) *TransferToSubAccountService { | ||
s.amount = amount | ||
return s | ||
} | ||
|
||
func (s *TransferToSubAccountService) transferToSubaccount(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) { | ||
r := &request{ | ||
method: "POST", | ||
endpoint: endpoint, | ||
secType: secTypeSigned, | ||
} | ||
m := params{ | ||
"toEmail": s.toEmail, | ||
"asset": s.asset, | ||
"amount": s.amount, | ||
} | ||
r.setParams(m) | ||
data, err = s.c.callAPI(ctx, r, opts...) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
return data, nil | ||
} | ||
|
||
// Do send request | ||
func (s *TransferToSubAccountService) Do(ctx context.Context, opts ...RequestOption) (res *TransferToSubAccountResponse, err error) { | ||
data, err := s.transferToSubaccount(ctx, "/sapi/v1/sub-account/transfer/subToSub", opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = &TransferToSubAccountResponse{} | ||
err = json.Unmarshal(data, res) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res, nil | ||
} | ||
|
||
// TransferToSubAccountResponse define transfer to subaccount response | ||
type TransferToSubAccountResponse struct { | ||
TxnID int64 `json:"txnId"` | ||
} |