-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmargin.go
61 lines (45 loc) · 1.76 KB
/
margin.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
package tasty
import (
"fmt"
"net/http"
)
// Fetch current margin/capital requirements report for an account.
func (c *Client) GetMarginRequirements(accountNumber string) (MarginRequirements, *http.Response, error) {
path := fmt.Sprintf("/margin/accounts/%s/requirements", accountNumber)
type marginResponse struct {
MarginRequirements MarginRequirements `json:"data"`
}
marginRes := new(marginResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, marginRes)
if err != nil {
return MarginRequirements{}, resp, err
}
return marginRes.MarginRequirements, resp, nil
}
// Get effective margin requirements for account.
func (c *Client) GetEffectiveMarginRequirements(accountNumber, underlyingSymbol string) (EffectiveMarginRequirements, *http.Response, error) {
path := fmt.Sprintf("/accounts/%s/margin-requirements/%s/effective", accountNumber, underlyingSymbol)
type marginResponse struct {
EffectiveMarginRequirements EffectiveMarginRequirements `json:"data"`
}
marginRes := new(marginResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, marginRes)
if err != nil {
return EffectiveMarginRequirements{}, resp, err
}
return marginRes.EffectiveMarginRequirements, resp, nil
}
// Publicly accessible, read only margin configuration.
func (c *Client) GetMarginRequirementsPublicConfiguration() (MarginRequirementsGlobalConfiguration,
*http.Response, error) {
path := "/margin-requirements-public-configuration"
type marginResponse struct {
MarginReq MarginRequirementsGlobalConfiguration `json:"data"`
}
marginRes := new(marginResponse)
resp, err := c.noAuthRequest(http.MethodGet, path, nil, nil, nil, marginRes)
if err != nil {
return MarginRequirementsGlobalConfiguration{}, resp, err
}
return marginRes.MarginReq, resp, nil
}