pkg/exchange: use v2 get account asset api

This commit is contained in:
Edwin 2024-01-03 11:25:46 +08:00
parent c5decf9bf8
commit 30164acdcf
4 changed files with 13 additions and 15 deletions

View File

@ -31,7 +31,7 @@ type GetAccountAssetsRequest struct {
client requestgen.AuthenticatedAPIClient client requestgen.AuthenticatedAPIClient
coin *string `param:"symbol,query"` coin *string `param:"symbol,query"`
assetType AssetType `param:"limit,query"` assetType AssetType `param:"assetType,query"`
} }
func (c *Client) NewGetAccountAssetsRequest() *GetAccountAssetsRequest { func (c *Client) NewGetAccountAssetsRequest() *GetAccountAssetsRequest {

View File

@ -7,17 +7,16 @@ import (
"strconv" "strconv"
"time" "time"
"github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi"
v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2" v2 "github.com/c9s/bbgo/pkg/exchange/bitget/bitgetapi/v2"
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/types"
) )
func toGlobalBalance(asset bitgetapi.AccountAsset) types.Balance { func toGlobalBalance(asset v2.AccountAsset) types.Balance {
return types.Balance{ return types.Balance{
Currency: asset.CoinName, Currency: asset.Coin,
Available: asset.Available, Available: asset.Available,
Locked: asset.Lock.Add(asset.Frozen), Locked: asset.Locked.Add(asset.Frozen),
Borrowed: fixedpoint.Zero, Borrowed: fixedpoint.Zero,
Interest: fixedpoint.Zero, Interest: fixedpoint.Zero,
NetAsset: fixedpoint.Zero, NetAsset: fixedpoint.Zero,

View File

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

View File

@ -254,7 +254,7 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
return nil, fmt.Errorf("account rate limiter wait error: %w", err) 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) resp, err := req.Do(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to query account assets: %w", err) return nil, fmt.Errorf("failed to query account assets: %w", err)
@ -263,7 +263,7 @@ func (e *Exchange) QueryAccountBalances(ctx context.Context) (types.BalanceMap,
bals := types.BalanceMap{} bals := types.BalanceMap{}
for _, asset := range resp { for _, asset := range resp {
b := toGlobalBalance(asset) b := toGlobalBalance(asset)
bals[asset.CoinName] = b bals[asset.Coin] = b
} }
return bals, nil return bals, nil