Skip to content

Commit

Permalink
add new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
“VincentCai” committed May 22, 2024
1 parent b75a96a commit a7d4dbb
Show file tree
Hide file tree
Showing 31 changed files with 184 additions and 43 deletions.
63 changes: 63 additions & 0 deletions pkg/client/accountclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,66 @@ func (p *AccountClient) Transfer(request account.TransferRequest) (*account.Tran

return nil, errors.New(postResp)
}

// 用户抵扣信息查询
func (p *AccountClient) GetUserInfo() (*account.GetUserInfoResponse, error) {
url := p.privateUrlBuilder.Build("GET", "/v1/account/switch/user/info", nil)
getResp, getErr := internal.HttpGet(url)
if getErr != nil {
return nil, getErr
}
result := account.GetUserInfoResponse{}
jsonErr := json.Unmarshal([]byte(getResp), &result)
if jsonErr != nil {
return nil, jsonErr
}
if result.Code == 200 {
return &result, nil
}

return nil, errors.New(getResp)
}

// 可抵扣币种查询信息
func (p *AccountClient) GetOverviewInfo() (*account.GetOverviewInfoResponse, error) {
url := p.privateUrlBuilder.Build("GET", "/v1/account/overview/info", nil)
getResp, getErr := internal.HttpGet(url)
if getErr != nil {
return nil, getErr
}
result := account.GetOverviewInfoResponse{}
jsonErr := json.Unmarshal([]byte(getResp), &result)
if jsonErr != nil {
return nil, jsonErr
}
if result.Code == 200 {
return &result, nil
}

return nil, errors.New(getResp)
}

// 设置现货/杠杆抵扣手续费方式
func (p *AccountClient) FeeSwitch(request account.FeeSwitchRequest) (*account.FeeSwitchResponse, error) {
postBody, jsonErr := model.ToJson(request)
if jsonErr != nil {
return nil, jsonErr
}

url := p.privateUrlBuilder.Build("POST", "/v1/account/fee/switch", nil)
postResp, postErr := internal.HttpPost(url, postBody)
if postErr != nil {
return nil, postErr
}

result := account.FeeSwitchResponse{}
jsonErr = json.Unmarshal([]byte(postResp), &result)
if jsonErr != nil {
return nil, jsonErr
}
if result.Code == 200 {
return &result, nil
}

return nil, errors.New(postResp)
}
25 changes: 25 additions & 0 deletions pkg/client/subuserclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,28 @@ func (p *SubUserClient) ApiKeyDeletion(request subuser.ApiKeyDeletionRequest) (*

return nil, errors.New(postResp)
}

// 用户主动授信
func (p *SubUserClient) ActiveCredit(request subuser.ActiveCreditRequest) (bool, error) {
postBody, jsonErr := model.ToJson(request)
if jsonErr != nil {
return false, jsonErr
}

url := p.privateUrlBuilder.Build("POST", "/v1/trust/user/active/credit", nil)
postResp, postErr := internal.HttpPost(url, postBody)
if postErr != nil {
return false, postErr
}

result := subuser.ActiveCreditResponse{}
jsonErr = json.Unmarshal([]byte(postResp), &result)
if jsonErr != nil {
return false, jsonErr
}
if result.Status == "ok" {
return true, nil
}

return false, errors.New(postResp)
}
6 changes: 6 additions & 0 deletions pkg/model/account/feeswitchrequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package account

type FeeSwitchRequest struct {
SwitchType int `json:"switchType"`
DeductionCurrency string `json:"deductionCurrency"`
}
9 changes: 9 additions & 0 deletions pkg/model/account/feeswitchresponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package account

type FeeSwitchResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Success bool `json:"success"`
Data *struct {
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/account/getaccountassetvaluationresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ type GetAccountAssetValuationResponse struct {
Data *struct {
Balance string `json:"balance"`
Timestamp int64 `json:"timestamp"`
}
} `json:"data"`
}
10 changes: 10 additions & 0 deletions pkg/model/account/getoverviewinforesponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package account

type GetOverviewInfoResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Success bool `json:"success"`
Data *struct {
Currency string `json:"currency"`
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/account/getpointbalanceresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type GetPointBalanceResponse struct {
ExpiryDate int64 `json:"expiryDate"`
RemainAmount string `json:"remainAmt"`
}
}
} `json:"data"`
}
12 changes: 12 additions & 0 deletions pkg/model/account/getuserinforesponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package account

type GetUserInfoResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Success bool `json:"success"`
Data *struct {
PointSwitch int `json:"pointSwitch"`
CurrencySwitch int `json:"currencySwitch"`
DeductionCurrency string `json:"deductionCurrency"`
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/account/subscribeaccountv2response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ type SubscribeAccountV2Response struct {
ChangeType string `json:"changeType"`
AccountType string `json:"accountType"`
ChangeTime int64 `json:"changeTime"`
}
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/account/transferpointresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ type TransferPointResponse struct {
Data *struct {
TransactId string `json:"transactId"`
TransactTime int64 `json:"transactTime"`
}
} `json:"data"`
}
10 changes: 5 additions & 5 deletions pkg/model/algoorder/cancelordersresponse.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package algoorder

type CancelOrdersResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Accepted []string `json:"accepted"`
Accepted []string `json:"accepted"`
Rejected []string `json:"rejected"`
}
}
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/algoorder/gethistoryordersresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ type GetHistoryOrdersResponse struct {
OrderStatus string `json:"orderStatus"`
ErrCode int `json:"errCode"`
ErrMessage string `json:"errMessage"`
}
} `json:"data"`
NextId int64 `json:"nextId"`
}
8 changes: 4 additions & 4 deletions pkg/model/algoorder/getopenordersresponse.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package algoorder

type GetOpenOrdersResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Code int `json:"code"`
Message string `json:"message"`
Data []struct {
AccountId int `json:"accountId"`
Source string `json:"source"`
Expand All @@ -19,6 +19,6 @@ type GetOpenOrdersResponse struct {
OrderOrigTime int64 `json:"orderOrigTime"`
LastActTime int64 `json:"lastActTime"`
OrderStatus string `json:"orderStatus"`
}
NextId int64 `json:"nextId"`
} `json:"data"`
NextId int64 `json:"nextId"`
}
2 changes: 1 addition & 1 deletion pkg/model/algoorder/getspecificorderresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ type GetSpecificOrderResponse struct {
OrderStatus string `json:"orderStatus"`
ErrCode int `json:"errCode"`
ErrMessage string `json:"errMessage"`
}
} `json:"data"`
}
8 changes: 4 additions & 4 deletions pkg/model/algoorder/placeorderresponse.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package algoorder

type PlaceOrderResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Code int `json:"code"`
Message string `json:"message"`
Data *struct {
ClientOrderId string `json:"clientOrderId"`
}
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/margin/crossmarginaccountsbalanceresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ type CrossMarginAccountsBalance struct {
Currency string `json:"currency"`
Type string `json:"type"`
Balance string `json:"balance"`
}
} `json:"list"`
}
2 changes: 1 addition & 1 deletion pkg/model/margin/getisolatedmarginloaninforesponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ type IsolatedMarginLoanInfo struct {
MaxLoanAmt string `json:"max-loan-amt"`
LoanableAmt string `json:"loanable-amt"`
ActualRate string `json:"actual-rate"`
}
} `json:"currencies"`
}
2 changes: 1 addition & 1 deletion pkg/model/order/cancelordersbycriteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ type CancelOrdersByCriteriaResponse struct {
SuccessCount int `json:"success-count"`
FailedCount int `json:"failed-count"`
NextId int `json:"next-id"`
}
} `json:"data"`
}
4 changes: 2 additions & 2 deletions pkg/model/order/cancelordersbyidsresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ type CancelOrdersByIdsResponse struct {
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
OrderState int `json:"order-state"`
}
}
} `json:"failed"`
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/order/gethistoryordersresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type GetHistoryOrdersResponse struct {
Batch string `json:"batch"`
StopPrice string `json:"stop-price"`
Operator string `json:"operator"`
}
} `json:"data"`
}
4 changes: 2 additions & 2 deletions pkg/model/order/getmatchresultsresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ type GetMatchResultsResponse struct {
Type string `json:"type"`
FilledAmount string `json:"filled-amount"`
FilledFees string `json:"filled-fees"`
FeeCurrency string `json:"fee-currency"`
FeeCurrency string `json:"fee-currency"`
Source string `json:"source"`
Role string `json:"role"`
FilledPoints string `json:"filled-points"`
FeeDeductCurrency string `json:"fee-deduct-currency"`
FeeDeductState string `json:"fee-deduct-state"`
}
} `json:"data"`
}
8 changes: 4 additions & 4 deletions pkg/model/order/getopenordersresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package order
import "github.com/shopspring/decimal"

