Skip to content

Commit

Permalink
Huobi: symbol, var assignment and UpdateAccountInfo fixes (#793)
Browse files Browse the repository at this point in the history
* huobi futures: GetSwapAccountInfo argument is optional

* huobi futures: fetch main account data as well

* huobi futures: shut linter up

Old warnings not introduced in this scope.
  • Loading branch information
lrascao authored Oct 7, 2021
1 parent fe4221d commit 5208d21
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
10 changes: 6 additions & 4 deletions exchanges/huobi/huobi_cfutures.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,13 @@ func (h *HUOBI) GetBasisData(ctx context.Context, code currency.Pair, period, ba
func (h *HUOBI) GetSwapAccountInfo(ctx context.Context, code currency.Pair) (SwapAccountInformation, error) {
var resp SwapAccountInformation
req := make(map[string]interface{})
codeValue, err := h.FormatSymbol(code, asset.CoinMarginedFutures)
if err != nil {
return resp, err
if !code.IsEmpty() {
codeValue, err := h.FormatSymbol(code, asset.CoinMarginedFutures)
if err != nil {
return resp, err
}
req["contract_code"] = codeValue
}
req["contract_code"] = codeValue
return resp, h.FuturesAuthenticatedHTTPRequest(ctx, exchange.RestFutures, http.MethodPost, huobiSwapAccInfo, nil, req, &resp)
}

Expand Down
4 changes: 2 additions & 2 deletions exchanges/huobi/huobi_futures.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,9 +903,9 @@ func (h *HUOBI) FGetOrderHistory(ctx context.Context, contractCode currency.Pair
return resp, fmt.Errorf("invalid reqType")
}
req["type"] = rType
var reqStatus string = "0"
reqStatus := "0"
if len(status) > 0 {
var firstTime bool = true
firstTime := true
for x := range status {
sType, ok := validOrderStatus[status[x]]
if !ok {
Expand Down
42 changes: 42 additions & 0 deletions exchanges/huobi/huobi_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,27 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
}

case asset.CoinMarginedFutures:
// fetch swap account info
acctInfo, err := h.GetSwapAccountInfo(ctx, currency.Pair{})
if err != nil {
return info, err
}

var mainAcctBalances []account.Balance
for x := range acctInfo.Data {
mainAcctBalances = append(mainAcctBalances, account.Balance{
CurrencyName: currency.NewCode(acctInfo.Data[x].Symbol),
TotalValue: acctInfo.Data[x].MarginBalance,
Hold: acctInfo.Data[x].MarginFrozen,
})
}

info.Accounts = append(info.Accounts, account.SubAccount{
Currencies: mainAcctBalances,
AssetType: assetType,
})

// fetch subaccounts data
subAccsData, err := h.GetSwapAllSubAccAssets(ctx, currency.Pair{})
if err != nil {
return info, err
Expand All @@ -727,6 +748,27 @@ func (h *HUOBI) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (ac
}
acc.Currencies = currencyDetails
case asset.Futures:
// fetch main account data
mainAcctData, err := h.FGetAccountInfo(ctx, currency.Code{})
if err != nil {
return info, err
}

var mainAcctBalances []account.Balance
for x := range mainAcctData.AccData {
mainAcctBalances = append(mainAcctBalances, account.Balance{
CurrencyName: currency.NewCode(mainAcctData.AccData[x].Symbol),
TotalValue: mainAcctData.AccData[x].MarginBalance,
Hold: mainAcctData.AccData[x].MarginFrozen,
})
}

info.Accounts = append(info.Accounts, account.SubAccount{
Currencies: mainAcctBalances,
AssetType: assetType,
})

// fetch subaccounts data
subAccsData, err := h.FGetAllSubAccountAssets(ctx, currency.Code{})
if err != nil {
return info, err
Expand Down

0 comments on commit 5208d21

Please sign in to comment.