Implemented Accounts endpoint on client
This commit is contained in:
parent
d86d0a775b
commit
13b5665109
20
README.md
20
README.md
@ -1 +1,19 @@
|
||||
# investmentally
|
||||
# Ally Invest API in Go
|
||||
|
||||
This project is intended to be an API wrapper for the Ally Invest API written in Golang
|
||||
|
||||
## Endpoints
|
||||
|
||||
The different endpoints that are currently covered by this API
|
||||
|
||||
### /accounts
|
||||
|
||||
Get all account information for a user.
|
||||
|
||||
## Running This Project
|
||||
|
||||
For now, just build this directory and run the executable.
|
||||
|
||||
### Requirements
|
||||
|
||||
You must within the .env file define your Ally Invest credentials
|
||||
|
25
client.go
25
client.go
@ -1,9 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/mrjones/oauth"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
@ -41,7 +43,28 @@ 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))
|
||||
return
|
||||
}
|
||||
|
||||
/* The /accounts endpoint of Ally */
|
||||
func (c *AllyApi) Accounts() (resp AllyResponse, err error) {
|
||||
b, err := c.get("accounts")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer b.Body.Close()
|
||||
raw, err := ioutil.ReadAll(b.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = xml.Unmarshal(raw, &resp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
17
main.go
17
main.go
@ -1,9 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -11,20 +9,7 @@ func main() {
|
||||
var api AllyApi
|
||||
api.Initialize()
|
||||
|
||||
// Set up our HTTP client
|
||||
acctSummary, _ := api.Accounts()
|
||||
|
||||
resp, err := api.Get("accounts")
|
||||
|
||||
defer resp.Body.Close()
|
||||
b, _ := ioutil.ReadAll(resp.Body)
|
||||
|
||||
var acctSummary AllyResponse
|
||||
err = xml.Unmarshal(b, &acctSummary)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", b)
|
||||
fmt.Printf("%f\n", acctSummary.Accounts[0].AccountHoldingsInfo.TotalSecurities)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user