forked from thrasher-corp/gocryptotrader
/
bitfinex.go
644 lines (543 loc) · 20.8 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
package bitfinex
import (
"errors"
"fmt"
"log"
"net/url"
"strconv"
"strings"
"time"
"github.com/gorilla/websocket"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
const (
bitfinexAPIURL = "https://api.bitfinex.com/v1/"
bitfinexAPIVersion = "1"
bitfinexTicker = "pubticker/"
bitfinexStats = "stats/"
bitfinexLendbook = "lendbook/"
bitfinexOrderbook = "book/"
bitfinexTrades = "trades/"
bitfinexKeyPermissions = "key_info"
bitfinexLends = "lends/"
bitfinexSymbols = "symbols/"
bitfinexSymbolsDetails = "symbols_details/"
bitfinexAccountInfo = "account_infos"
bitfinexAccountFees = "account_fees"
bitfinexAccountSummary = "summary"
bitfinexDeposit = "deposit/new"
bitfinexOrderNew = "order/new"
bitfinexOrderNewMulti = "order/new/multi"
bitfinexOrderCancel = "order/cancel"
bitfinexOrderCancelMulti = "order/cancel/multi"
bitfinexOrderCancelAll = "order/cancel/all"
bitfinexOrderCancelReplace = "order/cancel/replace"
bitfinexOrderStatus = "order/status"
bitfinexOrders = "orders"
bitfinexPositions = "positions"
bitfinexClaimPosition = "position/claim"
bitfinexHistory = "history"
bitfinexHistoryMovements = "history/movements"
bitfinexTradeHistory = "mytrades"
bitfinexOfferNew = "offer/new"
bitfinexOfferCancel = "offer/cancel"
bitfinexOfferStatus = "offer/status"
bitfinexOffers = "offers"
bitfinexMarginActiveFunds = "taken_funds"
bitfinexMarginTotalFunds = "total_taken_funds"
bitfinexMarginUnusedFunds = "unused_taken_funds"
bitfinexMarginClose = "funding/close"
bitfinexBalances = "balances"
bitfinexMarginInfo = "margin_infos"
bitfinexTransfer = "transfer"
bitfinexWithdrawal = "withdraw"
bitfinexActiveCredits = "credits"
// bitfinexMaxRequests if exceeded IP address blocked 10-60 sec, JSON response
// {"error": "ERR_RATE_LIMIT"}
bitfinexMaxRequests = 90
)
// Bitfinex is the overarching type across the bitfinex package
// Notes: Bitfinex has added a rate limit to the number of REST requests.
// Rate limit policy can vary in a range of 10 to 90 requests per minute
// depending on some factors (e.g. servers load, endpoint, etc.).
type Bitfinex struct {
exchange.Base
WebsocketConn *websocket.Conn
WebsocketSubdChannels map[int]WebsocketChanInfo
}
// SetDefaults sets the basic defaults for bitfinex
func (b *Bitfinex) SetDefaults() {
b.Name = "Bitfinex"
b.Enabled = false
b.Verbose = false
b.Websocket = false
b.RESTPollingDelay = 10
b.WebsocketSubdChannels = make(map[int]WebsocketChanInfo)
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
b.AssetTypes = []string{ticker.Spot}
}
// Setup takes in the supplied exchange configuration details and sets params
func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
if !exch.Enabled {
b.SetEnabled(false)
} else {
b.Enabled = true
b.AuthenticatedAPISupport = exch.AuthenticatedAPISupport
b.SetAPIKeys(exch.APIKey, exch.APISecret, "", false)
b.RESTPollingDelay = exch.RESTPollingDelay
b.Verbose = exch.Verbose
b.Websocket = exch.Websocket
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
err = b.SetAssetTypes()
if err != nil {
log.Fatal(err)
}
}
}
// GetTicker returns ticker information
func (b *Bitfinex) GetTicker(symbol string, values url.Values) (Ticker, error) {
response := Ticker{}
path := common.EncodeURLValues(bitfinexAPIURL+bitfinexTicker+symbol, values)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetStats returns various statistics about the requested pair
func (b *Bitfinex) GetStats(symbol string) ([]Stat, error) {
response := []Stat{}
path := fmt.Sprint(bitfinexAPIURL + bitfinexStats + symbol)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetFundingBook the entire margin funding book for both bids and asks sides
// per currency string
// symbol - example "USD"
func (b *Bitfinex) GetFundingBook(symbol string) (FundingBook, error) {
response := FundingBook{}
path := fmt.Sprint(bitfinexAPIURL + bitfinexLendbook + symbol)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetOrderbook retieves the orderbook bid and ask price points for a currency
// pair - By default the response will return 25 bid and 25 ask price points.
// CurrencyPair - Example "BTCUSD"
// Values can contain limit amounts for both the asks and bids - Example
// "limit_bids" = 1000
func (b *Bitfinex) GetOrderbook(currencyPair string, values url.Values) (Orderbook, error) {
response := Orderbook{}
path := common.EncodeURLValues(
bitfinexAPIURL+bitfinexOrderbook+currencyPair,
values,
)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetTrades returns a list of the most recent trades for the given curencyPair
// By default the response will return 100 trades
// CurrencyPair - Example "BTCUSD"
// Values can contain limit amounts for the number of trades returned - Example
// "limit_trades" = 1000
func (b *Bitfinex) GetTrades(currencyPair string, values url.Values) ([]TradeStructure, error) {
response := []TradeStructure{}
path := common.EncodeURLValues(
bitfinexAPIURL+bitfinexTrades+currencyPair,
values,
)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetLendbook returns a list of the most recent funding data for the given
// currency: total amount provided and Flash Return Rate (in % by 365 days) over
// time
// Symbol - example "USD"
func (b *Bitfinex) GetLendbook(symbol string, values url.Values) (Lendbook, error) {
response := Lendbook{}
if len(symbol) == 6 {
symbol = symbol[:3]
}
path := common.EncodeURLValues(bitfinexAPIURL+bitfinexLendbook+symbol, values)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetLends returns a list of the most recent funding data for the given
// currency: total amount provided and Flash Return Rate (in % by 365 days)
// over time
// Symbol - example "USD"
func (b *Bitfinex) GetLends(symbol string, values url.Values) ([]Lends, error) {
response := []Lends{}
path := common.EncodeURLValues(bitfinexAPIURL+bitfinexLends+symbol, values)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetSymbols returns the available currency pairs on the exchange
func (b *Bitfinex) GetSymbols() ([]string, error) {
products := []string{}
path := fmt.Sprint(bitfinexAPIURL + bitfinexSymbols)
return products, common.SendHTTPGetRequest(path, true, b.Verbose, &products)
}
// GetSymbolsDetails a list of valid symbol IDs and the pair details
func (b *Bitfinex) GetSymbolsDetails() ([]SymbolDetails, error) {
response := []SymbolDetails{}
path := fmt.Sprint(bitfinexAPIURL + bitfinexSymbolsDetails)
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
}
// GetAccountInfo returns information about your account incl. trading fees
func (b *Bitfinex) GetAccountInfo() ([]AccountInfo, error) {
response := []AccountInfo{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexAccountInfo, nil, &response)
}
// GetAccountFees - NOT YET IMPLEMENTED
func (b *Bitfinex) GetAccountFees() (AccountFees, error) {
response := AccountFees{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexAccountFees, nil, &response)
}
// GetAccountSummary returns a 30-day summary of your trading volume and return
// on margin funding
func (b *Bitfinex) GetAccountSummary() (AccountSummary, error) {
response := AccountSummary{}
return response,
b.SendAuthenticatedHTTPRequest(
"POST", bitfinexAccountSummary, nil, &response,
)
}
// NewDeposit returns a new deposit address
// Method - Example methods accepted: “bitcoin”, “litecoin”, “ethereum”,
//“tethers", "ethereumc", "zcash", "monero", "iota", "bcash"
// WalletName - accepted: “trading”, “exchange”, “deposit”
// renew - Default is 0. If set to 1, will return a new unused deposit address
func (b *Bitfinex) NewDeposit(method, walletName string, renew int) (DepositResponse, error) {
response := DepositResponse{}
request := make(map[string]interface{})
request["method"] = method
request["wallet_name"] = walletName
request["renew"] = renew
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexDeposit, request, &response)
}
// GetKeyPermissions checks the permissions of the key being used to generate
// this request.
func (b *Bitfinex) GetKeyPermissions() (KeyPermissions, error) {
response := KeyPermissions{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexKeyPermissions, nil, &response)
}
// GetMarginInfo shows your trading wallet information for margin trading
func (b *Bitfinex) GetMarginInfo() ([]MarginInfo, error) {
response := []MarginInfo{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexMarginInfo, nil, &response)
}
// GetAccountBalance returns full wallet balance information
func (b *Bitfinex) GetAccountBalance() ([]Balance, error) {
response := []Balance{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexBalances, nil, &response)
}
// WalletTransfer move available balances between your wallets
// Amount - Amount to move
// Currency - example "BTC"
// WalletFrom - example "exchange"
// WalletTo - example "deposit"
func (b *Bitfinex) WalletTransfer(amount float64, currency, walletFrom, walletTo string) ([]WalletTransfer, error) {
response := []WalletTransfer{}
request := make(map[string]interface{})
request["amount"] = amount
request["currency"] = currency
request["walletfrom"] = walletFrom
request["walletTo"] = walletTo
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexTransfer, request, &response)
}
// Withdrawal requests a withdrawal from one of your wallets.
// Major Upgrade needed on this function to include all query params
func (b *Bitfinex) Withdrawal(withdrawType, wallet, address string, amount float64) ([]Withdrawal, error) {
response := []Withdrawal{}
request := make(map[string]interface{})
request["withdrawal_type"] = withdrawType
request["walletselected"] = wallet
request["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
request["address"] = address
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexWithdrawal, request, &response)
}
// NewOrder submits a new order and returns a order information
// Major Upgrade needed on this function to include all query params
func (b *Bitfinex) NewOrder(currencyPair string, amount float64, price float64, buy bool, Type string, hidden bool) (Order, error) {
response := Order{}
request := make(map[string]interface{})
request["symbol"] = currencyPair
request["amount"] = strconv.FormatFloat(amount, 'f', -1, 64)
request["price"] = strconv.FormatFloat(price, 'f', -1, 64)
request["exchange"] = "bitfinex"
request["type"] = Type
request["is_hidden"] = hidden
if buy {
request["side"] = "buy"
} else {
request["side"] = "sell"
}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderNew, request, &response)
}
// NewOrderMulti allows several new orders at once
func (b *Bitfinex) NewOrderMulti(orders []PlaceOrder) (OrderMultiResponse, error) {
response := OrderMultiResponse{}
request := make(map[string]interface{})
request["orders"] = orders
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderNewMulti, request, &response)
}
// CancelOrder cancels a single order
func (b *Bitfinex) CancelOrder(OrderID int64) (Order, error) {
response := Order{}
request := make(map[string]interface{})
request["order_id"] = OrderID
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderCancel, request, &response)
}
// CancelMultipleOrders cancels multiple orders
func (b *Bitfinex) CancelMultipleOrders(OrderIDs []int64) (string, error) {
response := GenericResponse{}
request := make(map[string]interface{})
request["order_ids"] = OrderIDs
return response.Result,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderCancelMulti, request, nil)
}
// CancelAllOrders cancels all active and open orders
func (b *Bitfinex) CancelAllOrders() (string, error) {
response := GenericResponse{}
return response.Result,
b.SendAuthenticatedHTTPRequest("GET", bitfinexOrderCancelAll, nil, nil)
}
// ReplaceOrder replaces an older order with a new order
func (b *Bitfinex) ReplaceOrder(OrderID int64, Symbol string, Amount float64, Price float64, Buy bool, Type string, Hidden bool) (Order, error) {
response := Order{}
request := make(map[string]interface{})
request["order_id"] = OrderID
request["symbol"] = Symbol
request["amount"] = strconv.FormatFloat(Amount, 'f', -1, 64)
request["price"] = strconv.FormatFloat(Price, 'f', -1, 64)
request["exchange"] = "bitfinex"
request["type"] = Type
request["is_hidden"] = Hidden
if Buy {
request["side"] = "buy"
} else {
request["side"] = "sell"
}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderCancelReplace, request, &response)
}
// GetOrderStatus returns order status information
func (b *Bitfinex) GetOrderStatus(OrderID int64) (Order, error) {
orderStatus := Order{}
request := make(map[string]interface{})
request["order_id"] = OrderID
return orderStatus,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderStatus, request, &orderStatus)
}
// GetActiveOrders returns all active orders and statuses
func (b *Bitfinex) GetActiveOrders() ([]Order, error) {
response := []Order{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrders, nil, &response)
}
// GetActivePositions returns an array of active positions
func (b *Bitfinex) GetActivePositions() ([]Position, error) {
response := []Position{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexPositions, nil, &response)
}
// ClaimPosition allows positions to be claimed
func (b *Bitfinex) ClaimPosition(PositionID int) (Position, error) {
response := Position{}
request := make(map[string]interface{})
request["position_id"] = PositionID
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexClaimPosition, nil, nil)
}
// GetBalanceHistory returns balance history for the account
func (b *Bitfinex) GetBalanceHistory(symbol string, timeSince, timeUntil time.Time, limit int, wallet string) ([]BalanceHistory, error) {
response := []BalanceHistory{}
request := make(map[string]interface{})
request["currency"] = symbol
if !timeSince.IsZero() {
request["since"] = timeSince
}
if !timeUntil.IsZero() {
request["until"] = timeUntil
}
if limit > 0 {
request["limit"] = limit
}
if len(wallet) > 0 {
request["wallet"] = wallet
}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexHistory, request, &response)
}
// GetMovementHistory returns an array of past deposits and withdrawals
func (b *Bitfinex) GetMovementHistory(symbol, method string, timeSince, timeUntil time.Time, limit int) ([]MovementHistory, error) {
response := []MovementHistory{}
request := make(map[string]interface{})
request["currency"] = symbol
if len(method) > 0 {
request["method"] = method
}
if !timeSince.IsZero() {
request["since"] = timeSince
}
if !timeUntil.IsZero() {
request["until"] = timeUntil
}
if limit > 0 {
request["limit"] = limit
}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexHistoryMovements, request, &response)
}
// GetTradeHistory returns past executed trades
func (b *Bitfinex) GetTradeHistory(currencyPair string, timestamp, until time.Time, limit, reverse int) ([]TradeHistory, error) {
response := []TradeHistory{}
request := make(map[string]interface{})
request["currency"] = currencyPair
request["timestamp"] = timestamp
if !until.IsZero() {
request["until"] = until
}
if limit > 0 {
request["limit"] = limit
}
if reverse > 0 {
request["reverse"] = reverse
}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexTradeHistory, request, &response)
}
// NewOffer submits a new offer
func (b *Bitfinex) NewOffer(symbol string, amount, rate float64, period int64, direction string) (Offer, error) {
response := Offer{}
request := make(map[string]interface{})
request["currency"] = symbol
request["amount"] = amount
request["rate"] = rate
request["period"] = period
request["direction"] = direction
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOfferNew, request, &response)
}
// CancelOffer cancels offer by offerID
func (b *Bitfinex) CancelOffer(OfferID int64) (Offer, error) {
response := Offer{}
request := make(map[string]interface{})
request["offer_id"] = OfferID
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOfferCancel, request, &response)
}
// GetOfferStatus checks offer status whether it has been cancelled, execute or
// is still active
func (b *Bitfinex) GetOfferStatus(OfferID int64) (Offer, error) {
response := Offer{}
request := make(map[string]interface{})
request["offer_id"] = OfferID
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOrderStatus, request, &response)
}
// GetActiveCredits returns all available credits
func (b *Bitfinex) GetActiveCredits() ([]Offer, error) {
response := []Offer{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexActiveCredits, nil, &response)
}
// GetActiveOffers returns all current active offers
func (b *Bitfinex) GetActiveOffers() ([]Offer, error) {
response := []Offer{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexOffers, nil, &response)
}
// GetActiveMarginFunding returns an array of active margin funds
func (b *Bitfinex) GetActiveMarginFunding() ([]MarginFunds, error) {
response := []MarginFunds{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexMarginActiveFunds, nil, &response)
}
// GetUnusedMarginFunds returns an array of funding borrowed but not currently
// used
func (b *Bitfinex) GetUnusedMarginFunds() ([]MarginFunds, error) {
response := []MarginFunds{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexMarginUnusedFunds, nil, &response)
}
// GetMarginTotalTakenFunds returns an array of active funding used in a
// position
func (b *Bitfinex) GetMarginTotalTakenFunds() ([]MarginTotalTakenFunds, error) {
response := []MarginTotalTakenFunds{}
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexMarginTotalFunds, nil, &response)
}
// CloseMarginFunding closes an unused or used taken fund
func (b *Bitfinex) CloseMarginFunding(SwapID int64) (Offer, error) {
response := Offer{}
request := make(map[string]interface{})
request["swap_id"] = SwapID
return response,
b.SendAuthenticatedHTTPRequest("POST", bitfinexMarginClose, request, &response)
}
// SendAuthenticatedHTTPRequest sends an autheticated http request and json
// unmarshals result to a supplied variable
func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[string]interface{}, result interface{}) error {
if !b.AuthenticatedAPISupport {
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, b.Name)
}
if b.Nonce.Get() == 0 {
b.Nonce.Set(time.Now().UnixNano())
} else {
b.Nonce.Inc()
}
respErr := ErrorCapture{}
request := make(map[string]interface{})
request["request"] = fmt.Sprintf("/v%s/%s", bitfinexAPIVersion, path)
request["nonce"] = b.Nonce.String()
if params != nil {
for key, value := range params {
request[key] = value
}
}
PayloadJSON, err := common.JSONEncode(request)
if err != nil {
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON request")
}
if b.Verbose {
log.Printf("Request JSON: %s\n", PayloadJSON)
}
PayloadBase64 := common.Base64Encode(PayloadJSON)
hmac := common.GetHMAC(common.HashSHA512_384, []byte(PayloadBase64), []byte(b.APISecret))
headers := make(map[string]string)
headers["X-BFX-APIKEY"] = b.APIKey
headers["X-BFX-PAYLOAD"] = PayloadBase64
headers["X-BFX-SIGNATURE"] = common.HexEncodeToString(hmac)
resp, err := common.SendHTTPRequest(
method, bitfinexAPIURL+path, headers, strings.NewReader(""),
)
if err != nil {
return err
}
if b.Verbose {
log.Printf("Received raw: \n%s\n", resp)
}
if err = common.JSONDecode([]byte(resp), &respErr); err == nil {
if len(respErr.Message) != 0 {
return errors.New("Responded Error Issue: " + respErr.Message)
}
}
if err = common.JSONDecode([]byte(resp), &result); err != nil {
return errors.New("sendAuthenticatedHTTPRequest: Unable to JSON Unmarshal response")
}
return nil
}