Skip to content

Instantly share code, notes, and snippets.

@yubing24
Last active June 22, 2018 16:46
Show Gist options
  • Save yubing24/f836ac55325ada76feba37bd5d1ebc54 to your computer and use it in GitHub Desktop.
Save yubing24/f836ac55325ada76feba37bd5d1ebc54 to your computer and use it in GitHub Desktop.
Pay attention to the type of returned json data, as well as gzip?
package main
import (
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"net/http"
"os"
)
type poloniexData struct {
GlobalTradeID int `json:"globalTradeID"`
TradeID int `json:"tradeID"`
Date string `json:"date"`
Types string `json:"type"`
Rate string `json:"rate"`
Amount string `json:"amount"`
Total string `json:"total"`
}
func main() {
// Build the request
url := "https://poloniex.com/public?command=returnTradeHistory&currencyPair=BTC_NXT&start=1410158341&end=1410499372"
req, _:= http.NewRequest(http.MethodGet, url, nil)
req.Header.Add("Accept-Encoding", "gzip")
client := new(http.Client)
res, _ := client.Do(req)
defer res.Body.Close()
reader, _ := gzip.NewReader(res.Body)
buffer := new(bytes.Buffer)
buffer.ReadFrom(reader)
content := buffer.Bytes()
var data [] poloniexData
json.Unmarshal(content, &data)
fmt.Printf("Results: %v\n", data)
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment