mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Added new function on bitfinex for V2 API trade history request.
This commit is contained in:
@@ -29,6 +29,7 @@ const (
|
||||
bitfinexOrderbookV2 = "book"
|
||||
bitfinexOrderbook = "book/"
|
||||
bitfinexTrades = "trades/"
|
||||
bitfinexTradesV2 = "https://api.bitfinex.com/v2/trades/%s/hist?limit=1000&start=%s&end=%s"
|
||||
bitfinexKeyPermissions = "key_info"
|
||||
bitfinexLends = "lends/"
|
||||
bitfinexSymbols = "symbols/"
|
||||
@@ -336,6 +337,56 @@ func (b *Bitfinex) GetTrades(currencyPair string, values url.Values) ([]TradeStr
|
||||
return response, common.SendHTTPGetRequest(path, true, b.Verbose, &response)
|
||||
}
|
||||
|
||||
// GetTradesV2 uses the V2 API to get historic trades that occured on the
|
||||
// exchange
|
||||
//
|
||||
// currencyPair e.g. "tBTCUSD" v2 prefixes currency pairs with t. (?)
|
||||
// timestampStart is an int64 unix epoch time
|
||||
// timestampEnd is an int64 unix epoch time, make sure this is always there or
|
||||
// you will get the most recent trades.
|
||||
// reOrderResp reorders the returned data.
|
||||
func (b *Bitfinex) GetTradesV2(currencyPair string, timestampStart, timestampEnd int64, reOrderResp bool) ([]TradeStructureV2, error) {
|
||||
var resp [][]interface{}
|
||||
var actualHistory []TradeStructureV2
|
||||
|
||||
path := fmt.Sprintf(bitfinexTradesV2,
|
||||
currencyPair,
|
||||
strconv.FormatInt(timestampStart, 10),
|
||||
strconv.FormatInt(timestampEnd, 10))
|
||||
|
||||
err := common.SendHTTPGetRequest(path, true, b.Verbose, &resp)
|
||||
if err != nil {
|
||||
return actualHistory, err
|
||||
}
|
||||
|
||||
var tempHistory TradeStructureV2
|
||||
for _, data := range resp {
|
||||
tempHistory.TID = int64(data[0].(float64))
|
||||
tempHistory.Timestamp = int64(data[1].(float64))
|
||||
tempHistory.Amount = data[2].(float64)
|
||||
tempHistory.Price = data[3].(float64)
|
||||
tempHistory.Exchange = b.Name
|
||||
tempHistory.Type = "BUY"
|
||||
|
||||
if tempHistory.Amount < 0 {
|
||||
tempHistory.Type = "SELL"
|
||||
tempHistory.Amount = tempHistory.Amount * -1
|
||||
}
|
||||
|
||||
actualHistory = append(actualHistory, tempHistory)
|
||||
}
|
||||
|
||||
//re-order index
|
||||
if reOrderResp {
|
||||
orderedHistory := make([]TradeStructureV2, len(actualHistory))
|
||||
for i, quickRange := range actualHistory {
|
||||
orderedHistory[len(actualHistory)-i-1] = quickRange
|
||||
}
|
||||
return orderedHistory, nil
|
||||
}
|
||||
return actualHistory, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -162,6 +162,15 @@ func TestGetTrades(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTradesv2(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.GetTradesV2("tBTCUSD", 0, 0, true)
|
||||
if err != nil {
|
||||
t.Error("BitfinexGetTrades init error: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLends(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -78,6 +78,16 @@ type TradeStructure struct {
|
||||
Type string `json:"sell"`
|
||||
}
|
||||
|
||||
// TradeStructureV2 holds resp information
|
||||
type TradeStructureV2 struct {
|
||||
Timestamp int64
|
||||
TID int64
|
||||
Price float64
|
||||
Amount float64
|
||||
Exchange string
|
||||
Type string
|
||||
}
|
||||
|
||||
// Lendbook holds most recent funding data for a relevant currency
|
||||
type Lendbook struct {
|
||||
Bids []Book `json:"bids"`
|
||||
|
||||
Reference in New Issue
Block a user