Continuing work on parsing responses from Ally

This commit is contained in:
Jacob Windle 2019-11-14 16:46:16 -05:00
parent 6e504199cc
commit a383a0535c
8 changed files with 71 additions and 28 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
export.sh .env
allyinvest allyinvest

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/workspace.xml

8
.idea/allyinvest.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/allyinvest.iml" filepath="$PROJECT_DIR$/.idea/allyinvest.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

35
main.go
View File

@ -1,35 +1,28 @@
package main package main
import ( import (
"encoding/xml"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/joho/godotenv"
"github.com/mrjones/oauth" "github.com/mrjones/oauth"
) )
var endpoint string = "https://api.tradeking.com/v1/" var endpoint string = "https://api.tradeking.com/v1/"
/* My configuration structure for oauth */
type config struct {
ConsumerKey string
ConsumerSecret string
AccessToken string
AccessSecret string
}
func main() { func main() {
c := config{ // Load our environment variables
ConsumerKey: os.Getenv("CONSUMER_KEY"), err := godotenv.Load()
ConsumerSecret: os.Getenv("CONSUMER_SECRET"), if err != nil {
AccessToken: os.Getenv("ACCESS_TOKEN"), panic(err)
AccessSecret: os.Getenv("ACCESS_SECRET"),
} }
// Set up our new oauth consumer // Set up our new oauth consumer
cons := oauth.NewConsumer( cons := oauth.NewConsumer(
c.ConsumerKey, os.Getenv("CONSUMER_KEY"),
c.ConsumerSecret, os.Getenv("CONSUMER_SECRET"),
oauth.ServiceProvider{ oauth.ServiceProvider{
RequestTokenUrl: "https://developers.tradeking.com/oauth/request_token", RequestTokenUrl: "https://developers.tradeking.com/oauth/request_token",
AuthorizeTokenUrl: "https://developers.tradeking.com/oauth/authorize", AuthorizeTokenUrl: "https://developers.tradeking.com/oauth/authorize",
@ -38,7 +31,7 @@ func main() {
) )
// Set up our HTTP client // Set up our HTTP client
client, err := cons.MakeHttpClient(&oauth.AccessToken{Token: c.AccessToken, Secret: c.AccessSecret}) client, err := cons.MakeHttpClient(&oauth.AccessToken{Token: os.Getenv("ACCESS_TOKEN"), Secret: os.Getenv("ACCESS_SECRET")})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -48,5 +41,13 @@ func main() {
defer resp.Body.Close() defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body) b, _ := ioutil.ReadAll(resp.Body)
fmt.Printf("Got %s from Ally\n", b) var acctSummary AllyResponse
err = xml.Unmarshal(b, &acctSummary)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", b)
fmt.Printf("%s\n", acctSummary.Accounts)
} }

View File

@ -1,23 +1,34 @@
package main
import "encoding/xml"
/**
Our Response structure from ALLY
*/
type AllyResponse struct { type AllyResponse struct {
XMLName xml.Name `xml:"response"`
Error string `xml:"error"`
ResponseId string `xml:"id,attr"`
ElapsedTime int `xml:"elapsedtime"`
Accounts []AccountSummary `xml:"accounts>accountsummary"`
} }
type AllyAccounts struct { type AccountHoldings struct {
Accounts []AllyAccount
}
type AllyAccount struct {
Summary AccountSummary `xml:"accountsummary"`
} }
type AccountSummary struct { type AccountSummary struct {
Account int `xml:"accountsummary>account"` XMLName xml.Name `xml:"accountsummary"`
AccountName string `xml:"accountsummary>accountname"` Account int `xml:"account"`
AccountName string `xml:"accountname"`
Balance AccountBalance Balance AccountBalance
Holdings AccountHoldings Holdings AccountHoldings
} }
type Securities struct {
}
type AccountBalance struct { type AccountBalance struct {
Account int Account int `xml:"accounts>accountsummary>accountbalance>account"`
AccountValue float64 AccountValue float64
BuyingPower BuyingPower BuyingPower BuyingPower
FedCall int FedCall int