/
positions.go
73 lines (58 loc) · 1.26 KB
/
positions.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
import (
"strconv"
"time"
)
// PositionsService structure
type PositionsService struct {
client *Client
}
// Position structure
type Position struct {
ID int
Symbol string
Amount string
Status string
Base string
Timestamp string
Swap string
Pl string
}
func (p *Position) ParseTime() (*time.Time, error) {
i, err := strconv.ParseFloat(p.Timestamp, 64)
if err != nil {
return nil, err
}
t := time.Unix(int64(i), 0)
return &t, nil
}
// All - gets all positions
func (b *PositionsService) All() ([]Position, error) {
req, err := b.client.newAuthenticatedRequest("POST", "positions", nil)
if err != nil {
return nil, err
}
var positions []Position
_, err = b.client.do(req, &positions)
if err != nil {
return nil, err
}
return positions, nil
}
// Claim a position
func (b *PositionsService) Claim(positionId int, amount string) (Position, error) {
request := map[string]interface{}{
"position_id": positionId,
"amount": amount,
}
req, err := b.client.newAuthenticatedRequest("POST", "position/claim", request)
if err != nil {
return Position{}, err
}
var position = &Position{}
_, err = b.client.do(req, position)
if err != nil {
return Position{}, err
}
return *position, nil
}