-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.go
78 lines (61 loc) · 1.47 KB
/
models.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
69
70
71
72
73
74
75
76
77
78
package bitbank
import (
"sync"
depth "github.com/go-numb/go-bitbank/v1/depths"
"github.com/go-numb/go-bitbank/v1/ohlcv"
private "github.com/go-numb/go-bitbank/v1/privates"
ticker "github.com/go-numb/go-bitbank/v1/tickers"
transaction "github.com/go-numb/go-bitbank/v1/transactions"
)
const (
PUBLIC_URL = "https://public.bitbank.cc/"
PRIVATE_URL = "https://private.bitbank.cc/"
// API 公式ドキュメントに記載ないため,エラーで判別
// 1mでリミットを設けておく(参考: BitflyerAPI limit)
API_PRIVATE_LIMIT = 200
API_PUBLIC_LIMIT = 500
)
type Client struct {
PublicURL string
PrivateURL string
Transactions *transaction.Request
Depth *depth.Request
Tickers *ticker.Request
OHLCV *ohlcv.Request
Auth *private.Auth
Limit *APILimit
}
func New(token, secret string) *Client {
return &Client{
PublicURL: PUBLIC_URL,
PrivateURL: PRIVATE_URL,
Transactions: &transaction.Request{},
Depth: &depth.Request{},
Tickers: &ticker.Request{},
OHLCV: &ohlcv.Request{},
Auth: private.New(token, secret),
Limit: &APILimit{
Public: API_PUBLIC_LIMIT,
Private: API_PRIVATE_LIMIT,
},
}
}
type APILimit struct {
sync.Mutex
Public int
Private int
}
func (p *APILimit) Sub(isPrivate bool) {
p.Lock()
defer p.Unlock()
if isPrivate {
p.Private--
}
p.Public--
}
func (p *APILimit) Reset() {
p.Lock()
defer p.Unlock()
p.Private = API_PRIVATE_LIMIT
p.Public = API_PUBLIC_LIMIT
}