-
Notifications
You must be signed in to change notification settings - Fork 76
/
bitfinex.go
73 lines (60 loc) · 1.34 KB
/
bitfinex.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
// Package bitfinex bitfinex rest api
package bitfinex
import (
"strconv"
"strings"
"github.com/Akagi201/cryptotrader/model"
bitfinex "github.com/bitfinexcom/bitfinex-api-go/v1"
)
// Bitfinex API data
type Bitfinex struct {
bitfinex.Client
}
// New create new Allcoin API data
func New(accessKey string, secretKey string) *Bitfinex {
var client *bitfinex.Client
if accessKey != "" && secretKey != "" {
client = bitfinex.NewClient().Auth(accessKey, secretKey)
} else {
client = bitfinex.NewClient()
}
return &Bitfinex{
*client,
}
}
// GetTicker 行情
func (bf *Bitfinex) GetTicker(base string, quote string) (*model.Ticker, error) {
tick, err := bf.Ticker.Get(strings.ToUpper(quote) + strings.ToUpper(base))
buy, err := strconv.ParseFloat(tick.Bid, 64)
if err != nil {
return nil, err
}
sell, err := strconv.ParseFloat(tick.Ask, 64)
if err != nil {
return nil, err
}
last, err := strconv.ParseFloat(tick.LastPrice, 64)
if err != nil {
return nil, err
}
low, err := strconv.ParseFloat(tick.Low, 64)
if err != nil {
return nil, err
}
high, err := strconv.ParseFloat(tick.High, 64)
if err != nil {
return nil, err
}
vol, err := strconv.ParseFloat(tick.Volume, 64)
if err != nil {
return nil, err
}
return &model.Ticker{
Buy: buy,
Sell: sell,
Last: last,
Low: low,
High: high,
Vol: vol,
}, nil
}