bitget: implement QueryAccount

This commit is contained in:
c9s 2023-08-09 15:30:28 +08:00
parent 40762cad35
commit 4a64701e16
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 34 additions and 3 deletions

View File

@ -1,7 +1,25 @@
package bitget
import "strings"
import (
"strings"
"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)
func toGlobalSymbol(s string) string {
return strings.ToUpper(s)
}
func toGlobalBalance(asset bitgetapi.AccountAsset) types.Balance {
return types.Balance{
Currency: asset.CoinName,
Available: asset.Available,
Locked: asset.Lock.Add(asset.Frozen),
Borrowed: fixedpoint.Zero,
Interest: fixedpoint.Zero,
NetAsset: fixedpoint.Zero,
MaxWithdrawAmount: fixedpoint.Zero,
}
}

View File

@ -116,8 +116,21 @@ func (e *Exchange) QueryKLines(ctx context.Context, symbol string, interval type
}
func (e *Exchange) QueryAccount(ctx context.Context) (*types.Account, error) {
// TODO implement me
panic("implement me")
req := e.client.NewGetAccountAssetsRequest()
resp, err := req.Do(ctx)
if err != nil {
return nil, err
}
bals := types.BalanceMap{}
for _, asset := range resp {
b := toGlobalBalance(asset)
bals[asset.CoinName] = b
}
account := types.NewAccount()
account.UpdateBalances(bals)
return account, nil
}
func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap, error) {