ftx: honour subaccount setting when fetching balances
FTX won't allow us to fetch balances for all accounts when
using a subaccount API key.
@@ -427,12 +427,24 @@ func (f *FTX) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType as
// UpdateAccountInfo retrieves balances for all enabled currencies
func (f *FTX) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.Holdings, error) {
var resp account.Holdings
+
+ var data AllWalletBalances
+ if f.API.Credentials.Subaccount != "" {
+ balances, err := f.GetBalances(ctx)
+ if err != nil {
+ return resp, err
+ }
+ data = make(AllWalletBalances)
+ data[f.API.Credentials.Subaccount] = balances
+ } else {
// Get all wallet balances used so we can transfer between accounts if
// needed.
- data, err := f.GetAllWalletBalances(ctx)
+ var err error
+ data, err = f.GetAllWalletBalances(ctx)
if err != nil {
return resp, err
}
+ }
for subName, balances := range data {
// "main" defines the main account in the sub account list
@@ -449,8 +461,7 @@ func (f *FTX) UpdateAccountInfo(ctx context.Context, a asset.Item) (account.Hold
}
resp.Exchange = f.Name
- err = account.Process(&resp)
- if err != nil {
+ if err := account.Process(&resp); err != nil {
return account.Holdings{}, err
}
