-
Notifications
You must be signed in to change notification settings - Fork 2
/
mutualfunds.go
206 lines (175 loc) · 6.89 KB
/
mutualfunds.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package kiteapi
import (
"fmt"
"net/http"
"net/url"
"github.com/google/go-querystring/query"
)
// MFHolding represents a individual mutualfund holding.
type MFHolding struct {
Folio string `json:"folio"`
Fund string `json:"fund"`
Tradingsymbol string `json:"tradingsymbol"`
AveragePrice float64 `json:"average_price"`
LastPrice float64 `json:"last_price"`
LastPriceDate string `json:"last_price_date"`
Pnl float64 `json:"pnl"`
Quantity float64 `json:"quantity"`
}
// MFHoldings represents a list of mutualfund holdings.
type MFHoldings []MFHolding
// MFOrder represents a individual mutualfund order response.
type MFOrder struct {
OrderID string `json:"order_id"`
ExchangeOrderID string `json:"exchange_order_id"`
Tradingsymbol string `json:"tradingsymbol"`
Status string `json:"status"`
StatusMessage string `json:"status_message"`
Folio string `json:"folio"`
Fund string `json:"fund"`
OrderTimestamp Time `json:"order_timestamp"`
ExchangeTimestamp Time `json:"exchange_timestamp"`
SettlementID string `json:"settlement_id"`
TransactionType string `json:"transaction_type"`
Variety string `json:"variety"`
PurchaseType string `json:"purchase_type"`
Quantity float64 `json:"quantity"`
Amount float64 `json:"amount"`
LastPrice float64 `json:"last_price"`
AveragePrice float64 `json:"average_price"`
PlacedBy string `json:"placed_by"`
Tag string `json:"tag"`
}
// MFOrders represents a list of mutualfund orders.
type MFOrders []Order
// MFSIP represents a individual mutualfund SIP response.
type MFSIP struct {
ID string `json:"sip_id"`
Tradingsymbol string `json:"tradingsymbol"`
FundName string `json:"fund"`
DividendType string `json:"dividend_type"`
TransactionType string `json:"transaction_type"`
Status string `json:"status"`
Created Time `json:"created"`
Frequency string `json:"frequency"`
InstalmentAmount float64 `json:"instalment_amount"`
Instalments int `json:"instalments"`
LastInstalment Time `json:"last_instalment"`
PendingInstalments int `json:"pending_instalments"`
InstalmentDay int `json:"instalment_day"`
Tag string `json:"tag"`
}
// MFSIPs represents a list of mutualfund SIPs.
type MFSIPs []MFSIP
// MFOrderResponse represents the successful order place response.
type MFOrderResponse struct {
OrderID string `json:"order_id"`
}
// MFSIPResponse represents the successful SIP place response.
type MFSIPResponse struct {
OrderID *string `json:"order_id"`
SIPID string `json:"sip_id"`
}
// MFOrderParams represents parameters for placing an order.
type MFOrderParams struct {
Tradingsymbol string `json:"tradingsymbol" url:"tradingsymbol"`
TransactionType string `json:"transaction_type" url:"transaction_type"`
Quantity float64 `json:"quantity" url:"quantity,omitempty"`
Amount float64 `json:"amount" url:"amount,omitempty"`
Tag string `json:"tag" url:"tag,omitempty"`
}
// MFSIPParams represents parameters for placing a SIP.
type MFSIPParams struct {
Tradingsymbol string `json:"tradingsymbol" url:"tradingsymbol"`
Amount float64 `json:"amount" url:"amount"`
Instalments int `json:"instalments" url:"instalments"`
Frequency string `json:"frequency" url:"frequency"`
InstalmentDay int `json:"instalment_day" url:"instalment_day,omitempty"`
InitialAmount float64 `json:"initial_amount" url:"initial_amount,omitempty"`
Tag string `json:"tag" url:"tag,omitempty"`
}
// MFSIPModifyParams represents parameters for modifying a SIP.
type MFSIPModifyParams struct {
Amount float64 `json:"amount" url:"amount,omitempty"`
Frequency string `json:"frequency" url:"frequency,omitempty"`
InstalmentDay int `json:"instalment_day" url:"instalment_day,omitempty"`
Instalments int `json:"instalments" url:"instalments,omitempty"`
Status string `json:"status" url:"status,omitempty"`
}
// GetMFOrders gets list of mutualfund orders.
func (c *Client) GetMFOrders() (MFOrders, error) {
var orders MFOrders
err := c.doEnvelope(http.MethodGet, URIGetMFOrders, nil, nil, &orders)
return orders, err
}
// GetMFOrderInfo get individual mutualfund order info.
func (c *Client) GetMFOrderInfo(OrderID string) (MFOrder, error) {
var orderInfo MFOrder
err := c.doEnvelope(http.MethodGet, fmt.Sprintf(URIGetMFOrderInfo, OrderID), nil, nil, &orderInfo)
return orderInfo, err
}
// PlaceMFOrder places an mutualfund order.
func (c *Client) PlaceMFOrder(orderParams MFOrderParams) (MFOrderResponse, error) {
var (
orderResponse MFOrderResponse
params url.Values
err error
)
if params, err = query.Values(orderParams); err != nil {
return orderResponse, NewError(InputError, fmt.Sprintf("Error decoding order params: %v", err), nil)
}
err = c.doEnvelope(http.MethodPost, URIPlaceMFOrder, params, nil, &orderResponse)
return orderResponse, err
}
// GetMFSIPs gets list of mutualfund SIPs.
func (c *Client) GetMFSIPs() (MFSIPs, error) {
var sips MFSIPs
err := c.doEnvelope(http.MethodGet, URIGetMFSIPs, nil, nil, &sips)
return sips, err
}
// GetMFSIPInfo get individual SIP info.
func (c *Client) GetMFSIPInfo(sipID string) (MFSIP, error) {
var sip MFSIP
err := c.doEnvelope(http.MethodGet, fmt.Sprintf(URIGetMFSIPInfo, sipID), nil, nil, &sip)
return sip, err
}
// PlaceMFSIP places an mutualfund SIP order.
func (c *Client) PlaceMFSIP(sipParams MFSIPParams) (MFSIPResponse, error) {
var (
sipResponse MFSIPResponse
params url.Values
err error
)
if params, err = query.Values(sipParams); err != nil {
return sipResponse, NewError(InputError, fmt.Sprintf("Error decoding order params: %v", err), nil)
}
err = c.doEnvelope(http.MethodPost, URIPlaceMFSIP, params, nil, &sipResponse)
return sipResponse, err
}
// ModifyMFSIP modifies an mutualfund SIP.
func (c *Client) ModifyMFSIP(sipID string, sipParams MFSIPModifyParams) (MFSIPResponse, error) {
var (
sipResponse MFSIPResponse
params url.Values
err error
)
if params, err = query.Values(sipParams); err != nil {
return sipResponse, NewError(InputError, fmt.Sprintf("Error decoding order params: %v", err), nil)
}
err = c.doEnvelope(http.MethodPut, fmt.Sprintf(URIModifyMFSIP, sipID), params, nil, &sipResponse)
return sipResponse, err
}
// CancelMFSIP cancels an mutualfund SIP.
func (c *Client) CancelMFSIP(sipID string) (MFSIPResponse, error) {
var (
sipResponse MFSIPResponse
)
err := c.doEnvelope(http.MethodPut, fmt.Sprintf(URICancelMFSIP, sipID), nil, nil, &sipResponse)
return sipResponse, err
}
// GetMFHoldings gets list of user mutualfund holdings.
func (c *Client) GetMFHoldings() (MFHoldings, error) {
var holdings MFHoldings
err := c.doEnvelope(http.MethodGet, URIGetMFHoldings, nil, nil, &holdings)
return holdings, err
}