mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 15:11:10 +00:00
(Exchange) Add GetHistoricCandles() & GetHistoricCandlesEx() support to exchanges (#479)
* implemented binance and bitfinex GetHistoricCandles wrapper methods) * coinbene supported added * after and before clean up * gateio wrapper completed * merged upstream/master * Added bsaic KlineIntervalSupported() method * Converted binance fixed test * WIP * new KlineConvertToExchangeStandardString method added * end of day WIP * WIP * end of day WIP started migration of trade history * added kline support to hitbtc huobi lbank * added exchangehistory to all supported exchanges started work on coinbase 300 candles/request method * end of day WIP * removed unused ta and misc changes to flag ready for review * yobit cleanup * revert coinbase changES * general code clean up and added zb support * poloniex support added * renamed method to FormatExchangeKlineInterval other misc fixes * linter fixes * linter fixes * removed verbose * fixed poloniex test coverage * revert poloniex mock data * regenerated poloniex mock data * a very verbose clean up * binance mock clean up * removed unneeded t.Log() * setting verbose to true to debug CI issue * first pass changes addressed * common.ErrNotYetImplemented implemented :D * comments added * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * WIP-addressed exchange requests and reverted previous GetExchangeHistory changes * increased test coverage added kraken support * OKGroup support completed started work on address GetExchangeHistory feedback and migrating to own PR under https://github.com/xtda/gocryptotrader/tree/exchange_history * convert zb ratelimits * gofmt run on okcoin * increased delay on rate limit * gofmt package * fixed panic with coinbene and bithumb if conversion fails * very broken end of day WIP * added support for GetHistoricCandlesEx to coinbase and binance * gofmt package * coinbase, btcmarkets, zb ex wrapper function added * added all exchange support for ex regenerated mock data * update bithumb to return wrapper method * gofmt package * end of day started work on changes * reworked test coverage added okgroup support general fixes/change requests addressed * Added OneMonth * limit checks on supportedexchanges * reverted getexchangehistory * reworked binance tesT * added workaround for kraken panic * renamed command to extended removed interval check on non-implemented commands * added wrapperconfig back * increased test coverage for FormatExchangeKlineInterval * WIP * increased test coverage for FormatExchangeKlineInterval bitfinex/gateio/huobi * linter fixes * zb kraken lbank coinbene btcmarkets support added * removed verbose * OK group support for other asset types added * swapped margin to use spot endpoint * index support added test coverage added for asset types * added asset type to okcoin test * gofmt * add asset to extended method * removed verbose * add support for coinbene swap increase test coverage * removed verbose * small clean up of okgroup wrapper functions * verbose to troubleshoot CI issues * removed verbose * added error check reverted coinbasechanges * readme updated * removed unused start/finish started work on decoupling api requests from kline package * restructured coinbene, bithumb methods, added bitstamp support * kraken time fix * BTCMarkets restructure * typo fix * removed test for futures due to contact changing * added start/end date to extended method over range * converted to assettranslator * removed verbose * removed invalid char * reverted incorrectly removed return * added import * further template updates * macos hates my keyboard :D * misc canges * x -> i * removed verbose * updated fixCasing to allocate var before checks * removed time conversion * sort all outgoing kline candles * fixCasing fix * after/before checks added * added parallel to test * logic check on BTCmarkets * removed unused param, used correct iterator * converted HitBTC to use time.Time * add iszero false check to candle times * updated resultlimit to 5000 * new line added * added comment to exported const * use configured ratelimit * fixed pair for test * panic fixed WIP on fixCasing * fixCasing rework, started work on readme docs * enable rate limiter for wrapper issues tool * docs updated * removed err from return and formatted currency * updated Yobit supported status * Updated HitBTC to use onehour candles due to test exeuction times * added further details to gctcli output * added link to docs * added link to tempalte * disable FTX websocket in config_example * fix poloneix * regenerated poloniex mock data * removed recording flag
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
@@ -79,11 +80,21 @@ func TestGetTrades(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetHistoricRatesGranularityCheck(t *testing.T) {
|
||||
end := time.Now().UTC()
|
||||
start := end.Add(-time.Hour * 24)
|
||||
end := time.Now()
|
||||
start := end.Add(-time.Hour * 2)
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
_, err := c.GetHistoricCandles(p, asset.Spot, start, end, kline.OneHour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
_, err := c.GetHistoricCandles(p, asset.Spot, start, end, time.Hour)
|
||||
func TestCoinbasePro_GetHistoricCandlesExtended(t *testing.T) {
|
||||
start := time.Unix(1546300800, 0)
|
||||
end := time.Unix(1577836799, 0)
|
||||
|
||||
p := currency.NewPair(currency.BTC, currency.USD)
|
||||
_, err := c.GetHistoricCandlesExtended(p, asset.Spot, start, end, kline.OneDay)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package coinbasepro
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -112,9 +113,24 @@ func (c *CoinbasePro) SetDefaults() {
|
||||
},
|
||||
WithdrawPermissions: exchange.AutoWithdrawCryptoWithAPIPermission |
|
||||
exchange.AutoWithdrawFiatWithAPIPermission,
|
||||
Kline: kline.ExchangeCapabilitiesSupported{
|
||||
DateRanges: true,
|
||||
Intervals: true,
|
||||
},
|
||||
},
|
||||
Enabled: exchange.FeaturesEnabled{
|
||||
AutoPairUpdates: true,
|
||||
Kline: kline.ExchangeCapabilitiesEnabled{
|
||||
Intervals: map[string]bool{
|
||||
kline.OneMin.Word(): true,
|
||||
kline.FiveMin.Word(): true,
|
||||
kline.FifteenMin.Word(): true,
|
||||
kline.OneHour.Word(): true,
|
||||
kline.SixHour.Word(): true,
|
||||
kline.OneDay.Word(): true,
|
||||
},
|
||||
ResultLimit: 300,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -682,47 +698,38 @@ func (c *CoinbasePro) AuthenticateWebsocket() error {
|
||||
return common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// checkInterval checks allowable interval
|
||||
func checkInterval(i time.Duration) (int64, error) {
|
||||
switch i.Seconds() {
|
||||
case 60:
|
||||
return 60, nil
|
||||
case 300:
|
||||
return 300, nil
|
||||
case 900:
|
||||
return 900, nil
|
||||
case 3600:
|
||||
return 3600, nil
|
||||
case 21600:
|
||||
return 21600, nil
|
||||
case 86400:
|
||||
return 86400, nil
|
||||
}
|
||||
return 0, fmt.Errorf("interval not allowed %v", i.Seconds())
|
||||
}
|
||||
|
||||
// GetHistoricCandles returns a set of candle between two time periods for a
|
||||
// designated time period
|
||||
func (c *CoinbasePro) GetHistoricCandles(p currency.Pair, a asset.Item, start, end time.Time, interval time.Duration) (kline.Item, error) {
|
||||
i, err := checkInterval(interval)
|
||||
func (c *CoinbasePro) GetHistoricCandles(p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
if !c.KlineIntervalEnabled(interval) {
|
||||
return kline.Item{}, kline.ErrorKline{
|
||||
Interval: interval,
|
||||
}
|
||||
}
|
||||
|
||||
if kline.TotalCandlesPerInterval(start, end, interval) > c.Features.Enabled.Kline.ResultLimit {
|
||||
return kline.Item{}, errors.New(kline.ErrRequestExceedsExchangeLimits)
|
||||
}
|
||||
|
||||
candles := kline.Item{
|
||||
Exchange: c.Name,
|
||||
Pair: p,
|
||||
Asset: a,
|
||||
Interval: interval,
|
||||
}
|
||||
|
||||
gran, err := strconv.ParseInt(c.FormatExchangeKlineInterval(interval), 10, 64)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
history, err := c.GetHistoricRates(c.FormatExchangeCurrency(p, a).String(),
|
||||
start.Format(time.RFC3339),
|
||||
end.Format(time.RFC3339),
|
||||
i)
|
||||
gran)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
var candles kline.Item
|
||||
candles.Asset = a
|
||||
candles.Exchange = c.Name
|
||||
candles.Interval = interval
|
||||
candles.Pair = p
|
||||
|
||||
for x := range history {
|
||||
candles.Candles = append(candles.Candles, kline.Candle{
|
||||
Time: time.Unix(history[x].Time, 0),
|
||||
@@ -733,9 +740,56 @@ func (c *CoinbasePro) GetHistoricCandles(p currency.Pair, a asset.Item, start, e
|
||||
Volume: history[x].Volume,
|
||||
})
|
||||
}
|
||||
|
||||
candles.SortCandlesByTimestamp(false)
|
||||
return candles, nil
|
||||
}
|
||||
|
||||
// GetHistoricCandlesExtended returns candles between a time period for a set time interval
|
||||
func (c *CoinbasePro) GetHistoricCandlesExtended(p currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error) {
|
||||
if !c.KlineIntervalEnabled(interval) {
|
||||
return kline.Item{}, kline.ErrorKline{
|
||||
Interval: interval,
|
||||
}
|
||||
}
|
||||
|
||||
ret := kline.Item{
|
||||
Exchange: c.Name,
|
||||
Pair: p,
|
||||
Asset: a,
|
||||
Interval: interval,
|
||||
}
|
||||
|
||||
gran, err := strconv.ParseInt(c.FormatExchangeKlineInterval(interval), 10, 64)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
dates := kline.CalcDateRanges(start, end, interval, c.Features.Enabled.Kline.ResultLimit)
|
||||
for x := range dates {
|
||||
history, err := c.GetHistoricRates(c.FormatExchangeCurrency(p, a).String(),
|
||||
dates[x].Start.Format(time.RFC3339),
|
||||
dates[x].End.Format(time.RFC3339),
|
||||
gran)
|
||||
if err != nil {
|
||||
return kline.Item{}, err
|
||||
}
|
||||
|
||||
for i := range history {
|
||||
ret.Candles = append(ret.Candles, kline.Candle{
|
||||
Time: time.Unix(history[i].Time, 0),
|
||||
Low: history[i].Low,
|
||||
High: history[i].High,
|
||||
Open: history[i].Open,
|
||||
Close: history[i].Close,
|
||||
Volume: history[i].Volume,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
ret.SortCandlesByTimestamp(false)
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// ValidateCredentials validates current credentials used for wrapper
|
||||
// functionality
|
||||
func (c *CoinbasePro) ValidateCredentials() error {
|
||||
|
||||
Reference in New Issue
Block a user