type GetOpenOrdersResponse struct {
Status string `json:"status"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
Data []OpenOrder
Status string `json:"status"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
Data []OpenOrder `json:"data"`
}

type OpenOrder struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/order/getorderresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ type GetOrderResponse struct {
FinishedAt string `json:"finished-at"`
StopPrice string `json:"stop-price"`
Operator string `json:"operator"`
}
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/order/gettransactfeerateresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type GetTransactFeeRateResponse struct {
TakerFeeRate string `json:"takerFeeRate"`
ActualMakerRate string `json:"actualMakerRate"`
ActualTakerRate string `json:"actualTakerRate"`
}
} `json:"data"`
}
8 changes: 4 additions & 4 deletions pkg/model/order/placeordersresponse.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package order

type PlaceOrdersResponse struct {
Status string `json:"status"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
Data []PlaceOrderResult
Status string `json:"status"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
Data []PlaceOrderResult `json:"data"`
}

type PlaceOrderResult struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/order/subscribeorderv2response.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ type SubscribeOrderV2Response struct {
LastActTime int64 `json:"lastActTime"`
ErrorCode int `json:"errCode"`
ErrorMessage string `json:"errMessage"`
}
}
} `json:"data"`
}
4 changes: 2 additions & 2 deletions pkg/model/order/subscribetradeclearresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ type SubscribeTradeClearResponse struct {
Operator string `json:"operator"`
OrderCreateTime int64 `json:"orderCreateTime"`
OrderStatus string `json:"orderStatus"`
}
}
} `json:"data"`
}
2 changes: 1 addition & 1 deletion pkg/model/stablecoin/exchangestablecoinresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ExchangeStableCoinResponse struct {
ExchangeAmount string `json:"exchange-amount"`
ExchangeFee string `json:"exchange-fee"`
Time string `json:"time"`
}
} `json:"data"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
}
2 changes: 1 addition & 1 deletion pkg/model/stablecoin/getexchangerateresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type GetExchangeRateResponse struct {
ExchangeFee string `json:"exchangeFee"`
QuoteId string `json:"quoteId"`
Expiration string `json:"expiration"`
}
} `json:"data"`
ErrorCode string `json:"err-code"`
ErrorMessage string `json:"err-msg"`
}
9 changes: 9 additions & 0 deletions pkg/model/subuser/activecreditrequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package subuser

type ActiveCreditRequest struct {
TransactionId int64 `json:"transactionId"`
Currency string `json:"currency"`
Amount float64 `json:"amount"`
AccountId int64 `json:"accountId"`
UserId int64 `json:"userId"`
}
7 changes: 7 additions & 0 deletions pkg/model/subuser/activecreditresponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package subuser

type ActiveCreditResponse struct {
Status string `json:"status"`
Ts int64 `json:"ts"`
Data bool `json:"data"`
}

0 comments on commit a7d4dbb

Please sign in to comment.