make private if not part of provider interface
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5eea9ede3a
commit
47e460a9dc
@ -25,7 +25,7 @@ type Address struct {
|
|||||||
|
|
||||||
// GetAddress returns an Address struct populated with data from blockstream.info
|
// GetAddress returns an Address struct populated with data from blockstream.info
|
||||||
// for a given BTC address
|
// for a given BTC address
|
||||||
func (c *client) GetAddress(address string) (*Address, error) {
|
func (c *client) getAddress(address string) (*Address, error) {
|
||||||
addressResponse := &Address{}
|
addressResponse := &Address{}
|
||||||
|
|
||||||
err := c.get(fmt.Sprintf("address/%s", address), addressResponse, url.Values{})
|
err := c.get(fmt.Sprintf("address/%s", address), addressResponse, url.Values{})
|
||||||
|
@ -51,7 +51,7 @@ func (p *Provider) GetBalances() ([]int, []string, error) {
|
|||||||
ynabAccountIDs := make([]string, 0)
|
ynabAccountIDs := make([]string, 0)
|
||||||
var satoshiBalance int
|
var satoshiBalance int
|
||||||
for _, bitcoinAddress := range p.bitcoinAddresses {
|
for _, bitcoinAddress := range p.bitcoinAddresses {
|
||||||
addressResponse, err := p.client.GetAddress(bitcoinAddress)
|
addressResponse, err := p.client.getAddress(bitcoinAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return balances, ynabAccountIDs, fmt.Errorf("failed to get bitcoin address '%s': %v", bitcoinAddress, err)
|
return balances, ynabAccountIDs, fmt.Errorf("failed to get bitcoin address '%s': %v", bitcoinAddress, err)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
// of which the API client is authorized.
|
// of which the API client is authorized.
|
||||||
//
|
//
|
||||||
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts
|
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts
|
||||||
type Account struct {
|
type account struct {
|
||||||
// Type of the account (e.g., "Cash", "Margin").
|
// Type of the account (e.g., "Cash", "Margin").
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ type Account struct {
|
|||||||
// Balance belonging to an Account
|
// Balance belonging to an Account
|
||||||
//
|
//
|
||||||
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
|
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
|
||||||
type Balance struct {
|
type balance struct {
|
||||||
|
|
||||||
// Currency of the balance figure(e.g., "USD" or "CAD").
|
// Currency of the balance figure(e.g., "USD" or "CAD").
|
||||||
Currency string `json:"currency"`
|
Currency string `json:"currency"`
|
||||||
@ -61,35 +61,35 @@ type Balance struct {
|
|||||||
// AccountBalances represents per-currency and combined balances for a specified account.
|
// AccountBalances represents per-currency and combined balances for a specified account.
|
||||||
//
|
//
|
||||||
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
|
// Ref: http://www.questrade.com/api/documentation/rest-operations/account-calls/accounts-id-balances
|
||||||
type AccountBalances struct {
|
type accountBalances struct {
|
||||||
PerCurrencyBalances []Balance `json:"perCurrencyBalances"`
|
PerCurrencyBalances []balance `json:"perCurrencyBalances"`
|
||||||
CombinedBalances []Balance `json:"combinedBalances"`
|
CombinedBalances []balance `json:"combinedBalances"`
|
||||||
SODPerCurrencyBalances []Balance `json:"sodPerCurrencyBalances"`
|
SODPerCurrencyBalances []balance `json:"sodPerCurrencyBalances"`
|
||||||
SODCombinedBalances []Balance `json:"sodCombinedBalances"`
|
SODCombinedBalances []balance `json:"sodCombinedBalances"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccounts returns the logged-in User ID, and a list of accounts
|
// GetAccounts returns the logged-in User ID, and a list of accounts
|
||||||
// belonging to that user.
|
// belonging to that user.
|
||||||
func (c *client) GetAccounts() (int, []Account, error) {
|
func (c *client) GetAccounts() (int, []account, error) {
|
||||||
list := struct {
|
list := struct {
|
||||||
UserID int `json:"userId"`
|
UserID int `json:"userId"`
|
||||||
Accounts []Account `json:"accounts"`
|
Accounts []account `json:"accounts"`
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
err := c.get("v1/accounts", &list, url.Values{})
|
err := c.get("v1/accounts", &list, url.Values{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, []Account{}, err
|
return 0, []account{}, err
|
||||||
}
|
}
|
||||||
return list.UserID, list.Accounts, nil
|
return list.UserID, list.Accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBalances returns the balances for the account with the specified account number
|
// GetBalances returns the balances for the account with the specified account number
|
||||||
func (c *client) GetBalances(number string) (AccountBalances, error) {
|
func (c *client) GetBalances(number string) (accountBalances, error) {
|
||||||
bal := AccountBalances{}
|
bal := accountBalances{}
|
||||||
|
|
||||||
err := c.get("v1/accounts/"+number+"/balances", &bal, url.Values{})
|
err := c.get("v1/accounts/"+number+"/balances", &bal, url.Values{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return AccountBalances{}, err
|
return accountBalances{}, err
|
||||||
}
|
}
|
||||||
return bal, nil
|
return bal, nil
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
const loginServerURL = "https://login.questrade.com/oauth2/"
|
const loginServerURL = "https://login.questrade.com/oauth2/"
|
||||||
|
|
||||||
type LoginCredentials struct {
|
type loginCredentials struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
TokenType string `json:"token_type"`
|
TokenType string `json:"token_type"`
|
||||||
ExpiresIn int `json:"expires_in"`
|
ExpiresIn int `json:"expires_in"`
|
||||||
@ -24,7 +24,7 @@ type LoginCredentials struct {
|
|||||||
// endpoints. It holds the login credentials, http client/transport,
|
// endpoints. It holds the login credentials, http client/transport,
|
||||||
// rate limit information, and the login session timer.
|
// rate limit information, and the login session timer.
|
||||||
type client struct {
|
type client struct {
|
||||||
Credentials LoginCredentials
|
Credentials loginCredentials
|
||||||
SessionTimer *time.Timer
|
SessionTimer *time.Timer
|
||||||
RateLimitRemaining int
|
RateLimitRemaining int
|
||||||
RateLimitReset time.Time
|
RateLimitReset time.Time
|
||||||
@ -34,7 +34,7 @@ type client struct {
|
|||||||
|
|
||||||
// authHeader is a shortcut that returns a string to be placed
|
// authHeader is a shortcut that returns a string to be placed
|
||||||
// in the authorization header of API calls
|
// in the authorization header of API calls
|
||||||
func (l LoginCredentials) authHeader() string {
|
func (l loginCredentials) authHeader() string {
|
||||||
return l.TokenType + " " + l.AccessToken
|
return l.TokenType + " " + l.AccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ func newClient(refreshToken string) (*client, error) {
|
|||||||
|
|
||||||
// Create a new client
|
// Create a new client
|
||||||
c := &client{
|
c := &client{
|
||||||
Credentials: LoginCredentials{
|
Credentials: loginCredentials{
|
||||||
RefreshToken: refreshToken,
|
RefreshToken: refreshToken,
|
||||||
},
|
},
|
||||||
httpClient: httpClient,
|
httpClient: httpClient,
|
||||||
|
Loading…
Reference in New Issue
Block a user