diff --git a/.gitignore b/.gitignore index b34b32d..75c2dbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -export.sh +.env allyinvest \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..0e40fe8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/allyinvest.iml b/.idea/allyinvest.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/allyinvest.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..28a804d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5315145 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.go b/main.go index 2ccadf3..77f49ae 100644 --- a/main.go +++ b/main.go @@ -1,35 +1,28 @@ package main import ( + "encoding/xml" "fmt" "io/ioutil" "os" + "github.com/joho/godotenv" "github.com/mrjones/oauth" ) 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() { - c := config{ - ConsumerKey: os.Getenv("CONSUMER_KEY"), - ConsumerSecret: os.Getenv("CONSUMER_SECRET"), - AccessToken: os.Getenv("ACCESS_TOKEN"), - AccessSecret: os.Getenv("ACCESS_SECRET"), + // Load our environment variables + err := godotenv.Load() + if err != nil { + panic(err) } // Set up our new oauth consumer cons := oauth.NewConsumer( - c.ConsumerKey, - c.ConsumerSecret, + os.Getenv("CONSUMER_KEY"), + os.Getenv("CONSUMER_SECRET"), oauth.ServiceProvider{ RequestTokenUrl: "https://developers.tradeking.com/oauth/request_token", AuthorizeTokenUrl: "https://developers.tradeking.com/oauth/authorize", @@ -38,7 +31,7 @@ func main() { ) // 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 { panic(err) } @@ -48,5 +41,13 @@ func main() { defer resp.Body.Close() 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) } diff --git a/types.go b/types.go index 6c559e1..62d7877 100644 --- a/types.go +++ b/types.go @@ -1,23 +1,34 @@ +package main + +import "encoding/xml" + +/** +Our Response structure from ALLY +*/ 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 { - Accounts []AllyAccount -} - -type AllyAccount struct { - Summary AccountSummary `xml:"accountsummary"` +type AccountHoldings struct { } type AccountSummary struct { - Account int `xml:"accountsummary>account"` - AccountName string `xml:"accountsummary>accountname"` + XMLName xml.Name `xml:"accountsummary"` + Account int `xml:"account"` + AccountName string `xml:"accountname"` Balance AccountBalance Holdings AccountHoldings } +type Securities struct { +} + type AccountBalance struct { - Account int + Account int `xml:"accounts>accountsummary>accountbalance>account"` AccountValue float64 BuyingPower BuyingPower FedCall int @@ -47,4 +58,4 @@ type Money struct { UnclearedDeposits float64 UnsettledFunds float64 Yield float64 -} \ No newline at end of file +}