Skip to content

Commit bfd300f

Browse files
committed
Update
1 parent 4db239d commit bfd300f

File tree

17 files changed

+174
-52
lines changed

17 files changed

+174
-52
lines changed

examples/hbdm-demo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
AccessKey: accessKey,
1717
SecretKey: secretKey,
1818
EnablePrivateSign: false,
19-
Url: baseURL,
19+
BaseURL: baseURL,
2020
PrivateKeyPrime256: "",
2121
}
2222
client := hbdm.NewClient(apiParams)

examples/hbdmswap-demo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func main() {
1616
AccessKey: accessKey,
1717
SecretKey: secretKey,
1818
EnablePrivateSign: false,
19-
Url: baseURL,
19+
BaseURL: baseURL,
2020
PrivateKeyPrime256: "",
2121
}
2222
client := hbdmswap.NewClient(apiParams)

hbdm/hbdm.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package hbdm
22

33
import (
44
"fmt"
5-
"github.com/frankrap/huobi-api/util"
5+
"github.com/frankrap/huobi-api/utils"
66
"log"
77
"net/http"
88
"net/url"
@@ -19,7 +19,7 @@ type ApiParameter struct {
1919
AccessKey string
2020
SecretKey string
2121
EnablePrivateSign bool
22-
Url string
22+
BaseURL string
2323
PrivateKeyPrime256 string
2424
HttpClient *http.Client
2525
ProxyURL string
@@ -33,7 +33,7 @@ type Client struct {
3333

3434
func (c *Client) Heartbeat() (result HeartbeatResult, err error) {
3535
var resp []byte
36-
resp, err = util.HttpGet(c.httpClient, "https://www.hbdm.com/heartbeat/", "", nil)
36+
resp, err = utils.HttpGet(c.httpClient, "https://www.hbdm.com/heartbeat/", "", nil)
3737
if err != nil {
3838
return
3939
}
@@ -42,8 +42,8 @@ func (c *Client) Heartbeat() (result HeartbeatResult, err error) {
4242
}
4343

4444
func (c *Client) doGet(path string, params *url.Values, result interface{}) (resp []byte, err error) {
45-
url := c.params.Url + path + "?" + params.Encode()
46-
resp, err = util.HttpGet(
45+
url := c.params.BaseURL + path + "?" + params.Encode()
46+
resp, err = utils.HttpGet(
4747
c.httpClient,
4848
url,
4949
"",
@@ -67,10 +67,10 @@ func (c *Client) doGet(path string, params *url.Values, result interface{}) (res
6767

6868
func (c *Client) doPost(path string, params *url.Values, result interface{}) (resp []byte, err error) {
6969
c.sign("POST", path, params)
70-
jsonD, _ := util.ValuesToJson(*params)
70+
jsonD, _ := utils.ValuesToJson(*params)
7171

72-
url := c.params.Url + path + "?" + params.Encode()
73-
resp, err = util.HttpPost(
72+
url := c.params.BaseURL + path + "?" + params.Encode()
73+
resp, err = utils.HttpPost(
7474
c.httpClient,
7575
url,
7676
string(jsonD),
@@ -102,23 +102,16 @@ func (c *Client) sign(reqMethod, path string, postForm *url.Values) error {
102102
c.domain,
103103
path,
104104
postForm.Encode())
105-
signature, _ := util.GetParamHmacSHA256Base64Sign(c.params.SecretKey, payload)
105+
signature, _ := utils.GetParamHmacSHA256Base64Sign(c.params.SecretKey, payload)
106106
postForm.Set("Signature", signature)
107107
return nil
108108
}
109109

110110
func NewClient(params *ApiParameter) *Client {
111-
domain := strings.Replace(params.Url, "https://", "", -1)
111+
domain := strings.Replace(params.BaseURL, "https://", "", -1)
112112
httpClient := params.HttpClient
113113
if httpClient == nil {
114-
transport := util.CloneDefaultTransport()
115-
if params.ProxyURL != "" {
116-
transport.Proxy, _ = util.ParseProxy(params.ProxyURL)
117-
}
118-
httpClient = &http.Client{
119-
Timeout: 10 * time.Second,
120-
Transport: transport,
121-
}
114+
httpClient = utils.DefaultHttpClient(params.ProxyURL)
122115
}
123116
return &Client{
124117
params: params,

hbdm/hbdm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newTestClient() *Client {
2424
AccessKey: accessKey,
2525
SecretKey: secretKey,
2626
EnablePrivateSign: false,
27-
Url: baseURL,
27+
BaseURL: baseURL,
2828
PrivateKeyPrime256: "",
2929
}
3030
c := NewClient(apiParams)

hbdm/nws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package hbdm
66
import (
77
"context"
88
"fmt"
9-
"github.com/frankrap/huobi-api/util"
9+
"github.com/frankrap/huobi-api/utils"
1010
"github.com/lithammer/shortuuid/v3"
1111
"github.com/recws-org/recws"
1212
"github.com/tidwall/gjson"
@@ -147,7 +147,7 @@ func (ws *NWS) setSignatureData(data map[string]string, apiKey, apiSecretKey str
147147
return err
148148
}
149149
payload := fmt.Sprintf("%s\n%s\n%s\n%s", "GET", u.Host, u.Path, postForm.Encode())
150-
sign, _ := util.GetParamHmacSHA256Base64Sign(apiSecretKey, payload)
150+
sign, _ := utils.GetParamHmacSHA256Base64Sign(apiSecretKey, payload)
151151
data["Signature"] = sign
152152
return nil
153153
}
@@ -247,7 +247,7 @@ func (ws *NWS) run() {
247247
continue
248248
}
249249

250-
msg, err = util.GzipUncompress(msg)
250+
msg, err = utils.GzipUncompress(msg)
251251
if err != nil {
252252
continue
253253
}

hbdm/ws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package hbdm
66
import (
77
"context"
88
"fmt"
9-
"github.com/frankrap/huobi-api/util"
9+
"github.com/frankrap/huobi-api/utils"
1010
"github.com/lithammer/shortuuid/v3"
1111
"github.com/recws-org/recws"
1212
"github.com/tidwall/gjson"
@@ -173,7 +173,7 @@ func (ws *WS) run() {
173173
continue
174174
}
175175

176-
msg, err = util.GzipUncompress(msg)
176+
msg, err = utils.GzipUncompress(msg)
177177
if err != nil {
178178
continue
179179
}

hbdmswap/hbdmswap.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package hbdmswap
22

33
import (
44
"fmt"
5-
"github.com/frankrap/huobi-api/util"
5+
"github.com/frankrap/huobi-api/utils"
66
"log"
77
"net/http"
88
"net/url"
@@ -19,7 +19,7 @@ type ApiParameter struct {
1919
AccessKey string
2020
SecretKey string
2121
EnablePrivateSign bool
22-
Url string
22+
BaseURL string
2323
PrivateKeyPrime256 string
2424
HttpClient *http.Client
2525
ProxyURL string
@@ -33,7 +33,7 @@ type Client struct {
3333

3434
func (c *Client) Heartbeat() (result HeartbeatResult, err error) {
3535
var resp []byte
36-
resp, err = util.HttpGet(c.httpClient, "https://www.hbdm.com/heartbeat/", "", nil)
36+
resp, err = utils.HttpGet(c.httpClient, "https://www.hbdm.com/heartbeat/", "", nil)
3737
if err != nil {
3838
return
3939
}
@@ -42,8 +42,8 @@ func (c *Client) Heartbeat() (result HeartbeatResult, err error) {
4242
}
4343

4444
func (c *Client) doGet(path string, params *url.Values, result interface{}) (resp []byte, err error) {
45-
url := c.params.Url + path + "?" + params.Encode()
46-
resp, err = util.HttpGet(
45+
url := c.params.BaseURL + path + "?" + params.Encode()
46+
resp, err = utils.HttpGet(
4747
c.httpClient,
4848
url,
4949
"",
@@ -67,10 +67,10 @@ func (c *Client) doGet(path string, params *url.Values, result interface{}) (res
6767

6868
func (c *Client) doPost(path string, params *url.Values, result interface{}) (resp []byte, err error) {
6969
c.sign("POST", path, params)
70-
jsonD, _ := util.ValuesToJson(*params)
70+
jsonD, _ := utils.ValuesToJson(*params)
7171

72-
url := c.params.Url + path + "?" + params.Encode()
73-
resp, err = util.HttpPost(
72+
url := c.params.BaseURL + path + "?" + params.Encode()
73+
resp, err = utils.HttpPost(
7474
c.httpClient,
7575
url,
7676
string(jsonD),
@@ -103,23 +103,16 @@ func (c *Client) sign(reqMethod, path string, postForm *url.Values) error {
103103
path,
104104
postForm.Encode(),
105105
)
106-
signature, _ := util.GetParamHmacSHA256Base64Sign(c.params.SecretKey, payload)
106+
signature, _ := utils.GetParamHmacSHA256Base64Sign(c.params.SecretKey, payload)
107107
postForm.Set("Signature", signature)
108108
return nil
109109
}
110110

111111
func NewClient(params *ApiParameter) *Client {
112-
domain := strings.Replace(params.Url, "https://", "", -1)
112+
domain := strings.Replace(params.BaseURL, "https://", "", -1)
113113
httpClient := params.HttpClient
114114
if httpClient == nil {
115-
transport := util.CloneDefaultTransport()
116-
if params.ProxyURL != "" {
117-
transport.Proxy, _ = util.ParseProxy(params.ProxyURL)
118-
}
119-
httpClient = &http.Client{
120-
Timeout: 10 * time.Second,
121-
Transport: transport,
122-
}
115+
httpClient = utils.DefaultHttpClient(params.ProxyURL)
123116
}
124117
return &Client{
125118
params: params,

hbdmswap/hbdmswap_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newTestClient() *Client {
2424
AccessKey: accessKey,
2525
SecretKey: secretKey,
2626
EnablePrivateSign: false,
27-
Url: baseURL,
27+
BaseURL: baseURL,
2828
PrivateKeyPrime256: "",
2929
}
3030
c := NewClient(apiParams)

hbdmswap/nws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package hbdmswap
66
import (
77
"context"
88
"fmt"
9-
"github.com/frankrap/huobi-api/util"
9+
"github.com/frankrap/huobi-api/utils"
1010
"github.com/lithammer/shortuuid/v3"
1111
"github.com/recws-org/recws"
1212
"github.com/tidwall/gjson"
@@ -139,7 +139,7 @@ func (ws *NWS) setSignatureData(data map[string]string, apiKey, apiSecretKey str
139139
return err
140140
}
141141
payload := fmt.Sprintf("%s\n%s\n%s\n%s", "GET", u.Host, u.Path, postForm.Encode())
142-
sign, _ := util.GetParamHmacSHA256Base64Sign(apiSecretKey, payload)
142+
sign, _ := utils.GetParamHmacSHA256Base64Sign(apiSecretKey, payload)
143143
data["Signature"] = sign
144144
return nil
145145
}
@@ -235,7 +235,7 @@ func (ws *NWS) run() {
235235
continue
236236
}
237237

238-
msg, err = util.GzipUncompress(msg)
238+
msg, err = utils.GzipUncompress(msg)
239239
if err != nil {
240240
continue
241241
}

hbdmswap/ws.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package hbdmswap
66
import (
77
"context"
88
"fmt"
9-
"github.com/frankrap/huobi-api/util"
9+
"github.com/frankrap/huobi-api/utils"
1010
"github.com/recws-org/recws"
1111
"github.com/tidwall/gjson"
1212
"log"
@@ -166,7 +166,7 @@ func (ws *WS) run() {
166166
continue
167167
}
168168

169-
msg, err = util.GzipUncompress(msg)
169+
msg, err = utils.GzipUncompress(msg)
170170
if err != nil {
171171
continue
172172
}

0 commit comments

Comments
 (0)