Skip to content

Commit

Permalink
pkg/exchange: use v2 get account asset api
Browse files Browse the repository at this point in the history
  • Loading branch information
bailantaotao committed Jan 3, 2024
1 parent c5decf9 commit 30164ac
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type GetAccountAssetsRequest struct {
client requestgen.AuthenticatedAPIClient

coin *string `param:"symbol,query"`
assetType AssetType `param:"limit,query"`
assetType AssetType `param:"assetType,query"`
}

func (c *Client) NewGetAccountAssetsRequest() *GetAccountAssetsRequest {
Expand Down
7 changes: 3 additions & 4 deletions pkg/exchange/bitget/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import (
"strconv"
"time"

"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
)

func toGlobalBalance(asset bitgetapi.AccountAsset) types.Balance {
func toGlobalBalance(asset v2.AccountAsset) types.Balance {
return types.Balance{
Currency: asset.CoinName,
Currency: asset.Coin,
Available: asset.Available,
Locked: asset.Lock.Add(asset.Frozen),
Locked: asset.Locked.Add(asset.Frozen),
Borrowed: fixedpoint.Zero,
Interest: fixedpoint.Zero,
NetAsset: fixedpoint.Zero,
Expand Down
15 changes: 7 additions & 8 deletions pkg/exchange/bitget/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/stretchr/testify/assert"

"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types"
Expand All @@ -23,13 +22,13 @@ func Test_toGlobalBalance(t *testing.T) {
// "lock":"0",
// "uTime":"1622697148"
// }
asset := bitgetapi.AccountAsset{
CoinId: 2,
CoinName: "USDT",
Available: fixedpoint.NewFromFloat(1.2),
Frozen: fixedpoint.NewFromFloat(0.5),
Lock: fixedpoint.NewFromFloat(0.5),
UTime: types.NewMillisecondTimestampFromInt(1622697148),
asset := v2.AccountAsset{
Coin: "USDT",
Available: fixedpoint.NewFromFloat(1.2),
Frozen: fixedpoint.NewFromFloat(0.5),
Locked: fixedpoint.NewFromFloat(0.5),
LimitAvailable: fixedpoint.Zero,
UpdatedTime: types.NewMillisecondTimestampFromInt(1622697148),
}

assert.Equal(t, types.Balance{
Expand Down
4 changes: 2 additions & 2 deletions pkg/exchange/bitget/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
return nil, fmt.Errorf("account rate limiter wait error: %w", err)
}

req := e.client.NewGetAccountAssetsRequest()
req := e.v2client.NewGetAccountAssetsRequest().AssetType(v2.AssetTypeHoldOnly)
resp, err := req.Do(ctx)
if err != nil {
return nil, fmt.Errorf("failed to query account assets: %w", err)
Expand All @@ -263,7 +263,7 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
bals := types.BalanceMap{}
for _, asset := range resp {
b := toGlobalBalance(asset)
bals[asset.CoinName] = b
bals[asset.Coin] = b
}

return bals, nil
Expand Down

0 comments on commit 30164ac

Please sign in to comment.