forked from bitfinexcom/bitfinex-api-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
143 lines (127 loc) · 2.71 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"log"
"os"
"github.com/aopoltorzhicky/bitfinex-api-go/pkg/models/fundingoffer"
"github.com/aopoltorzhicky/bitfinex-api-go/v2/rest"
"github.com/davecgh/go-spew/spew"
)
// Set BFX_API_KEY and BFX_API_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() {
key := os.Getenv("BFX_API_KEY")
secret := os.Getenv("BFX_API_SECRET")
c := rest.NewClient().Credentials(key, secret)
offers(c)
offerHistory(c)
loans(c)
loansHistory(c)
activeCredits(c)
creditsHistory(c)
fundingTrades(c)
keepFunding(c)
/********* submit a new funding offer ***********/
fo, err := c.Funding.SubmitOffer(&fundingoffer.SubmitRequest{
Type: "LIMIT",
Symbol: "fUSD",
Amount: 1000,
Rate: 0.012,
Period: 7,
Hidden: true,
})
if err != nil {
panic(err)
}
newOffer := fo.NotifyInfo.(*fundingoffer.New)
/********* cancel funding offer ***********/
fc, err := c.Funding.CancelOffer(&fundingoffer.CancelRequest{
ID: newOffer.ID,
})
if err != nil {
panic(err)
}
fmt.Println(fc)
}
func offers(c *rest.Client) {
// active funding offers
snap, err := c.Funding.Offers("fUSD")
if err != nil {
panic(err)
}
for _, item := range snap.Snapshot {
fmt.Println(item)
}
}
func offerHistory(c *rest.Client) {
// funding offer history
snapHist, err := c.Funding.OfferHistory("fUSD")
if err != nil {
panic(err)
}
for _, item := range snapHist.Snapshot {
fmt.Println(item)
}
}
func loans(c *rest.Client) {
// active loans
snapLoans, err := c.Funding.Loans("fUSD")
if err != nil {
panic(err)
}
for _, item := range snapLoans.Snapshot {
fmt.Println(item)
}
}
func loansHistory(c *rest.Client) {
napLoansHist, err := c.Funding.LoansHistory("fUSD")
if err != nil {
panic(err)
}
for _, item := range napLoansHist.Snapshot {
fmt.Println(item)
}
}
func activeCredits(c *rest.Client) {
// active credits
snapCredits, err := c.Funding.Credits("fUSD")
if err != nil {
panic(err)
}
for _, item := range snapCredits.Snapshot {
fmt.Println(item)
}
}
func creditsHistory(c *rest.Client) {
napCreditsHist, err := c.Funding.CreditsHistory("fUSD")
if err != nil {
panic(err)
}
for _, item := range napCreditsHist.Snapshot {
fmt.Println(item)
}
}
func fundingTrades(c *rest.Client) {
napTradesHist, err := c.Funding.Trades("fUSD")
if err != nil {
panic(err)
}
for _, item := range napTradesHist.Snapshot {
fmt.Println(item)
}
}
func keepFunding(c *rest.Client) {
// keep funding
resp, err := c.Funding.KeepFunding(rest.KeepFundingRequest{
Type: "credit",
ID: 12345, // Insert correct ID
})
if err != nil {
log.Fatalf("KeepFunding error: %s", err)
}
spew.Dump(resp)
}