Skip to content

Commit

Permalink
Fix signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed Sep 11, 2018
1 parent 7314a6d commit 551d485
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
An open source sdk for [Binance exchange](https://www.binance.com) written in Golang. There are endpoints/streams that
are not implemented yet. Feel free to collaborate with me if you need them now :)

**THIS LIBRARY IS NOT READY FOR PRODUCTION YET**

## Installation
After you've configured your local Go package:
```bash
Expand Down
12 changes: 8 additions & 4 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *request) Sign() *request {

func (c *client) Do(request *request) ([]byte, error) {
r, _ := c.createRequest(request)

c.addSignature(request, r)
r.Header.Set("X-MBX-APIKEY", c.apiKey)

client := http.Client{}
Expand All @@ -106,9 +106,6 @@ func (c *client) Do(request *request) ([]byte, error) {
}

func (c *client) createRequest(request *request) (*http.Request, error) {
if request.signed {
request.Param("signature", c.sign(request))
}
if request.method == "GET" {
return c.get(request)
}
Expand All @@ -122,6 +119,13 @@ func (c *client) sign(request *request) string {
return hex.EncodeToString(signature.Sum(nil))
}

func (c *client) addSignature(request *request, httpRequest *http.Request) {
if request.signed {
query := httpRequest.URL.Query()
httpRequest.URL.RawQuery = query.Encode() + "&signature=" + c.sign(request)
}
}

func (c *client) get(request *request) (*http.Request, error) {
parameters := request.parameters.Encode()
return http.NewRequest(request.method, c.baseUrl+request.path + "?" + parameters, nil)
Expand Down

0 comments on commit 551d485

Please sign in to comment.