Last active
January 7, 2017 21:00
-
-
Save thomaspeitz/525458fe1bb9f1dcb63bf445a36a1785 to your computer and use it in GitHub Desktop.
bitcoin.de api golang GET example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"encoding/hex" | |
"encoding/json" | |
"fmt" | |
"log" | |
"net/http" | |
"strconv" | |
"time" | |
) | |
func ComputeHmac256(message string, secret string) string { | |
key := []byte(secret) | |
h := hmac.New(sha256.New, key) | |
h.Write([]byte(message)) | |
return hex.EncodeToString(h.Sum(nil)) | |
} | |
type Orders struct { | |
Orders []Order | |
Errors []int | |
Credits int | |
} | |
type Order struct { | |
Order_id string | |
Type string | |
Max_amount float64 | |
Min_amount float64 | |
Price float64 | |
Max_volume float64 | |
Min_volume float64 | |
Order_requirements_fullfilled bool | |
Trading_partner_information | |
Order_requirements | |
} | |
type Trading_partner_information struct { | |
Username string | |
Is_kyc_full bool | |
Trust_level string | |
Bank_name string | |
Bic string | |
Seat_of_bank string | |
Rating int | |
Amount_trades int | |
} | |
type Order_requirements struct { | |
Min_trust_level string | |
Only_kyc_full bool | |
Seat_of_bank []string | |
Payment_option int | |
} | |
func main() { | |
api_key := "" | |
api_secret := "" | |
apihost := "https://api.bitcoin.de" | |
apiversion := "v1" | |
client := &http.Client{} | |
x_api_nonce := strconv.FormatInt(time.Now().UnixNano(), 10) | |
post_hashed := "d41d8cd98f00b204e9800998ecf8427e" | |
orderuri := apihost + "/" + apiversion + "/" + "orders" | |
//tradeuri := apihost + "/" + apiversion + "/" + "trades" | |
//accounturi := apihost + "/" + apiversion + "/" + "account" | |
var method = "GET" | |
var parameters = "type=buy" | |
var url = orderuri + "?" + parameters | |
var encrypt_url = method + "#" + url + "#" + api_key + "#" + x_api_nonce + "#" + post_hashed | |
var x_api_signature = ComputeHmac256(encrypt_url, api_secret) | |
req, _ := http.NewRequest("GET", url, nil) | |
req.Header.Add("X-API-KEY", api_key) | |
req.Header.Add("X-API-NONCE", x_api_nonce) | |
req.Header.Add("X-API-SIGNATURE", x_api_signature) | |
resp, err := client.Do(req) | |
if err != nil { | |
log.Fatal(err) | |
} else { | |
var o Orders | |
defer resp.Body.Close() | |
err := json.NewDecoder(resp.Body).Decode(&o) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for _, order := range o.Orders { | |
fmt.Println(order.Order_id) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment