forked from bitfinexcom/bitfinex-api-go
/
offers.go
101 lines (73 loc) · 2.03 KB
/
offers.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package bitfinex
import "strconv"
type OffersService struct {
client *Client
}
const (
LEND = "lend"
LOAN = "loan"
)
type Offer struct {
Id int64
Currency string
Rate string
Period int64
Direction string
Timestamp string
IsLive bool `json:"is_live"`
IsCancelled bool `json:"is_cancelled"`
OriginalAmount string `json:"original_amount:string"`
RemainingAmount string `json:"remaining_amount:string"`
ExecutedAmount string `json:"executed_amount:string"`
OfferId int64 `json:"offer_id"`
}
// Create new offer for LEND or LOAN a currency, use LEND or LOAN constants as direction
func (s *OffersService) New(currency string, amount, rate float64, period int64, direction string) (Offer, error) {
payload := map[string]interface{}{
"currency": currency,
"amount": strconv.FormatFloat(amount, 'f', -1, 32),
"rate": strconv.FormatFloat(rate, 'f', -1, 32),
"period": strconv.FormatInt(period, 10),
"direction": direction,
}
req, err := s.client.newAuthenticatedRequest("POST", "offers/new", payload)
if err != nil {
return Offer{}, err
}
var offer = &Offer{}
_, err = s.client.do(req, offer)
if err != nil {
return Offer{}, err
}
return *offer, nil
}
func (s *OffersService) Cancel(offerId int64) (Offer, error) {
payload := map[string]interface{}{
"offer_id": strconv.FormatInt(offerId, 10),
}
req, err := s.client.newAuthenticatedRequest("POST", "offers/cancel", payload)
if err != nil {
return Offer{}, err
}
var offer = &Offer{}
_, err = s.client.do(req, offer)
if err != nil {
return Offer{}, err
}
return *offer, nil
}
func (s *OffersService) Status(offerId int64) (Offer, error) {
payload := map[string]interface{}{
"offer_id": strconv.FormatInt(offerId, 10),
}
req, err := s.client.newAuthenticatedRequest("POST", "offers/status", payload)
if err != nil {
return Offer{}, err
}
var offer = &Offer{}
_, err = s.client.do(req, offer)
if err != nil {
return Offer{}, err
}
return *offer, nil
}