Covered account detail response
This commit is contained in:
parent
c6eb542a2c
commit
e2479704f2
51
client.go
51
client.go
@ -46,38 +46,41 @@ func (c *AllyApi) Initialize() {
|
|||||||
|
|
||||||
func (c *AllyApi) get(path string) (resp *http.Response, err error) {
|
func (c *AllyApi) get(path string) (resp *http.Response, err error) {
|
||||||
resp, err = c.Client.Get(fmt.Sprintf("%s\\%s", endpoint, path))
|
resp, err = c.Client.Get(fmt.Sprintf("%s\\%s", endpoint, path))
|
||||||
return
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetAndMarshal call GET on the path, and marshal the resopnse to interface
|
||||||
|
// type
|
||||||
|
func (c *AllyApi) getAndRead(path string) []byte {
|
||||||
|
resp, err := c.get(path)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Could not make request")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
raw, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Could not read body!")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The /accounts endpoint of Ally */
|
/* The /accounts endpoint of Ally */
|
||||||
func (c *AllyApi) Accounts() []AccountSummary {
|
func (c *AllyApi) Accounts() []AccountSummary {
|
||||||
b, err := c.get("accounts")
|
|
||||||
if err != nil {
|
|
||||||
}
|
|
||||||
|
|
||||||
defer b.Body.Close()
|
|
||||||
raw, err := ioutil.ReadAll(b.Body)
|
|
||||||
fmt.Printf("%s\n", raw)
|
|
||||||
if err != nil {
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp AccountResponse
|
var resp AccountResponse
|
||||||
err = xml.Unmarshal(raw, &resp)
|
_ = xml.Unmarshal(c.getAndRead("accounts"), &resp)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return resp.Accounts.Accountsummary
|
return resp.Accounts.Accountsummary
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *AllyApi) AccountBalances() (balances []AccountBalance) {
|
func (c *AllyApi) AccountBalances() (balances []AccountBalance) {
|
||||||
b, err := c.get("accounts/balances")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Could not get account balances")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer b.Body.Close()
|
|
||||||
|
|
||||||
var resp AccountBalanceResponse
|
var resp AccountBalanceResponse
|
||||||
|
_ = xml.Unmarshal(c.getAndRead("accounts/balances"), &resp)
|
||||||
|
return resp.AccountBalances
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *AllyApi) AccountDetail(accountId int) AccountDetailResponse {
|
||||||
|
var resp AccountDetailResponse
|
||||||
|
_ = xml.Unmarshal(c.getAndRead(fmt.Sprintf("accounts/%d", accountId)), &resp)
|
||||||
|
return resp
|
||||||
}
|
}
|
||||||
|
9
main.go
9
main.go
@ -1,11 +1,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Load our environment variables
|
// Load our environment variables
|
||||||
var api AllyApi
|
var api AllyApi
|
||||||
api.Initialize()
|
api.Initialize()
|
||||||
|
|
||||||
fmt.Printf("%s\n", api.Accounts()[0].Accountholdings.Displaydata.Totalsecurities)
|
acctId, _ := strconv.Atoi(api.Accounts()[0].Account)
|
||||||
|
|
||||||
|
fmt.Printf("AccountDetail: %s\n", api.AccountDetail(acctId).AccountHoldings.Holding[0].Displaydata.Change)
|
||||||
}
|
}
|
||||||
|
182
types.go
182
types.go
@ -4,96 +4,100 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AccountSummary struct {
|
type Accountbalance struct {
|
||||||
XMLName xml.Name `xml:"accountsummary"`
|
XMLName xml.Name `xml:"accountbalance"`
|
||||||
Text string `xml:",chardata"`
|
Account string `xml:"account"`
|
||||||
Account string `xml:"account"`
|
Accountvalue float64 `xml:"accountvalue"`
|
||||||
Accountbalance struct {
|
Buyingpower struct {
|
||||||
|
Text string `xml:",chardata"`
|
||||||
|
Cashavailableforwithdrawal float64 `xml:"cashavailableforwithdrawal"`
|
||||||
|
Daytrading float64 `xml:"daytrading"`
|
||||||
|
Equitypercentage float64 `xml:"equitypercentage"`
|
||||||
|
Options float64 `xml:"options"`
|
||||||
|
Soddaytrading float64 `xml:"soddaytrading"`
|
||||||
|
Sodoptions float64 `xml:"sodoptions"`
|
||||||
|
Sodstock float64 `xml:"sodstock"`
|
||||||
|
Stock float64 `xml:"stock"`
|
||||||
|
} `xml:"buyingpower"`
|
||||||
|
Fedcall float64 `xml:"fedcall"`
|
||||||
|
Housecall float64 `xml:"housecall"`
|
||||||
|
Money struct {
|
||||||
|
Text string `xml:",chardata"`
|
||||||
|
Accruedinterest float64 `xml:"accruedinterest"`
|
||||||
|
Cash float64 `xml:"cash"`
|
||||||
|
Cashavailable float64 `xml:"cashavailable"`
|
||||||
|
Marginbalance float64 `xml:"marginbalance"`
|
||||||
|
Mmf float64 `xml:"mmf"`
|
||||||
|
Total float64 `xml:"total"`
|
||||||
|
Uncleareddeposits float64 `xml:"uncleareddeposits"`
|
||||||
|
Unsettledfunds float64 `xml:"unsettledfunds"`
|
||||||
|
Yield float64 `xml:"yield"`
|
||||||
|
} `xml:"money"`
|
||||||
|
Securities struct {
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
Account string `xml:"account"`
|
Longoptions float64 `xml:"longoptions"`
|
||||||
Accountvalue float64 `xml:"accountvalue"`
|
Longstocks float64 `xml:"longstocks"`
|
||||||
Buyingpower struct {
|
Options float64 `xml:"options"`
|
||||||
Text string `xml:",chardata"`
|
Shortoptions float64 `xml:"shortoptions"`
|
||||||
Cashavailableforwithdrawal float64 `xml:"cashavailableforwithdrawal"`
|
Shortstocks float64 `xml:"shortstocks"`
|
||||||
Daytrading float64 `xml:"daytrading"`
|
Stocks float64 `xml:"stocks"`
|
||||||
Equitypercentage float64 `xml:"equitypercentage"`
|
Total float64 `xml:"total"`
|
||||||
Options float64 `xml:"options"`
|
} `xml:"securities"`
|
||||||
Soddaytrading float64 `xml:"soddaytrading"`
|
}
|
||||||
Sodoptions float64 `xml:"sodoptions"`
|
|
||||||
Sodstock float64 `xml:"sodstock"`
|
type Accountholdings struct {
|
||||||
Stock float64 `xml:"stock"`
|
XMLName xml.Name `xml:"accountholdings"`
|
||||||
} `xml:"buyingpower"`
|
Displaydata struct {
|
||||||
Fedcall float64 `xml:"fedcall"`
|
Text string `xml:",chardata"`
|
||||||
Housecall float64 `xml:"housecall"`
|
Totalsecurities string `xml:"totalsecurities"`
|
||||||
Money struct {
|
} `xml:"displaydata"`
|
||||||
Text string `xml:",chardata"`
|
Holding []struct {
|
||||||
Accruedinterest float64 `xml:"accruedinterest"`
|
|
||||||
Cash float64 `xml:"cash"`
|
|
||||||
Cashavailable float64 `xml:"cashavailable"`
|
|
||||||
Marginbalance float64 `xml:"marginbalance"`
|
|
||||||
Mmf float64 `xml:"mmf"`
|
|
||||||
Total float64 `xml:"total"`
|
|
||||||
Uncleareddeposits float64 `xml:"uncleareddeposits"`
|
|
||||||
Unsettledfunds float64 `xml:"unsettledfunds"`
|
|
||||||
Yield float64 `xml:"yield"`
|
|
||||||
} `xml:"money"`
|
|
||||||
Securities struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Longoptions float64 `xml:"longoptions"`
|
|
||||||
Longstocks float64 `xml:"longstocks"`
|
|
||||||
Options float64 `xml:"options"`
|
|
||||||
Shortoptions float64 `xml:"shortoptions"`
|
|
||||||
Shortstocks float64 `xml:"shortstocks"`
|
|
||||||
Stocks float64 `xml:"stocks"`
|
|
||||||
Total float64 `xml:"total"`
|
|
||||||
} `xml:"securities"`
|
|
||||||
} `xml:"accountbalance"`
|
|
||||||
Accountholdings struct {
|
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
|
Accounttype string `xml:"accounttype"`
|
||||||
|
Costbasis string `xml:"costbasis"`
|
||||||
Displaydata struct {
|
Displaydata struct {
|
||||||
Text string `xml:",chardata"`
|
Text string `xml:",chardata"`
|
||||||
Totalsecurities string `xml:"totalsecurities"`
|
Accounttype string `xml:"accounttype"`
|
||||||
|
Assetclass string `xml:"assetclass"`
|
||||||
|
Change string `xml:"change"`
|
||||||
|
Costbasis string `xml:"costbasis"`
|
||||||
|
Desc string `xml:"desc"`
|
||||||
|
Lastprice string `xml:"lastprice"`
|
||||||
|
Marketvalue string `xml:"marketvalue"`
|
||||||
|
Marketvaluechange string `xml:"marketvaluechange"`
|
||||||
|
Qty string `xml:"qty"`
|
||||||
|
Symbol string `xml:"symbol"`
|
||||||
} `xml:"displaydata"`
|
} `xml:"displaydata"`
|
||||||
Holding []struct {
|
Gainloss float64 `xml:"gainloss"`
|
||||||
Text string `xml:",chardata"`
|
Instrument struct {
|
||||||
Accounttype string `xml:"accounttype"`
|
Text string `xml:",chardata"`
|
||||||
Costbasis string `xml:"costbasis"`
|
Cusip string `xml:"cusip"`
|
||||||
Displaydata struct {
|
Desc string `xml:"desc"`
|
||||||
Text string `xml:",chardata"`
|
Factor string `xml:"factor"`
|
||||||
Accounttype string `xml:"accounttype"`
|
Sectyp string `xml:"sectyp"`
|
||||||
Assetclass string `xml:"assetclass"`
|
Sym string `xml:"sym"`
|
||||||
Change string `xml:"change"`
|
} `xml:"instrument"`
|
||||||
Costbasis string `xml:"costbasis"`
|
Marketvalue float64 `xml:"marketvalue"`
|
||||||
Desc string `xml:"desc"`
|
Marketvaluechange float64 `xml:"marketvaluechange"`
|
||||||
Lastprice string `xml:"lastprice"`
|
Price float64 `xml:"price"`
|
||||||
Marketvalue string `xml:"marketvalue"`
|
Purchaseprice float64 `xml:"purchaseprice"`
|
||||||
Marketvaluechange string `xml:"marketvaluechange"`
|
Qty float64 `xml:"qty"`
|
||||||
Qty string `xml:"qty"`
|
Quote struct {
|
||||||
Symbol string `xml:"symbol"`
|
Text string `xml:",chardata"`
|
||||||
} `xml:"displaydata"`
|
Change float64 `xml:"change"`
|
||||||
Gainloss float64 `xml:"gainloss"`
|
Lastprice float64 `xml:"lastprice"`
|
||||||
Instrument struct {
|
} `xml:"quote"`
|
||||||
Text string `xml:",chardata"`
|
Underlying string `xml:"underlying"`
|
||||||
Cusip string `xml:"cusip"`
|
} `xml:"holding"`
|
||||||
Desc string `xml:"desc"`
|
Totalsecurities float64 `xml:"totalsecurities"`
|
||||||
Factor string `xml:"factor"`
|
}
|
||||||
Sectyp string `xml:"sectyp"`
|
|
||||||
Sym string `xml:"sym"`
|
type AccountSummary struct {
|
||||||
} `xml:"instrument"`
|
XMLName xml.Name `xml:"accountsummary"`
|
||||||
Marketvalue float64 `xml:"marketvalue"`
|
Text string `xml:",chardata"`
|
||||||
Marketvaluechange float64 `xml:"marketvaluechange"`
|
Account string `xml:"account"`
|
||||||
Price float64 `xml:"price"`
|
Accountbalance Accountbalance `xml:"accountbalance"`
|
||||||
Purchaseprice float64 `xml:"purchaseprice"`
|
Accountholdings Accountholdings `xml:"accountholdings"`
|
||||||
Qty float64 `xml:"qty"`
|
|
||||||
Quote struct {
|
|
||||||
Text string `xml:",chardata"`
|
|
||||||
Change float64 `xml:"change"`
|
|
||||||
Lastprice float64 `xml:"lastprice"`
|
|
||||||
} `xml:"quote"`
|
|
||||||
Underlying string `xml:"underlying"`
|
|
||||||
} `xml:"holding"`
|
|
||||||
Totalsecurities float64 `xml:"totalsecurities"`
|
|
||||||
} `xml:"accountholdings"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountResponse struct {
|
type AccountResponse struct {
|
||||||
@ -118,3 +122,9 @@ type AccountBalanceResponse struct {
|
|||||||
AccountBalances []AccountBalance `xml:"accountbalance"`
|
AccountBalances []AccountBalance `xml:"accountbalance"`
|
||||||
TotalBalance float64 `xml:"totalbalance>accountvalue"`
|
TotalBalance float64 `xml:"totalbalance>accountvalue"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AccountDetailResponse struct {
|
||||||
|
XMLName xml.Name `xml:"response"`
|
||||||
|
AccountBalance Accountbalance `xml:"accountbalance"`
|
||||||
|
AccountHoldings Accountholdings `xml:"accountholdings"`
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user