-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser_client.go
94 lines (87 loc) · 2.75 KB
/
user_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package fyers
import (
"encoding/json"
"fmt"
"github.com/rishi-anand/fyers-go-client/api"
"github.com/rishi-anand/fyers-go-client/utils"
)
func (c *client) GetProfile() (api.UserProfile, error) {
if resp, err := c.invoke(utils.GET, c.toUri(ApiV2, ProfileUrl), nil); err != nil {
return api.UserProfile{}, err
} else {
if utils.IsSuccessResponse(resp) {
var response api.UserProfile
if json.Unmarshal([]byte(utils.GetJsonValueAtPath(resp, "data")), &response); err != nil {
return api.UserProfile{}, err
} else {
return response, nil
}
} else {
return api.UserProfile{}, fmt.Errorf("failed to get profile information. %v", utils.GetJsonValueAtPath(resp, "message"))
}
}
}
func (c *client) GetFund() (api.UserFund, error) {
if resp, err := c.invoke(utils.GET, c.toUri(ApiV2, FundsUrl), nil); err != nil {
return api.UserFund{}, err
} else {
if utils.IsSuccessResponse(resp) {
var response api.UserFund
if json.Unmarshal(resp, &response); err != nil {
return api.UserFund{}, err
} else {
return response, nil
}
} else {
return api.UserFund{}, fmt.Errorf("failed to get fund information. %v", utils.GetJsonValueAtPath(resp, "message"))
}
}
}
func (c *client) GetHoldings() (api.UserHoldings, error) {
if resp, err := c.invoke(utils.GET, c.toUri(ApiV2, HoldingsUrl), nil); err != nil {
return api.UserHoldings{}, err
} else {
if utils.IsSuccessResponse(resp) {
var response api.UserHoldings
if json.Unmarshal(resp, &response); err != nil {
return api.UserHoldings{}, err
} else {
return response, nil
}
} else {
return api.UserHoldings{}, fmt.Errorf("failed to get holdings information. %v", utils.GetJsonValueAtPath(resp, "message"))
}
}
}
func (c *client) GetPositions() (api.UserPosition, error) {
if resp, err := c.invoke(utils.GET, c.toUri(ApiV2, PositionsUrl), nil); err != nil {
return api.UserPosition{}, err
} else {
if utils.IsSuccessResponse(resp) {
var response api.UserPosition
if json.Unmarshal(resp, &response); err != nil {
return api.UserPosition{}, err
} else {
return response, nil
}
} else {
return api.UserPosition{}, fmt.Errorf("failed to get positions information. %v", utils.GetJsonValueAtPath(resp, "message"))
}
}
}
func (c *client) ListTrades() ([]api.TradeBook, error) {
if resp, err := c.invoke(utils.GET, c.toUri(ApiV2, TradeBookUrl), nil); err != nil {
return nil, err
} else {
if utils.IsSuccessResponse(resp) {
var response []api.TradeBook
if json.Unmarshal([]byte(utils.GetJsonValueAtPath(resp, "tradeBook")), &response); err != nil {
return nil, err
} else {
return response, nil
}
} else {
return nil, fmt.Errorf("failed to get trades information. %v", utils.GetJsonValueAtPath(resp, "message"))
}
}
}