allyinvest/main.go

54 lines
1.2 KiB
Go
Raw Normal View History

2019-11-08 04:30:22 +00:00
package main
import (
"encoding/xml"
2019-11-08 04:30:22 +00:00
"fmt"
"io/ioutil"
"os"
"github.com/joho/godotenv"
2019-11-08 04:30:22 +00:00
"github.com/mrjones/oauth"
)
var endpoint string = "https://api.tradeking.com/v1/"
func main() {
// Load our environment variables
err := godotenv.Load()
if err != nil {
panic(err)
2019-11-08 04:30:22 +00:00
}
// Set up our new oauth consumer
cons := oauth.NewConsumer(
os.Getenv("CONSUMER_KEY"),
os.Getenv("CONSUMER_SECRET"),
2019-11-08 04:30:22 +00:00
oauth.ServiceProvider{
RequestTokenUrl: "https://developers.tradeking.com/oauth/request_token",
AuthorizeTokenUrl: "https://developers.tradeking.com/oauth/authorize",
AccessTokenUrl: "https://developers.tradeking.com/oauth/access_token",
},
)
// Set up our HTTP client
client, err := cons.MakeHttpClient(&oauth.AccessToken{Token: os.Getenv("ACCESS_TOKEN"), Secret: os.Getenv("ACCESS_SECRET")})
2019-11-08 04:30:22 +00:00
if err != nil {
panic(err)
}
resp, err := client.Get(fmt.Sprintf("%s\\%s", endpoint, "accounts"))
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
2019-11-09 03:26:17 +00:00
var acctSummary AllyResponse
err = xml.Unmarshal(b, &acctSummary)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", b)
fmt.Printf("%s\n", acctSummary.Accounts[0].Balance.Money.AccruedInterest)
2019-11-08 04:30:22 +00:00
}