forked from bitfinexcom/bitfinex-api-go
/
main.go
60 lines (49 loc) · 1.22 KB
/
main.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
package main
import (
"flag"
"log"
"os"
"strconv"
"github.com/venarius/bitfinex-api-go/v2"
"github.com/venarius/bitfinex-api-go/v2/rest"
)
var (
orderid = flag.String("id", "", "lookup trades for an order ID")
api = flag.String("api", "https://api-pub.bitfinex.com/v2/", "v2 REST API URL")
)
// Set BFX_APIKEY and BFX_SECRET as :
//
// export BFX_API_KEY=YOUR_API_KEY
// export BFX_API_SECRET=YOUR_API_SECRET
//
// you can obtain it from https://www.bitfinex.com/api
func main() {
flag.Parse()
key := os.Getenv("BFX_API_KEY")
secret := os.Getenv("BFX_API_SECRET")
c := rest.NewClientWithURL(*api).Credentials(key, secret)
available, err := c.Platform.Status()
if err != nil {
log.Fatalf("getting status: %s", err)
}
if !available {
log.Fatalf("API not available")
}
if *orderid != "" {
ordid, err := strconv.ParseInt(*orderid, 10, 64)
if err != nil {
log.Fatal(err)
}
os, err := c.Orders.OrderTrades(bitfinex.TradingPrefix+bitfinex.BTCUSD, ordid)
if err != nil {
log.Fatalf("getting order trades: %s", err)
}
log.Printf("order trades: %#v\n", os)
} else {
os, err := c.Orders.AllHistory()
if err != nil {
log.Fatalf("getting orders: %s", err)
}
log.Printf("orders: %#v\n", os)
}
}