Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions hyperliquid/exchange_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
30 changes: 30 additions & 0 deletions hyperliquid/info_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
17 changes: 17 additions & 0 deletions hyperliquid/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down