Continuing work on parsing responses from Ally
This commit is contained in:
parent
6e504199cc
commit
a383a0535c
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
export.sh
|
||||
.env
|
||||
allyinvest
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
# Default ignored files
|
||||
/workspace.xml
|
8
.idea/allyinvest.iml
Normal file
8
.idea/allyinvest.iml
Normal 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
6
.idea/misc.xml
Normal 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
8
.idea/modules.xml
Normal 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
6
.idea/vcs.xml
Normal 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
35
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)
|
||||
}
|
||||
|
31
types.go
31
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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user