diff --git a/hyperliquid/exchange_types.go b/hyperliquid/exchange_types.go index a9af9e9..69af1c6 100644 --- a/hyperliquid/exchange_types.go +++ b/hyperliquid/exchange_types.go @@ -191,12 +191,19 @@ type FundingDelta struct { } type Withdrawal struct { + Time int64 `json:"time"` Hash string `json:"hash"` Amount float64 `json:"usdc"` Fee float64 `json:"fee"` Nonce int64 `json:"nonce"` } +type Deposit struct { + Hash string `json:"hash,omitempty"` + Time int64 `json:"time,omitempty"` + Amount float64 `json:"usdc,omitempty"` +} + type WithdrawAction struct { Type string `msgpack:"type" json:"type"` Destination string `msgpack:"destination" json:"destination"` diff --git a/hyperliquid/info_service.go b/hyperliquid/info_service.go index 9a1e64a..144ff22 100644 --- a/hyperliquid/info_service.go +++ b/hyperliquid/info_service.go @@ -240,6 +240,7 @@ func (api *InfoAPI) GetWithdrawals(address string) (*[]Withdrawal, error) { for _, update := range *updates { if update.Delta.Type == "withdraw" { withrawal := Withdrawal{ + Time: update.Time, Hash: update.Hash, Amount: update.Delta.Usdc, Fee: update.Delta.Fee, @@ -258,6 +259,35 @@ func (api *InfoAPI) GetAccountWithdrawals() (*[]Withdrawal, error) { return api.GetWithdrawals(api.AccountAddress()) } +// Helper function to get the deposits of the given address +// By default returns last 90 days +func (api *InfoAPI) GetDeposits(address string) (*[]Deposit, error) { + startTime, endTime := GetDefaultTimeRange() + updates, err := api.GetNonFundingUpdates(address, startTime, endTime) + if err != nil { + return nil, err + } + var deposits []Deposit + for _, update := range *updates { + if update.Delta.Type == "deposit" { + deposit := Deposit{ + Hash: update.Hash, + Amount: update.Delta.Usdc, + Time: update.Time, + } + deposits = append(deposits, deposit) + } + } + return &deposits, nil +} + +// Helper function to get the deposits of the account address +// The same as GetDeposits but user is set to the account address +// Check AccountAddress() or SetAccountAddress() if there is a need to set the account address +func (api *InfoAPI) GetAccountDeposits() (*[]Deposit, error) { + return api.GetDeposits(api.AccountAddress()) +} + // Helper function to build a map of asset names to asset info // It is used to get the assetId for a given asset name func (api *InfoAPI) BuildMetaMap() (map[string]AssetInfo, error) { diff --git a/hyperliquid/info_test.go b/hyperliquid/info_test.go index 52ce96c..f8bbed0 100644 --- a/hyperliquid/info_test.go +++ b/hyperliquid/info_test.go @@ -247,6 +247,23 @@ func TestInfoAPI_GetAccountWithdrawals(t *testing.T) { t.Logf("GetAccountWithdrawals() = %v", res) } +func TestInfoAPI_GetAccountDeposits(t *testing.T) { + api := GetInfoAPI() + res, err := api.GetAccountDeposits() + if err != nil { + t.Errorf("GetAccountDeposits() error = %v", err) + } + if len(*res) == 0 { + t.Errorf("GetAccountDeposits() len = %v, want > %v", res, 0) + } + for _, deposit := range *res { + if deposit.Amount == 0 { + t.Errorf("deposit.Amount = %v, want > %v", deposit.Amount, 0) + } + } + t.Logf("GetAccountDeposits() = %v", res) +} + func TestInfoAPI_GetMarketPx(t *testing.T) { api := GetInfoAPI() res, err := api.GetMartketPx("BTC")