forked from baibaratsky/go-poloniex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
56 lines (43 loc) · 954 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package poloniex
import (
"time"
"net/http"
"golang.org/x/time/rate"
"gopkg.in/resty.v0"
)
const (
defaultTimeout = 130 * time.Second
maxRequestsPerSecond = 6
)
type Key struct {
Key string
Secret string
}
type Client struct {
keyPool keyPool
resty *resty.Client
limiter *rate.Limiter
}
func NewClient(keys []Key) *Client {
client := Client{
keyPool: keyPool{
keys: make(chan *Key, len(keys)),
},
resty: resty.DefaultClient.SetTimeout(defaultTimeout),
limiter: rate.NewLimiter(maxRequestsPerSecond, 1),
}
for i := range keys {
client.keyPool.Put(&keys[i])
}
return &client
}
func (client *Client) SetTimeout(timeout time.Duration) {
client.resty.SetTimeout(timeout)
}
func (client *Client) SetTransport(transport *http.Transport) {
client.resty.SetTransport(transport)
}
func (client *Client) SetRequestRateLimit(limit rate.Limit) {
client.limiter.SetLimit(limit)
}
type Params map[string]string