Skip to content

Commit

Permalink
Merge pull request #101 from johnnybravo-xyz/master
Browse files Browse the repository at this point in the history
feat: Add Full User Profile
  • Loading branch information
vividvilla authored Nov 21, 2023
2 parents f07f57d + 970add1 commit 4874af5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const (
URIUserSessionInvalidate string = "/session/token"
URIUserSessionRenew string = "/session/refresh_token"
URIUserProfile string = "/user/profile"
URIFullUserProfile string = "/user/profile/full"
URIUserMargins string = "/user/margins"
URIUserMarginsSegment string = "/user/margins/%s" // "/user/margins/{segment}"

Expand Down
1 change: 1 addition & 0 deletions connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var MockResponders = [][]string{

// GET endpoints
{http.MethodGet, URIUserProfile, "profile.json"},
{http.MethodGet, URIFullUserProfile, "full_profile.json"},
{http.MethodGet, URIUserMargins, "margins.json"},
{http.MethodGet, URIUserMarginsSegment, "margins_equity.json"},
{http.MethodGet, URIGetOrders, "orders.json"},
Expand Down
2 changes: 1 addition & 1 deletion mock_responses
36 changes: 36 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ type UserMeta struct {
DematConsent string `json:"demat_consent"`
}

// FullUserMeta contains full meta data of the user.
type FullUserMeta struct {
DematConsent string `json:"poa"`
Silo string `json:"silo"`
AccountBlocks []string `json:"account_blocks"`
}

// UserProfile represents a user's personal and financial profile.
type UserProfile struct {
UserID string `json:"user_id"`
Expand All @@ -54,6 +61,28 @@ type UserProfile struct {
Exchanges []string `json:"exchanges"`
}

type FullUserProfile struct {
UserID string `json:"user_id"`
UserName string `json:"user_name"`
AvatarURL string `json:"avatar_url"`
UserType string `json:"user_type"`
Email string `json:"email"`
Phone string `json:"phone"`
Broker string `json:"broker"`
TwoFAType string `json:"twofa_type"`
Banks []Bank `json:"bank_accounts"`
DPIDs []string `json:"dp_ids"`
Products []string `json:"products"`
OrderTypes []string `json:"order_types"`
Exchanges []string `json:"exchanges"`
PAN string `json:"pan"`
UserShortName string `json:"user_shortname"`
Tags []string `json:"tags"`
PasswordTimestamp models.Time `json:"password_timestamp"`
TwoFATimestamp models.Time `json:"twofa_timestamp"`
Meta FullUserMeta `json:"meta"`
}

// Margins represents the user margins for a segment.
type Margins struct {
Category string `json:"-"`
Expand Down Expand Up @@ -178,6 +207,13 @@ func (c *Client) GetUserProfile() (UserProfile, error) {
return userProfile, err
}

// GetFullUserProfile gets full user profile.
func (c *Client) GetFullUserProfile() (FullUserProfile, error) {
var fUserProfile FullUserProfile
err := c.doEnvelope(http.MethodGet, URIFullUserProfile, nil, nil, &fUserProfile)
return fUserProfile, err
}

// GetUserMargins gets all user margins.
func (c *Client) GetUserMargins() (AllMargins, error) {
var allUserMargins AllMargins
Expand Down
8 changes: 8 additions & 0 deletions user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ func (ts *TestSuite) TestGetUserProfile(t *testing.T) {
}
}

func (ts *TestSuite) TestGetFullUserProfile(t *testing.T) {
t.Parallel()
fullProfile, err := ts.KiteConnect.GetFullUserProfile()
if err != nil || fullProfile.Email == "" || fullProfile.UserID == "" {
t.Errorf("Error while reading full user profile. Error: %v", err)
}
}

func (ts *TestSuite) TestGetUserMargins(t *testing.T) {
t.Parallel()
margins, err := ts.KiteConnect.GetUserMargins()
Expand Down

0 comments on commit 4874af5

Please sign in to comment.