Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

Commit

Permalink
stat: imp. GatherOhlcv() and testunit
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoul committed Nov 14, 2018
1 parent 0a7925c commit c8d5d4a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cryptocurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ func TestCryptoOhlcvHistorical(t *testing.T) {
info, err := GetInstance().CryptoOhlcvHistorical(&types.Options{
Symbol: "BTC",
Convert: "USD",
TimeStart: "2018-11-10",
TimeEnd: "2018-11-14",
TimeStart: "2018-11-12",
TimeEnd: "2018-11-13",
Interval: types.IntervalOptions.Hourly,
})
if err != nil {
Expand Down
25 changes: 25 additions & 0 deletions statistics/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ func TaskGatherCryptoQuote(options *types.Options) {
}
}

// GatherOhlcv gathers crypto quote
func GatherOhlcv(options *types.Options, job *gocron.Job) {
job.Do(TaskGatherOhlcv, options)
}

// TaskGatherOhlcv records crypto quote
func TaskGatherOhlcv(options *types.Options) {
start := time.Now().AddDate(0, 0, -2)
end := time.Now().AddDate(0, 0, -1)
options.TimeStart = util.ISODate(start)
options.TimeEnd = util.ISODate(end)

if data, err := coinmarketcap.GetInstance().CryptoOhlcvHistorical(options); err == nil {
for _, v := range data.Ohlcv {
for _, q := range v.Quotes {
logger.WithFields(log.Fields{
"symbol": data.Symbol,
"quote": q,
"ctime": v.TimeClose,
}).Info("GatherOhlcv")
}
}
}
}

// GatherExchangeMarketPairs gathers exchange quotes
func GatherExchangeMarketPairs(options *types.Options, targetSymbol string, job *gocron.Job) {
job.Do(TaskGatherExchangeMarketPairs, options, targetSymbol)
Expand Down
9 changes: 9 additions & 0 deletions statistics/statistics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func TestGatherCryptoQuote(t *testing.T) {
time.Sleep(15 * time.Second)
}

func TestGatherOhlcv(t *testing.T) {
GatherOhlcv(&types.Options{
Symbol: "BTC",
Convert: "USD",
}, gocron.Every(10).Seconds())
gocron.Start()
time.Sleep(15 * time.Second)
}

func TestGatherExchangeMarketPairs(t *testing.T) {
GatherExchangeMarketPairs(&types.Options{
Slug: "binance",
Expand Down
3 changes: 2 additions & 1 deletion types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ type OhlcvQuote struct {
Low float64 `json:"low"`
Close float64 `json:"close"`
Volume float64 `json:"volume"`
LastUpdated string `json:"last_updated"`
Timestamp string `json:"timestamp,omitempty"`
LastUpdated string `json:"last_updated,omitempty"`
}

// ExchangeMarketQuotes structure
Expand Down
5 changes: 5 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@ func InvokeChromedp(url, qeury string, sec int, buffer *string) (err error) {
err = dp.Wait()
return
}

// ISODate returns ISO date format like "2018-11-23"
func ISODate(t time.Time) string {
return strings.Split(t.Format(time.RFC3339), "T")[0]
}

0 comments on commit c8d5d4a

Please sign in to comment.