Beispiel #1
0
func (client Client) postRequest(
	path string, params map[string]interface{}, result interface{}) (err error) {

	params["request"] = "/v1/" + path
	paramJson, err := json.Marshal(params)
	if err != nil {
		return
	}
	payload := base64.StdEncoding.EncodeToString(paramJson)

	mac := hmac.New(sha512.New384, []byte(client.apiSecret))
	mac.Write([]byte(payload))
	signature := hex.EncodeToString(mac.Sum(nil))

	req, err := http.NewRequest("POST", API_URL+path, strings.NewReader(""))
	if err != nil {
		return
	}
	req.Header.Set("X-BFX-APIKEY", client.apiKey)
	req.Header.Set("X-BFX-PAYLOAD", payload)
	req.Header.Set("X-BFX-SIGNATURE", signature)

	var httpClient http.Client
	resp, err := httpClient.Do(req)
	if err != nil {
		return
	}
	err = bitcoin.JsonParse(resp.Body, result)
	return
}
Beispiel #2
0
func (client Client) postRequest(
	method string, params url.Values, result interface{}) (err error) {

	params.Set("method", method)
	paramString := params.Encode()

	mac := hmac.New(sha512.New, []byte(client.apiSecret))
	mac.Write([]byte(paramString))
	signature := hex.EncodeToString(mac.Sum(nil))

	req, err := http.NewRequest("POST", TAPI_URL, strings.NewReader(paramString))
	if err != nil {
		return
	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Set("Key", client.apiKey)
	req.Header.Set("Sign", signature)

	var httpClient http.Client
	resp, err := httpClient.Do(req)
	if err != nil {
		return
	}
	err = bitcoin.JsonParse(resp.Body, result)
	return
}
Beispiel #3
0
func (client *Client) getRequest(path string, result interface{}) (err error) {
	resp, err := http.Get(API_URL + path)
	if err != nil {
		return
	}
	err = bitcoin.JsonParse(resp.Body, result)
	return
}
Beispiel #4
0
func postRequest(path string, params url.Values, result interface{}) (err error) {
	resp, err := http.PostForm(API_URL+path, params)
	if err != nil {
		return
	}
	err = bitcoin.JsonParse(resp.Body, result)
	return
}
Beispiel #5
0
func (client *Client) postRequest(
	path string, params url.Values, result interface{}) (err error) {

	client.nonce++
	nonce := fmt.Sprintf("%v", client.nonce)
	params.Set("nonce", nonce)
	data := params.Encode()

	req, err := http.NewRequest("POST", API_URL+path, strings.NewReader(data))

	secret, err := base64.StdEncoding.DecodeString(client.apiSecret)
	mac := hmac.New(sha512.New, secret)
	nonceData256 := sha256.Sum256([]byte(nonce + string(data)))

	mac.Write([]byte(path + string(nonceData256[:32])))

	signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))

	req.Header.Set("API-Key", client.apiKey)
	req.Header.Set("API-Sign", signature)

	var httpClient http.Client
	resp, err := httpClient.Do(req)
	if err != nil {
		return
	}
	err = bitcoin.JsonParse(resp.Body, result)
	if err != nil {
		return
	}

	resultValue := reflect.ValueOf(result)
	error := (resultValue.Elem().FieldByName("Error").Interface()).([]string)
	if len(error) > 0 {
		err = errors.New(strings.Join(error, "; "))
	}

	return
}