Skip to content

Commit

Permalink
ftx: honour subaccount setting when fetching balances (thrasher-corp#780
Browse files Browse the repository at this point in the history
)

FTX won't allow us to fetch balances for all accounts when
using a subaccount API key.
  • Loading branch information
lrascao authored Sep 14, 2021
1 parent 7ab861f commit 068b375
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions exchanges/ftx/ftx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,23 @@ 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
// Get all wallet balances used so we can transfer between accounts if
// needed.
data, err := f.GetAllWalletBalances(ctx)
if err != nil {
return resp, err

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.
var err error
data, err = f.GetAllWalletBalances(ctx)
if err != nil {
return resp, err
}
}

for subName, balances := range data {
Expand All @@ -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
}

Expand Down

0 comments on commit 068b375

Please sign in to comment.