Skip to content

Instantly share code, notes, and snippets.

@coldfire-x
Last active December 12, 2015 02:49
Show Gist options
  • Save coldfire-x/4702191 to your computer and use it in GitHub Desktop.
Save coldfire-x/4702191 to your computer and use it in GitHub Desktop.
get my stock price
package main
import (
"fmt"
"time"
"net/http"
"encoding/json"
"io/ioutil"
)
func getPrices(codes []string) {
url := "http://cj.gw.com.cn/stockHq.php"
timestamp := time.Now().UnixNano() / 10e5
url = fmt.Sprintf("%s?&_=%d&code=", url, timestamp)
for _, stock := range codes {
url += stock + ";"
}
//fmt.Println(url)
respose, err := http.Get(url)
defer respose.Body.Close()
if err != nil {
fmt.Println("Something Wrong happened!")
}
body, _ := ioutil.ReadAll(respose.Body)
//fmt.Printf("%v", string(body))
var m []interface{}
json.Unmarshal(body, &m)
// fmt.Println(m)
for _, v := range m {
k := v.(map[string]interface{})
fmt.Printf("%s%8s%8s\n", k["name"], k["lp"], k["zf"])
}
}
func main() {
stockCodes := []string{"SZ002151", "SH600118"}
//fmt.Println(stockCodes)
getPrices(stockCodes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment