-
Notifications
You must be signed in to change notification settings - Fork 13
/
accounts.go
77 lines (65 loc) · 2.18 KB
/
accounts.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
package igmarkets
import (
"bytes"
"context"
"fmt"
"net/http"
)
const (
AccountTypeCFD = "CFD"
AccountTypePhysical = "PHYSICAL"
AccountTypeSpreadbet = "SPREADBET"
AccountStatusEnabled = "ENABLED"
AccountStatusDisabled = "DISABLED"
AccountStatusSuspended = "SUSPENDED_FROM_DEALING"
)
type Accounts struct {
Accounts []struct {
AccountId string `json:"accountId"`
AccountName string `json:"accountName"`
AccountAlias string `json:"accountAlias"`
Status string `json:"status"`
AccountType string `json:"accountType"`
Preferred bool `json:"preferred"`
Balance struct {
Balance float64 `json:"balance"`
Deposit float64 `json:"deposit"`
ProfitLoss float64 `json:"profitLoss"`
Available float64 `json:"available"`
} `json:"balance"`
Currency string `json:"currency"`
CanTransferFrom bool `json:"canTransferFrom"`
CanTransferTo bool `json:"canTransferTo"`
} `json:"accounts"`
}
type AccountsPreferences struct {
TrailingStopsEnabled bool `json:"trailingStopsEnabled"`
}
// GetAccounts - Returns a list of accounts belonging to the logged-in client.
func (ig *IGMarkets) GetAccounts(ctx context.Context) (*Accounts, error) {
bodyReq := new(bytes.Buffer)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/gateway/deal/accounts", ig.APIURL), bodyReq)
if err != nil {
return nil, fmt.Errorf("igmarkets: unable to get accounts: %v", err)
}
igResponseInterface, err := ig.doRequest(ctx, req, 1, Accounts{})
if err != nil {
return nil, err
}
accounts, _ := igResponseInterface.(*Accounts)
return accounts, err
}
// GetAccountPreferences - Returns all account related preferences
func (ig *IGMarkets) GetAccountPreferences(ctx context.Context) (*AccountsPreferences, error) {
bodyReq := new(bytes.Buffer)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/gateway/deal/accounts/preferences", ig.APIURL), bodyReq)
if err != nil {
return nil, fmt.Errorf("igmarkets: unable to get account preferences: %v", err)
}
igResponseInterface, err := ig.doRequest(ctx, req, 1, AccountsPreferences{})
if err != nil {
return nil, err
}
accounts, _ := igResponseInterface.(*AccountsPreferences)
return accounts, err
}