-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_exchange.go
68 lines (52 loc) · 1.36 KB
/
crypto_exchange.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
57
58
59
60
61
62
63
64
65
66
67
68
package crypto_exchange
import (
"net/http"
"sync"
)
type CryptoExchange int
type DefaultCryptoExchangeClient struct {
mu sync.Mutex
client *http.Client
accessKey string
secretKey string
UpbitService *UpbitService
}
type service struct {
client *http.Client
baseURL string
accessKey string
secretKey string
}
type Option func(*DefaultCryptoExchangeClient)
// NewClient returns a new http client and cryptocurrency exchange services.
// In order to use APIs that need authentication, AccessKey and SecretKey must be provided.
func NewClient(httpClient *http.Client, opts ...Option) *DefaultCryptoExchangeClient {
if httpClient == nil {
httpClient = &http.Client{}
}
client := &DefaultCryptoExchangeClient{
client: httpClient,
}
for _, opt := range opts {
opt(client)
}
client.UpbitService = newUpbitService(client.copyHTTPClient(), client.accessKey, client.secretKey)
return client
}
func WithAccessKey(accessKey string) Option {
return func(c *DefaultCryptoExchangeClient) {
c.accessKey = accessKey
}
}
func WithSecretKey(secretKey string) Option {
return func(c *DefaultCryptoExchangeClient) {
c.secretKey = secretKey
}
}
// copyHTTPClient returns the client use by DefaultClient
func (c *DefaultCryptoExchangeClient) copyHTTPClient() *http.Client {
c.mu.Lock()
defer c.mu.Unlock()
copiedClient := *c.client
return &copiedClient
}