mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
pkg/exchange: use v2 get account asset api
This commit is contained in:
parent
c5decf9bf8
commit
30164acdcf
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
@ -23,13 +22,13 @@ func Test_toGlobalBalance(t *testing.T) {
|
|||
// "lock":"0",
|
||||
// "uTime":"1622697148"
|
||||
// }
|
||||
asset := bitgetapi.AccountAsset{
|
||||
CoinId: 2,
|
||||
CoinName: "USDT",
|
||||
asset := v2.AccountAsset{
|
||||
Coin: "USDT",
|
||||
Available: fixedpoint.NewFromFloat(1.2),
|
||||
Frozen: fixedpoint.NewFromFloat(0.5),
|
||||
Lock: fixedpoint.NewFromFloat(0.5),
|
||||
UTime: types.NewMillisecondTimestampFromInt(1622697148),
|
||||
Locked: fixedpoint.NewFromFloat(0.5),
|
||||
LimitAvailable: fixedpoint.Zero,
|
||||
UpdatedTime: types.NewMillisecondTimestampFromInt(1622697148),
|
||||
}
|
||||
|
||||
assert.Equal(t, types.Balance{
|
||||
|
|
|
@ -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)
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user