2019-11-08 04:30:22 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-11-14 21:46:16 +00:00
|
|
|
"encoding/xml"
|
2019-11-08 04:30:22 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
2019-11-14 21:46:16 +00:00
|
|
|
"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() {
|
2019-11-14 21:46:16 +00:00
|
|
|
// 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(
|
2019-11-14 21:46:16 +00:00
|
|
|
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
|
2019-11-14 21:46:16 +00:00
|
|
|
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
|
|
|
|
2019-11-14 21:46:16 +00:00
|
|
|
var acctSummary AllyResponse
|
|
|
|
err = xml.Unmarshal(b, &acctSummary)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%s\n", b)
|
2019-11-15 02:15:47 +00:00
|
|
|
fmt.Printf("%s\n", acctSummary.Accounts[0].Balance.Money.AccruedInterest)
|
2019-11-08 04:30:22 +00:00
|
|
|
}
|