Built helper that handles query functions
This commit is contained in:
parent
b816717362
commit
9e4c2a70e5
22
client.go
22
client.go
@ -8,7 +8,9 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* The trading endpoint for Ally */
|
/* The trading endpoint for Ally */
|
||||||
@ -66,6 +68,19 @@ func (c *AllyApi) getAndRead(path string) []byte {
|
|||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Build up our query string, then send it along.
|
||||||
|
*/
|
||||||
|
func (c *AllyApi) getWithParameters(path string, values url.Values) []byte {
|
||||||
|
b := strings.Builder{}
|
||||||
|
for k, v := range values {
|
||||||
|
b.WriteString(fmt.Sprintf("?%s=%s", k, strings.Join(v, ",")))
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Path built: %s%s\n", path, b.String())
|
||||||
|
return c.getAndRead(fmt.Sprintf("%s%s", path, b.String()))
|
||||||
|
}
|
||||||
|
|
||||||
/* The /accounts endpoint of Ally */
|
/* The /accounts endpoint of Ally */
|
||||||
func (c *AllyApi) Accounts() []AccountSummary {
|
func (c *AllyApi) Accounts() []AccountSummary {
|
||||||
var resp AccountResponse
|
var resp AccountResponse
|
||||||
@ -111,6 +126,13 @@ func (c *AllyApi) MarketClock() (resp MarketClockResponse) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *AllyApi) MarketQuotes() {
|
||||||
|
v := url.Values{
|
||||||
|
"symbols": []string{"IBM"},
|
||||||
|
}
|
||||||
|
fmt.Printf("%s\n", c.getWithParameters("market/ext/quotes", v))
|
||||||
|
}
|
||||||
|
|
||||||
// Why does this work?? wtf??
|
// Why does this work?? wtf??
|
||||||
func (c *AllyApi) marshalInterfaceResponse(p string, i interface{}) {
|
func (c *AllyApi) marshalInterfaceResponse(p string, i interface{}) {
|
||||||
resp := c.getAndRead(p)
|
resp := c.getAndRead(p)
|
||||||
|
6
main.go
6
main.go
@ -1,13 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Load our environment variables
|
// Load our environment variables
|
||||||
var api AllyApi
|
var api AllyApi
|
||||||
api.Initialize()
|
api.Initialize()
|
||||||
|
|
||||||
fmt.Printf("Market Clock: %d\n", api.MarketClock().CurrentStatus)
|
api.MarketQuotes()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user