Showing 30 of 64 files from the diff.
Newly tracked file
services/worker/rates.go changed.
Newly tracked file
services/assets/client.go changed.
Newly tracked file
services/worker/memory.go changed.
Newly tracked file
api/api.go changed.
Newly tracked file
redis/redis.go changed.
Newly tracked file
services/worker/tickers.go changed.
Other files ignored by Codecov
internal/init.go has changed.
api/api_test.go has changed.
go.sum has changed.
db/db.go has changed.
go.mod has changed.

@@ -1,14 +1,14 @@
Loading
1 1
package infocontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
5 +
	"strconv"
6 +
	"strings"
7 +
6 8
	"github.com/trustwallet/golibs/coin"
7 9
	"github.com/trustwallet/watchmarket/db/models"
8 10
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
9 11
	"github.com/trustwallet/watchmarket/services/controllers"
10 -
	"strconv"
11 -
	"strings"
12 12
)
13 13
14 14
type (
@@ -46,7 +46,7 @@
Loading
46 46
	}, nil
47 47
}
48 48
49 -
func (c Controller) getDetailsByPriority(data detailsNormalizedRequest, ctx context.Context) (controllers.InfoResponse, error) {
49 +
func (c Controller) getDetailsByPriority(data detailsNormalizedRequest) (controllers.InfoResponse, error) {
50 50
	availableTickerProviders := c.coinInfoPriority
51 51
	availableRateProviders := c.configuration.Markets.Priority.Rates
52 52
@@ -55,7 +55,7 @@
Loading
55 55
		details watchmarket.CoinDetails
56 56
	)
57 57
	for _, p := range availableTickerProviders {
58 -
		data, err := c.api[p].GetCoinData(data.Coin, data.Token, data.Currency, ctx)
58 +
		data, err := c.api[p].GetCoinData(data.Coin, data.Token, data.Currency)
59 59
		if err == nil {
60 60
			details = data
61 61
			break
@@ -65,7 +65,7 @@
Loading
65 65
	result.Provider = details.Provider
66 66
	result.ProviderURL = details.ProviderURL
67 67
68 -
	dbTickers, err := c.database.GetTickersByQueries([]models.TickerQuery{{Coin: data.Coin, TokenId: strings.ToLower(data.Token)}}, ctx)
68 +
	dbTickers, err := c.database.GetTickersByQueries([]models.TickerQuery{{Coin: data.Coin, TokenId: strings.ToLower(data.Token)}})
69 69
	if err != nil {
70 70
		return controllers.InfoResponse{}, err
71 71
	}
@@ -82,7 +82,7 @@
Loading
82 82
	result.TotalSupply = tickerData.TotalSupply
83 83
84 84
	if data.Currency != watchmarket.DefaultCurrency {
85 -
		rates, err := c.database.GetRates(data.Currency, ctx)
85 +
		rates, err := c.database.GetRates(data.Currency)
86 86
		if err != nil {
87 87
			return controllers.InfoResponse{}, err
88 88
		}

@@ -1,7 +1,6 @@
Loading
1 1
package fixer
2 2
3 3
import (
4 -
	"context"
5 4
	"github.com/imroc/req"
6 5
	log "github.com/sirupsen/logrus"
7 6
)
@@ -15,12 +14,12 @@
Loading
15 14
	return Client{r: req.New(), key: key, currency: currency, api: api}
16 15
}
17 16
18 -
func (c Client) FetchRates(ctx context.Context) (Rate, error) {
17 +
func (c Client) FetchRates() (Rate, error) {
19 18
	var (
20 19
		values = req.Param{"access_key": c.key, "base": c.currency} // Base USD supported only in paid api}
21 20
		result Rate
22 21
	)
23 -
	resp, err := c.r.Get(c.api+"/latest", values, ctx)
22 +
	resp, err := c.r.Get(c.api+"/latest", values)
24 23
	if err != nil {
25 24
		return Rate{}, err
26 25
	}

@@ -1,7 +1,6 @@
Loading
1 1
package markets
2 2
3 3
import (
4 -
	"context"
5 4
	"github.com/trustwallet/watchmarket/config"
6 5
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 6
	"github.com/trustwallet/watchmarket/services/assets"
@@ -18,18 +17,18 @@
Loading
18 17
19 18
	RatesAPI interface {
20 19
		Provider
21 -
		GetRates(ctx context.Context) (watchmarket.Rates, error)
20 +
		GetRates() (watchmarket.Rates, error)
22 21
	}
23 22
24 23
	TickersAPI interface {
25 24
		Provider
26 -
		GetTickers(ctx context.Context) (watchmarket.Tickers, error)
25 +
		GetTickers() (watchmarket.Tickers, error)
27 26
	}
28 27
29 28
	ChartsAPI interface {
30 29
		Provider
31 -
		GetChartData(coinID uint, token, currency string, timeStart int64, ctx context.Context) (watchmarket.Chart, error)
32 -
		GetCoinData(coinID uint, token, currency string, ctx context.Context) (watchmarket.CoinDetails, error)
30 +
		GetChartData(coinID uint, token, currency string, timeStart int64) (watchmarket.Chart, error)
31 +
		GetCoinData(coinID uint, token, currency string) (watchmarket.CoinDetails, error)
33 32
	}
34 33
35 34
	Providers   map[string]Provider

@@ -1,44 +1,39 @@
Loading
1 1
package worker
2 2
3 3
import (
4 -
	"context"
4 +
	"sync"
5 +
5 6
	log "github.com/sirupsen/logrus"
6 7
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 8
	"github.com/trustwallet/watchmarket/services/markets"
8 -
	"go.elastic.co/apm"
9 -
	"sync"
10 9
)
11 10
12 11
func (w Worker) FetchAndSaveRates() {
13 -
	tx := apm.DefaultTracer.StartTransaction("FetchAndSaveRates", "app")
14 -
	ctx := apm.ContextWithTransaction(context.Background(), tx)
15 -
	defer tx.End()
16 -
17 12
	log.Info("Fetching Rates ...")
18 -
	fetchedRates := fetchRates(w.ratesApis, ctx)
13 +
	fetchedRates := fetchRates(w.ratesApis)
19 14
	normalizedRates := toRatesModel(fetchedRates)
20 15
21 -
	if err := w.db.AddRates(normalizedRates, w.configuration.Worker.BatchLimit, ctx); err != nil {
16 +
	if err := w.db.AddRates(normalizedRates, w.configuration.Worker.BatchLimit); err != nil {
22 17
		log.Error(err)
23 18
	}
24 19
}
25 20
26 -
func fetchRates(ratesApis markets.RatesAPIs, ctx context.Context) watchmarket.Rates {
21 +
func fetchRates(ratesApis markets.RatesAPIs) watchmarket.Rates {
27 22
	wg := new(sync.WaitGroup)
28 23
	s := new(rates)
29 24
	for _, t := range ratesApis {
30 25
		wg.Add(1)
31 -
		go fetchRatesByProvider(t, wg, s, ctx)
26 +
		go fetchRatesByProvider(t, wg, s)
32 27
	}
33 28
	wg.Wait()
34 29
35 30
	return s.rates
36 31
}
37 32
38 -
func fetchRatesByProvider(r markets.RatesAPI, wg *sync.WaitGroup, s *rates, ctx context.Context) {
33 +
func fetchRatesByProvider(r markets.RatesAPI, wg *sync.WaitGroup, s *rates) {
39 34
	defer wg.Done()
40 35
41 -
	rates, err := r.GetRates(ctx)
36 +
	rates, err := r.GetRates()
42 37
	if err != nil {
43 38
		log.WithFields(log.Fields{"provider": r.GetProvider(), "details": err}).Error("Failed to fetch rates")
44 39
		return

@@ -1,9 +1,9 @@
Loading
1 1
package chartscontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
6 5
	"errors"
6 +
7 7
	log "github.com/sirupsen/logrus"
8 8
	"github.com/trustwallet/watchmarket/config"
9 9
	"github.com/trustwallet/watchmarket/db"
@@ -46,7 +46,7 @@
Loading
46 46
	}
47 47
}
48 48
49 -
func (c Controller) HandleChartsRequest(cr controllers.ChartRequest, ctx context.Context) (watchmarket.Chart, error) {
49 +
func (c Controller) HandleChartsRequest(cr controllers.ChartRequest) (watchmarket.Chart, error) {
50 50
	var ch watchmarket.Chart
51 51
52 52
	verifiedData, err := toChartsRequestData(cr)
@@ -56,7 +56,7 @@
Loading
56 56
57 57
	key := c.redisCache.GenerateKey(charts + cr.CoinQuery + cr.Token + cr.Currency + cr.MaxItems)
58 58
59 -
	cachedChartRaw, err := c.redisCache.GetWithTime(key, verifiedData.TimeStart, ctx)
59 +
	cachedChartRaw, err := c.redisCache.GetWithTime(key, verifiedData.TimeStart)
60 60
	if err == nil && len(cachedChartRaw) > 0 {
61 61
		err = json.Unmarshal(cachedChartRaw, &ch)
62 62
		if err == nil && len(ch.Prices) > 0 {
@@ -64,12 +64,12 @@
Loading
64 64
		}
65 65
	}
66 66
67 -
	res, err := c.checkTickersAvailability(verifiedData.Coin, verifiedData.Token, ctx)
67 +
	res, err := c.checkTickersAvailability(verifiedData.Coin, verifiedData.Token)
68 68
	if err != nil || len(res) == 0 {
69 69
		return ch, err
70 70
	}
71 71
72 -
	rawChart, err := c.getChartsByPriority(verifiedData, ctx)
72 +
	rawChart, err := c.getChartsByPriority(verifiedData)
73 73
	if err != nil {
74 74
		return watchmarket.Chart{}, errors.New(watchmarket.ErrInternal)
75 75
	}
@@ -86,7 +86,7 @@
Loading
86 86
	}
87 87
88 88
	if err == nil && len(chart.Prices) > 0 {
89 -
		err = c.redisCache.SetWithTime(key, chartRaw, verifiedData.TimeStart, ctx)
89 +
		err = c.redisCache.SetWithTime(key, chartRaw, verifiedData.TimeStart)
90 90
		if err != nil {
91 91
			log.WithFields(log.Fields{"err": err}).Error("failed to save cache")
92 92
		}

@@ -1,17 +1,17 @@
Loading
1 1
package chartscontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
6 5
	"errors"
6 +
	"strconv"
7 +
	"strings"
8 +
	"time"
9 +
7 10
	"github.com/trustwallet/golibs/asset"
8 11
	"github.com/trustwallet/golibs/coin"
9 12
	"github.com/trustwallet/watchmarket/db/models"
10 13
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
11 14
	"github.com/trustwallet/watchmarket/services/controllers"
12 -
	"strconv"
13 -
	"strings"
14 -
	"time"
15 15
)
16 16
17 17
const charts = "charts"
@@ -57,11 +57,11 @@
Loading
57 57
	}, nil
58 58
}
59 59
60 -
func (c Controller) checkTickersAvailability(coin uint, token string, ctx context.Context) ([]models.Ticker, error) {
60 +
func (c Controller) checkTickersAvailability(coin uint, token string) ([]models.Ticker, error) {
61 61
	tr := []models.TickerQuery{{Coin: coin, TokenId: strings.ToLower(token)}}
62 62
	if c.configuration.RestAPI.UseMemoryCache {
63 63
		key := strings.ToLower(asset.BuildID(coin, token))
64 -
		rawResult, err := c.memoryCache.Get(key, ctx)
64 +
		rawResult, err := c.memoryCache.Get(key)
65 65
		if err != nil {
66 66
			return nil, err
67 67
		}
@@ -82,7 +82,7 @@
Loading
82 82
		}
83 83
		return []models.Ticker{result}, nil
84 84
	}
85 -
	dbTickers, err := c.database.GetTickersByQueries(tr, ctx)
85 +
	dbTickers, err := c.database.GetTickersByQueries(tr)
86 86
	if err != nil {
87 87
		return nil, err
88 88
	}
@@ -95,10 +95,10 @@
Loading
95 95
	return res, nil
96 96
}
97 97
98 -
func (c Controller) getChartsByPriority(data chartsNormalizedRequest, ctx context.Context) (watchmarket.Chart, error) {
98 +
func (c Controller) getChartsByPriority(data chartsNormalizedRequest) (watchmarket.Chart, error) {
99 99
	availableProviders := c.chartsPriority
100 100
	for _, p := range availableProviders {
101 -
		price, err := c.api[p].GetChartData(data.Coin, data.Token, data.Currency, data.TimeStart, ctx)
101 +
		price, err := c.api[p].GetChartData(data.Coin, data.Token, data.Currency, data.TimeStart)
102 102
		if len(price.Prices) > 0 && err == nil {
103 103
			return price, nil
104 104
		}

@@ -1,12 +1,12 @@
Loading
1 1
package binancedex
2 2
3 3
import (
4 -
	"context"
5 4
	"strconv"
6 5
	"strings"
7 6
	"time"
8 7
9 8
	"errors"
9 +
10 10
	"github.com/trustwallet/golibs/coin"
11 11
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
12 12
)
@@ -16,8 +16,8 @@
Loading
16 16
	BNBAsset = coin.Binance().Symbol
17 17
)
18 18
19 -
func (p Provider) GetTickers(ctx context.Context) (watchmarket.Tickers, error) {
20 -
	prices, err := p.client.fetchPrices(ctx)
19 +
func (p Provider) GetTickers() (watchmarket.Tickers, error) {
20 +
	prices, err := p.client.fetchPrices()
21 21
	if err != nil {
22 22
		return nil, err
23 23
	}

@@ -1,7 +1,6 @@
Loading
1 1
package assets
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
6 5
	"fmt"
7 6
@@ -20,7 +19,7 @@
Loading
20 19
	return Client{r: req.New(), api: api}
21 20
}
22 21
23 -
func (c Client) GetCoinInfo(coinId uint, token string, ctx context.Context) (watchmarket.Info, error) {
22 +
func (c Client) GetCoinInfo(coinId uint, token string) (watchmarket.Info, error) {
24 23
	coinObject, ok := coin.Coins[coinId]
25 24
	if !ok {
26 25
		return watchmarket.Info{}, errors.New("coin not found " + "token " + token)
@@ -31,7 +30,7 @@
Loading
31 30
		result watchmarket.Info
32 31
	)
33 32
34 -
	resp, err := c.r.Get(path, ctx)
33 +
	resp, err := c.r.Get(path)
35 34
	if err != nil {
36 35
		return watchmarket.Info{}, err
37 36
	}

@@ -1,13 +1,13 @@
Loading
1 1
package coinmarketcap
2 2
3 3
import (
4 -
	"context"
5 -
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
6 4
	"strings"
5 +
6 +
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 7
)
8 8
9 -
func (p Provider) GetRates(ctx context.Context) (rates watchmarket.Rates, err error) {
10 -
	prices, err := p.client.fetchPrices(p.currency, ctx)
9 +
func (p Provider) GetRates() (rates watchmarket.Rates, err error) {
10 +
	prices, err := p.client.fetchPrices(p.currency)
11 11
	if err != nil {
12 12
		return
13 13
	}

@@ -1,21 +1,21 @@
Loading
1 1
package coingecko
2 2
3 3
import (
4 -
	"context"
5 4
	"strings"
6 5
7 6
	"errors"
7 +
8 8
	"github.com/trustwallet/golibs/coin"
9 9
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 10
)
11 11
12 -
func (p Provider) GetTickers(ctx context.Context) (watchmarket.Tickers, error) {
13 -
	coins, err := p.client.fetchCoins(ctx)
12 +
func (p Provider) GetTickers() (watchmarket.Tickers, error) {
13 +
	coins, err := p.client.fetchCoins()
14 14
	if err != nil {
15 15
		return watchmarket.Tickers{}, err
16 16
	}
17 17
18 -
	rates := p.client.fetchRates(coins, p.currency, ctx)
18 +
	rates := p.client.fetchRates(coins, p.currency)
19 19
	tickersList := p.normalizeTickers(rates, coins, p.id, p.currency)
20 20
	return tickersList, nil
21 21
}

@@ -1,7 +1,6 @@
Loading
1 1
package coingecko
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
6 5
	"sort"
7 6
	"strings"
@@ -14,10 +13,10 @@
Loading
14 13
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
15 14
)
16 15
17 -
func (p Provider) GetChartData(coinID uint, token, currency string, timeStart int64, ctx context.Context) (watchmarket.Chart, error) {
16 +
func (p Provider) GetChartData(coinID uint, token, currency string, timeStart int64) (watchmarket.Chart, error) {
18 17
	chartsData := watchmarket.Chart{}
19 18
20 -
	coins, err := p.client.fetchCoins(ctx)
19 +
	coins, err := p.client.fetchCoins()
21 20
	if err != nil {
22 21
		return chartsData, err
23 22
	}
@@ -31,7 +30,7 @@
Loading
31 30
32 31
	timeEndDate := time.Now().Unix()
33 32
34 -
	c, err := p.client.fetchCharts(coinResult.Id, currency, timeStart, timeEndDate, ctx)
33 +
	c, err := p.client.fetchCharts(coinResult.Id, currency, timeStart, timeEndDate)
35 34
	if err != nil {
36 35
		return chartsData, err
37 36
	}
@@ -39,8 +38,8 @@
Loading
39 38
	return normalizeCharts(c), nil
40 39
}
41 40
42 -
func (p Provider) GetCoinData(coinID uint, token, currency string, ctx context.Context) (watchmarket.CoinDetails, error) {
43 -
	coins, err := p.client.fetchCoins(ctx)
41 +
func (p Provider) GetCoinData(coinID uint, token, currency string) (watchmarket.CoinDetails, error) {
42 +
	coins, err := p.client.fetchCoins()
44 43
	if err != nil {
45 44
		return watchmarket.CoinDetails{}, err
46 45
	}
@@ -52,12 +51,12 @@
Loading
52 51
		return watchmarket.CoinDetails{}, err
53 52
	}
54 53
55 -
	ratesData := p.client.fetchRates(Coins{coinResult}, currency, ctx)
54 +
	ratesData := p.client.fetchRates(Coins{coinResult}, currency)
56 55
	if len(ratesData) == 0 {
57 56
		return watchmarket.CoinDetails{}, errors.New("no rates found")
58 57
	}
59 58
60 -
	infoData, err := p.info.GetCoinInfo(coinID, token, ctx)
59 +
	infoData, err := p.info.GetCoinInfo(coinID, token)
61 60
	if err != nil {
62 61
		log.WithFields(log.Fields{"coin": coinID, "token": token}).Warn("No assets assets about that coin")
63 62
	}

@@ -1,18 +1,18 @@
Loading
1 1
package tickerscontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
6 5
	"errors"
6 +
	"strings"
7 +
7 8
	log "github.com/sirupsen/logrus"
8 9
	"github.com/trustwallet/watchmarket/db/models"
9 10
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 -
	"strings"
11 11
)
12 12
13 -
func (c Controller) getRateByPriority(currency string, ctx context.Context) (watchmarket.Rate, error) {
13 +
func (c Controller) getRateByPriority(currency string) (watchmarket.Rate, error) {
14 14
	if c.configuration.RestAPI.UseMemoryCache {
15 -
		rawResult, err := c.cache.Get(currency, ctx)
15 +
		rawResult, err := c.cache.Get(currency)
16 16
		if err != nil {
17 17
			return watchmarket.Rate{}, err
18 18
		}
@@ -23,7 +23,7 @@
Loading
23 23
		return result, nil
24 24
	}
25 25
26 -
	rates, err := c.database.GetRates(currency, ctx)
26 +
	rates, err := c.database.GetRates(currency)
27 27
	if err != nil {
28 28
		log.Error(err, "getRateByPriority")
29 29
		return watchmarket.Rate{}, err
@@ -55,9 +55,9 @@
Loading
55 55
	}, nil
56 56
}
57 57
58 -
func (c Controller) rateToDefaultCurrency(t watchmarket.Ticker, rate watchmarket.Rate, ctx context.Context) (watchmarket.Rate, bool) {
58 +
func (c Controller) rateToDefaultCurrency(t watchmarket.Ticker, rate watchmarket.Rate) (watchmarket.Rate, bool) {
59 59
	if t.Price.Currency != watchmarket.DefaultCurrency {
60 -
		newRate, err := c.getRateByPriority(strings.ToUpper(t.Price.Currency), ctx)
60 +
		newRate, err := c.getRateByPriority(strings.ToUpper(t.Price.Currency))
61 61
		if err != nil {
62 62
			return watchmarket.Rate{}, false
63 63
		}

@@ -1,18 +1,18 @@
Loading
1 1
package fixer
2 2
3 3
import (
4 -
	"context"
5 -
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
6 4
	"strings"
5 +
6 +
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 7
)
8 8
9 9
const (
10 10
	id = "fixer"
11 11
)
12 12
13 -
func (p Provider) GetRates(ctx context.Context) (watchmarket.Rates, error) {
13 +
func (p Provider) GetRates() (watchmarket.Rates, error) {
14 14
	var result watchmarket.Rates
15 -
	rawRates, err := p.client.FetchRates(ctx)
15 +
	rawRates, err := p.client.FetchRates()
16 16
	if err != nil {
17 17
		return result, err
18 18
	}

@@ -1,24 +1,19 @@
Loading
1 1
package worker
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
5 +
6 6
	log "github.com/sirupsen/logrus"
7 7
	"github.com/trustwallet/watchmarket/config"
8 8
	"github.com/trustwallet/watchmarket/db/models"
9 9
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 -
	"go.elastic.co/apm"
11 10
)
12 11
13 12
func (w Worker) SaveTickersToMemory() {
14 -
	tx := apm.DefaultTracer.StartTransaction("SaveTickersToMemory", "app")
15 -
	ctx := apm.ContextWithTransaction(context.Background(), tx)
16 -
	defer tx.End()
17 -
18 13
	log.Info("---------------------------------------")
19 14
	log.Info("Memory Cache: request to DB for tickers ...")
20 15
21 -
	allTickers, err := w.db.GetAllTickers(ctx)
16 +
	allTickers, err := w.db.GetAllTickers()
22 17
	if err != nil {
23 18
		log.Warn("Failed to get tickers: ", err.Error())
24 19
		return
@@ -32,7 +27,7 @@
Loading
32 27
			log.Error(err)
33 28
			continue
34 29
		}
35 -
		if err = w.cache.Set(key, rawVal, ctx); err != nil {
30 +
		if err = w.cache.Set(key, rawVal); err != nil {
36 31
			log.Error(err)
37 32
			continue
38 33
		}
@@ -43,14 +38,10 @@
Loading
43 38
}
44 39
45 40
func (w Worker) SaveRatesToMemory() {
46 -
	tx := apm.DefaultTracer.StartTransaction("SaveRatesToMemory", "app")
47 -
	ctx := apm.ContextWithTransaction(context.Background(), tx)
48 -
	defer tx.End()
49 -
50 41
	log.Info("---------------------------------------")
51 42
	log.Info("Memory Cache: request to DB for rates ...")
52 43
53 -
	allRates, err := w.db.GetAllRates(ctx)
44 +
	allRates, err := w.db.GetAllRates()
54 45
	if err != nil {
55 46
		log.Warn("Failed to get rates: ", err.Error())
56 47
		return
@@ -65,7 +56,7 @@
Loading
65 56
			log.Error(err)
66 57
			continue
67 58
		}
68 -
		if err = w.cache.Set(key, rawVal, ctx); err != nil {
59 +
		if err = w.cache.Set(key, rawVal); err != nil {
69 60
			log.Error(err)
70 61
			continue
71 62
		}

@@ -9,7 +9,7 @@
Loading
9 9
	"github.com/prometheus/client_golang/prometheus/promhttp"
10 10
	ginSwagger "github.com/swaggo/gin-swagger"
11 11
	"github.com/swaggo/gin-swagger/swaggerFiles"
12 -
	"github.com/trustwallet/golibs-networking/middleware"
12 +
	"github.com/trustwallet/golibs/middleware"
13 13
	"github.com/trustwallet/watchmarket/api/endpoint"
14 14
	_ "github.com/trustwallet/watchmarket/docs"
15 15
	"github.com/trustwallet/watchmarket/services/controllers"

@@ -1,7 +1,6 @@
Loading
1 1
package binancedex
2 2
3 3
import (
4 -
	"context"
5 4
	"github.com/imroc/req"
6 5
	log "github.com/sirupsen/logrus"
7 6
)
@@ -18,8 +17,8 @@
Loading
18 17
	}
19 18
}
20 19
21 -
func (c Client) fetchPrices(ctx context.Context) ([]CoinPrice, error) {
22 -
	resp, err := c.r.Get(c.baseURL+"/v1/ticker/24hr", req.Param{"limit": "1000"}, ctx)
20 +
func (c Client) fetchPrices() ([]CoinPrice, error) {
21 +
	resp, err := c.r.Get(c.baseURL+"/v1/ticker/24hr", req.Param{"limit": "1000"})
23 22
	if err != nil {
24 23
		return nil, err
25 24
	}

@@ -1,11 +1,10 @@
Loading
1 1
package redis
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
6 -
	"github.com/go-redis/redis"
7 -
	"go.elastic.co/apm/module/apmgoredis"
8 5
	"time"
6 +
7 +
	"github.com/go-redis/redis"
9 8
)
10 9
11 10
type Redis struct {
@@ -25,9 +24,8 @@
Loading
25 24
	return Redis{client: *client}, nil
26 25
}
27 26
28 -
func (db Redis) Get(key string, ctx context.Context) ([]byte, error) {
29 -
	client := apmgoredis.Wrap(&db.client).WithContext(ctx)
30 -
	cmd := client.Get(key)
27 +
func (db Redis) Get(key string) ([]byte, error) {
28 +
	cmd := db.client.Get(key)
31 29
	if cmd.Err() == redis.Nil {
32 30
		return nil, errors.New("not found")
33 31
	} else if cmd.Err() != nil {
@@ -37,18 +35,16 @@
Loading
37 35
	return []byte(cmd.Val()), nil
38 36
}
39 37
40 -
func (db Redis) Set(key string, value []byte, expiration time.Duration, ctx context.Context) error {
41 -
	client := apmgoredis.Wrap(&db.client).WithContext(ctx)
42 -
	cmd := client.Set(key, value, expiration)
38 +
func (db Redis) Set(key string, value []byte, expiration time.Duration) error {
39 +
	cmd := db.client.Set(key, value, expiration)
43 40
	if cmd.Err() != nil {
44 41
		return cmd.Err()
45 42
	}
46 43
	return nil
47 44
}
48 45
49 -
func (db Redis) Delete(key string, ctx context.Context) error {
50 -
	client := apmgoredis.Wrap(&db.client).WithContext(ctx)
51 -
	cmd := client.Del(key)
46 +
func (db Redis) Delete(key string) error {
47 +
	cmd := db.client.Del(key)
52 48
	if cmd.Err() != nil {
53 49
		return cmd.Err()
54 50
	}

@@ -1,14 +1,14 @@
Loading
1 1
package tickerscontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
5 +
	"strings"
6 +
	"sync"
7 +
6 8
	log "github.com/sirupsen/logrus"
7 9
	"github.com/trustwallet/golibs/asset"
8 10
	"github.com/trustwallet/watchmarket/db/models"
9 11
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 -
	"strings"
11 -
	"sync"
12 12
)
13 13
14 14
type (
@@ -18,12 +18,12 @@
Loading
18 18
	}
19 19
)
20 20
21 -
func (c Controller) getTickersByPriority(tickerQueries []models.TickerQuery, ctx context.Context) (watchmarket.Tickers, error) {
21 +
func (c Controller) getTickersByPriority(tickerQueries []models.TickerQuery) (watchmarket.Tickers, error) {
22 22
	if c.configuration.RestAPI.UseMemoryCache {
23 23
		var results watchmarket.Tickers
24 24
		for _, tr := range tickerQueries {
25 25
			key := strings.ToLower(asset.BuildID(tr.Coin, tr.TokenId))
26 -
			rawResult, err := c.cache.Get(key, ctx)
26 +
			rawResult, err := c.cache.Get(key)
27 27
			if err != nil {
28 28
				continue
29 29
			}
@@ -36,7 +36,7 @@
Loading
36 36
		return results, nil
37 37
	}
38 38
39 -
	dbTickers, err := c.database.GetTickersByQueries(tickerQueries, ctx)
39 +
	dbTickers, err := c.database.GetTickersByQueries(tickerQueries)
40 40
	if err != nil {
41 41
		log.Error(err, "getTickersByPriority")
42 42
		return nil, err

@@ -1,11 +1,11 @@
Loading
1 1
package rediscache
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
6 5
	"errors"
7 -
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
8 6
	"strconv"
7 +
8 +
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
9 9
)
10 10
11 11
type CachedInterval struct {
@@ -14,22 +14,22 @@
Loading
14 14
	Key       string
15 15
}
16 16
17 -
func (i Instance) GetWithTime(key string, time int64, ctx context.Context) ([]byte, error) {
17 +
func (i Instance) GetWithTime(key string, time int64) ([]byte, error) {
18 18
	var (
19 19
		keyInterval string
20 20
		data        []byte
21 21
	)
22 -
	keyInterval, err := i.getIntervalKey(key, time, ctx)
22 +
	keyInterval, err := i.getIntervalKey(key, time)
23 23
	if err != nil {
24 24
		return data, err
25 25
	}
26 26
27 -
	cacheData, err := i.redis.Get(keyInterval, ctx)
27 +
	cacheData, err := i.redis.Get(keyInterval)
28 28
	if err == nil {
29 29
		return cacheData, err
30 30
	}
31 31
32 -
	err = i.redis.Delete(keyInterval, ctx)
32 +
	err = i.redis.Delete(keyInterval)
33 33
	if err != nil {
34 34
		return data, errors.New("invalid cache is not deleted")
35 35
	}
@@ -37,7 +37,7 @@
Loading
37 37
	return data, errors.New("cache is not valid")
38 38
}
39 39
40 -
func (i Instance) SetWithTime(key string, data []byte, time int64, ctx context.Context) error {
40 +
func (i Instance) SetWithTime(key string, data []byte, time int64) error {
41 41
	if data == nil {
42 42
		return errors.New("data is empty")
43 43
	}
@@ -49,22 +49,22 @@
Loading
49 49
		Key:       cachingKey,
50 50
	}
51 51
52 -
	err := i.updateInterval(key, interval, ctx)
52 +
	err := i.updateInterval(key, interval)
53 53
	if err != nil {
54 54
		return err
55 55
	}
56 56
57 -
	err = i.redis.Set(cachingKey, data, i.cachingPeriod, ctx)
57 +
	err = i.redis.Set(cachingKey, data, i.cachingPeriod)
58 58
	if err != nil {
59 59
		return err
60 60
	}
61 61
	return nil
62 62
}
63 63
64 -
func (i Instance) getIntervalKey(key string, time int64, ctx context.Context) (string, error) {
64 +
func (i Instance) getIntervalKey(key string, time int64) (string, error) {
65 65
	var currentIntervals []CachedInterval
66 66
67 -
	rawIntervals, err := i.redis.Get(key, ctx)
67 +
	rawIntervals, err := i.redis.Get(key)
68 68
	if err != nil {
69 69
		return "", err
70 70
	}
@@ -91,10 +91,10 @@
Loading
91 91
	return results[0], nil
92 92
}
93 93
94 -
func (i Instance) updateInterval(key string, interval CachedInterval, ctx context.Context) error {
94 +
func (i Instance) updateInterval(key string, interval CachedInterval) error {
95 95
	var currentIntervals []CachedInterval
96 96
97 -
	rawIntervals, err := i.redis.Get(key, ctx)
97 +
	rawIntervals, err := i.redis.Get(key)
98 98
	if err != nil && err.Error() != "not found" {
99 99
		return err
100 100
	}
@@ -120,7 +120,7 @@
Loading
120 120
		return err
121 121
	}
122 122
123 -
	err = i.redis.Set(key, rawNewIntervalsRaw, i.cachingPeriod, ctx)
123 +
	err = i.redis.Set(key, rawNewIntervalsRaw, i.cachingPeriod)
124 124
	if err != nil {
125 125
		return err
126 126
	}

@@ -1,14 +1,14 @@
Loading
1 1
package tickerscontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
5 +
	"strings"
6 +
6 7
	"github.com/trustwallet/watchmarket/config"
7 8
	"github.com/trustwallet/watchmarket/db"
8 9
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
9 10
	"github.com/trustwallet/watchmarket/services/cache"
10 11
	"github.com/trustwallet/watchmarket/services/controllers"
11 -
	"strings"
12 12
)
13 13
14 14
type Controller struct {
@@ -34,42 +34,42 @@
Loading
34 34
	}
35 35
}
36 36
37 -
func (c Controller) HandleTickersRequestV2(tr controllers.TickerRequestV2, ctx context.Context) (controllers.TickerResponseV2, error) {
37 +
func (c Controller) HandleTickersRequestV2(tr controllers.TickerRequestV2) (controllers.TickerResponseV2, error) {
38 38
	if tr.Ids == nil || len(tr.Ids) >= c.configuration.RestAPI.RequestLimit {
39 39
		return controllers.TickerResponseV2{}, errors.New(watchmarket.ErrBadRequest)
40 40
	}
41 41
42 -
	rate, err := c.getRateByPriority(strings.ToUpper(tr.Currency), ctx)
42 +
	rate, err := c.getRateByPriority(strings.ToUpper(tr.Currency))
43 43
	if err != nil {
44 44
		return controllers.TickerResponseV2{}, errors.New(watchmarket.ErrNotFound)
45 45
	}
46 46
47 -
	tickers, err := c.getTickersByPriority(makeTickerQueriesV2(tr.Ids), ctx)
47 +
	tickers, err := c.getTickersByPriority(makeTickerQueriesV2(tr.Ids))
48 48
	if err != nil {
49 49
		return controllers.TickerResponseV2{}, errors.New(watchmarket.ErrInternal)
50 50
	}
51 51
52 -
	tickers = c.normalizeTickers(tickers, rate, ctx)
52 +
	tickers = c.normalizeTickers(tickers, rate)
53 53
54 54
	return createResponseV2(tr, tickers), nil
55 55
}
56 56
57 -
func (c Controller) HandleTickersRequest(tr controllers.TickerRequest, ctx context.Context) (controllers.TickerResponse, error) {
57 +
func (c Controller) HandleTickersRequest(tr controllers.TickerRequest) (controllers.TickerResponse, error) {
58 58
	if tr.Assets == nil || len(tr.Assets) >= c.configuration.RestAPI.RequestLimit {
59 59
		return controllers.TickerResponse{}, errors.New(watchmarket.ErrBadRequest)
60 60
	}
61 61
62 -
	rate, err := c.getRateByPriority(strings.ToUpper(tr.Currency), ctx)
62 +
	rate, err := c.getRateByPriority(strings.ToUpper(tr.Currency))
63 63
	if err != nil {
64 64
		return controllers.TickerResponse{}, errors.New(watchmarket.ErrNotFound)
65 65
	}
66 66
67 -
	tickers, err := c.getTickersByPriority(makeTickerQueries(tr.Assets), ctx)
67 +
	tickers, err := c.getTickersByPriority(makeTickerQueries(tr.Assets))
68 68
	if err != nil {
69 69
		return controllers.TickerResponse{}, errors.New(watchmarket.ErrInternal)
70 70
	}
71 71
72 -
	tickers = c.normalizeTickers(tickers, rate, ctx)
72 +
	tickers = c.normalizeTickers(tickers, rate)
73 73
74 74
	return createResponse(tr, tickers), nil
75 75
}

@@ -1,44 +1,39 @@
Loading
1 1
package worker
2 2
3 3
import (
4 -
	"context"
4 +
	"sync"
5 +
5 6
	log "github.com/sirupsen/logrus"
6 7
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 8
	"github.com/trustwallet/watchmarket/services/markets"
8 -
	"go.elastic.co/apm"
9 -
	"sync"
10 9
)
11 10
12 11
func (w Worker) FetchAndSaveTickers() {
13 -
	tx := apm.DefaultTracer.StartTransaction("FetchAndSaveTickers", "app")
14 -
	ctx := apm.ContextWithTransaction(context.Background(), tx)
15 -
	defer tx.End()
16 -
17 12
	log.Info("Fetching Tickers ...")
18 -
	fetchedTickers := fetchTickers(w.tickersApis, ctx)
13 +
	fetchedTickers := fetchTickers(w.tickersApis)
19 14
	normalizedTickers := toTickersModel(fetchedTickers)
20 15
21 -
	if err := w.db.AddTickers(normalizedTickers, w.configuration.Worker.BatchLimit, ctx); err != nil {
16 +
	if err := w.db.AddTickers(normalizedTickers, w.configuration.Worker.BatchLimit); err != nil {
22 17
		log.Error(err)
23 18
	}
24 19
}
25 20
26 -
func fetchTickers(tickersApis markets.TickersAPIs, ctx context.Context) watchmarket.Tickers {
21 +
func fetchTickers(tickersApis markets.TickersAPIs) watchmarket.Tickers {
27 22
	wg := new(sync.WaitGroup)
28 23
	s := new(tickers)
29 24
	for _, t := range tickersApis {
30 25
		wg.Add(1)
31 -
		go fetchTickersByProvider(t, wg, s, ctx)
26 +
		go fetchTickersByProvider(t, wg, s)
32 27
	}
33 28
	wg.Wait()
34 29
35 30
	return s.tickers
36 31
}
37 32
38 -
func fetchTickersByProvider(t markets.TickersAPI, wg *sync.WaitGroup, s *tickers, ctx context.Context) {
33 +
func fetchTickersByProvider(t markets.TickersAPI, wg *sync.WaitGroup, s *tickers) {
39 34
	defer wg.Done()
40 35
41 -
	tickers, err := t.GetTickers(ctx)
36 +
	tickers, err := t.GetTickers()
42 37
	if err != nil {
43 38
		log.WithFields(log.Fields{"provider": t.GetProvider(), "details": err}).Error("Failed to fetch tickers")
44 39
		return

@@ -1,21 +1,21 @@
Loading
1 1
package coinmarketcap
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
6 5
	"fmt"
7 -
	log "github.com/sirupsen/logrus"
8 -
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
9 6
	"sort"
10 7
	"strings"
11 8
	"time"
9 +
10 +
	log "github.com/sirupsen/logrus"
11 +
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
12 12
)
13 13
14 14
const (
15 15
	chartDataSize = 3
16 16
)
17 17
18 -
func (p Provider) GetChartData(coinID uint, token, currency string, timeStart int64, ctx context.Context) (watchmarket.Chart, error) {
18 +
func (p Provider) GetChartData(coinID uint, token, currency string, timeStart int64) (watchmarket.Chart, error) {
19 19
	chartsData := watchmarket.Chart{}
20 20
	coinsFromCmcMap := CmcSlice(p.Cm).coinToCmcMap()
21 21
	coinObj, err := coinsFromCmcMap.getCoinByContract(coinID, token)
@@ -28,25 +28,25 @@
Loading
28 28
	timeStartDate := time.Unix(timeStart, 0)
29 29
	days := int(time.Since(timeStartDate).Hours() / 24)
30 30
	timeEnd := time.Now().Unix()
31 -
	c, err := p.client.fetchChartsData(coinObj.Id, currency, timeStart, timeEnd, getInterval(days), ctx)
31 +
	c, err := p.client.fetchChartsData(coinObj.Id, currency, timeStart, timeEnd, getInterval(days))
32 32
	if err != nil {
33 33
		return chartsData, err
34 34
	}
35 35
	return normalizeCharts(currency, c), nil
36 36
}
37 37
38 -
func (p Provider) GetCoinData(coinID uint, token, currency string, ctx context.Context) (watchmarket.CoinDetails, error) {
38 +
func (p Provider) GetCoinData(coinID uint, token, currency string) (watchmarket.CoinDetails, error) {
39 39
	details := watchmarket.CoinDetails{}
40 40
	coinsFromCmcMap := CmcSlice(p.Cm).coinToCmcMap()
41 41
	coinObj, err := coinsFromCmcMap.getCoinByContract(coinID, token)
42 42
	if err != nil {
43 43
		return details, err
44 44
	}
45 -
	priceData, err := p.client.fetchCoinData(coinObj.Id, currency, ctx)
45 +
	priceData, err := p.client.fetchCoinData(coinObj.Id, currency)
46 46
	if err != nil {
47 47
		return details, err
48 48
	}
49 -
	assetsData, err := p.info.GetCoinInfo(coinID, token, ctx)
49 +
	assetsData, err := p.info.GetCoinInfo(coinID, token)
50 50
	if err != nil {
51 51
		log.WithFields(log.Fields{"coinID": coinID, "token": token}).Warn("No assets assets about that coinID")
52 52
	}

@@ -1,13 +1,13 @@
Loading
1 1
package memory
2 2
3 3
import (
4 -
	"context"
5 4
	"crypto/sha1"
6 5
	"encoding/base64"
7 6
	"errors"
7 +
	"time"
8 +
8 9
	gocache "github.com/patrickmn/go-cache"
9 10
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 -
	"time"
11 11
)
12 12
13 13
type Instance struct {
@@ -30,12 +30,12 @@
Loading
30 30
	return base64.URLEncoding.EncodeToString(hash[:])
31 31
}
32 32
33 -
func (i Instance) Set(key string, data []byte, ctx context.Context) error {
33 +
func (i Instance) Set(key string, data []byte) error {
34 34
	i.Cache.Set(key, data, gocache.NoExpiration)
35 35
	return nil
36 36
}
37 37
38 -
func (i Instance) Get(key string, ctx context.Context) ([]byte, error) {
38 +
func (i Instance) Get(key string) ([]byte, error) {
39 39
	res, ok := i.Cache.Get(key)
40 40
	if !ok {
41 41
		return nil, errors.New(watchmarket.ErrNotFound)
@@ -43,11 +43,11 @@
Loading
43 43
	return res.([]byte), nil
44 44
}
45 45
46 -
func (i Instance) SetWithTime(key string, data []byte, time int64, ctx context.Context) error {
46 +
func (i Instance) SetWithTime(key string, data []byte, time int64) error {
47 47
	return nil
48 48
}
49 49
50 -
func (i Instance) GetWithTime(key string, time int64, ctx context.Context) ([]byte, error) {
50 +
func (i Instance) GetWithTime(key string, time int64) ([]byte, error) {
51 51
	return nil, nil
52 52
}
53 53

@@ -1,12 +1,12 @@
Loading
1 1
package rediscache
2 2
3 3
import (
4 -
	"context"
5 4
	"crypto/sha1"
6 5
	"encoding/base64"
7 6
	"errors"
8 -
	"github.com/trustwallet/watchmarket/redis"
9 7
	"time"
8 +
9 +
	"github.com/trustwallet/watchmarket/redis"
10 10
)
11 11
12 12
type Instance struct {
@@ -30,19 +30,19 @@
Loading
30 30
	return base64.URLEncoding.EncodeToString(hash[:])
31 31
}
32 32
33 -
func (i Instance) Get(key string, ctx context.Context) ([]byte, error) {
34 -
	raw, err := i.redis.Get(key, ctx)
33 +
func (i Instance) Get(key string) ([]byte, error) {
34 +
	raw, err := i.redis.Get(key)
35 35
	if err != nil {
36 36
		return nil, err
37 37
	}
38 38
	return raw, nil
39 39
}
40 40
41 -
func (i Instance) Set(key string, data []byte, ctx context.Context) error {
41 +
func (i Instance) Set(key string, data []byte) error {
42 42
	if data == nil {
43 43
		return errors.New("data is empty")
44 44
	}
45 -
	err := i.redis.Set(key, data, i.cachingPeriod, ctx)
45 +
	err := i.redis.Set(key, data, i.cachingPeriod)
46 46
	if err != nil {
47 47
		return err
48 48
	}

@@ -1,15 +1,15 @@
Loading
1 1
package coingecko
2 2
3 3
import (
4 -
	"context"
5 4
	"fmt"
6 -
	"github.com/imroc/req"
7 -
	log "github.com/sirupsen/logrus"
8 5
	"net/url"
9 6
	"strconv"
10 7
	"strings"
11 8
	"sync"
12 9
	"time"
10 +
11 +
	"github.com/imroc/req"
12 +
	log "github.com/sirupsen/logrus"
13 13
)
14 14
15 15
type Client struct {
@@ -25,7 +25,7 @@
Loading
25 25
	return c
26 26
}
27 27
28 -
func (c Client) fetchCharts(id, currency string, timeStart, timeEnd int64, ctx context.Context) (Charts, error) {
28 +
func (c Client) fetchCharts(id, currency string, timeStart, timeEnd int64) (Charts, error) {
29 29
	var (
30 30
		result Charts
31 31
		values = req.Param{
@@ -34,7 +34,7 @@
Loading
34 34
			"to":          strconv.FormatInt(timeEnd, 10),
35 35
		}
36 36
	)
37 -
	resp, err := c.r.Get(c.baseURL+fmt.Sprintf("/v3/coins/%s/market_chart/range", id), values, ctx)
37 +
	resp, err := c.r.Get(c.baseURL+fmt.Sprintf("/v3/coins/%s/market_chart/range", id), values)
38 38
	if err != nil {
39 39
		return Charts{}, err
40 40
	}
@@ -47,7 +47,7 @@
Loading
47 47
	return result, nil
48 48
}
49 49
50 -
func (c Client) fetchRates(coins Coins, currency string, ctx context.Context) (prices CoinPrices) {
50 +
func (c Client) fetchRates(coins Coins, currency string) (prices CoinPrices) {
51 51
	ci := coins.coinIds()
52 52
53 53
	i := 0
@@ -64,7 +64,7 @@
Loading
64 64
			bucket := ci[i:end]
65 65
			ids := strings.Join(bucket[:], ",")
66 66
67 -
			cp, err := c.fetchMarkets(ids, currency, ctx)
67 +
			cp, err := c.fetchMarkets(ids, currency)
68 68
			if err != nil {
69 69
				log.Error(err)
70 70
				return
@@ -87,13 +87,13 @@
Loading
87 87
	return
88 88
}
89 89
90 -
func (c Client) fetchMarkets(ids, currency string, ctx context.Context) (CoinPrices, error) {
90 +
func (c Client) fetchMarkets(ids, currency string) (CoinPrices, error) {
91 91
	var (
92 92
		result CoinPrices
93 93
		values = url.Values{"vs_currency": {currency}, "sparkline": {"false"}, "ids": {ids}}
94 94
	)
95 95
96 -
	resp, err := c.r.Get(c.baseURL+"/v3/coins/markets", values, ctx)
96 +
	resp, err := c.r.Get(c.baseURL+"/v3/coins/markets", values)
97 97
	if err != nil {
98 98
		return CoinPrices{}, err
99 99
	}
@@ -106,9 +106,9 @@
Loading
106 106
	return result, nil
107 107
}
108 108
109 -
func (c Client) fetchCoins(ctx context.Context) (Coins, error) {
109 +
func (c Client) fetchCoins() (Coins, error) {
110 110
	var result Coins
111 -
	resp, err := c.r.Get(c.baseURL+"/v3/coins/list", req.Param{"include_platform": "true"}, ctx)
111 +
	resp, err := c.r.Get(c.baseURL+"/v3/coins/list", req.Param{"include_platform": "true"})
112 112
	if err != nil {
113 113
		return Coins{}, err
114 114
	}

@@ -1,11 +1,11 @@
Loading
1 1
package coinmarketcap
2 2
3 3
import (
4 -
	"context"
5 4
	"fmt"
5 +
	"strconv"
6 +
6 7
	"github.com/imroc/req"
7 8
	log "github.com/sirupsen/logrus"
8 -
	"strconv"
9 9
)
10 10
11 11
type Client struct {
@@ -26,14 +26,14 @@
Loading
26 26
	}
27 27
}
28 28
29 -
func (c Client) fetchPrices(currency string, ctx context.Context) (CoinPrices, error) {
29 +
func (c Client) fetchPrices(currency string) (CoinPrices, error) {
30 30
	var (
31 31
		result CoinPrices
32 32
		path   = c.proApiURL + "/v1/cryptocurrency/listings/latest"
33 33
		header = req.Header{"X-CMC_PRO_API_KEY": c.key}
34 34
	)
35 35
36 -
	resp, err := c.r.Get(path, req.Param{"limit": "5000", "convert": currency}, header, ctx)
36 +
	resp, err := c.r.Get(path, req.Param{"limit": "5000", "convert": currency}, header)
37 37
	if err != nil {
38 38
		return CoinPrices{}, err
39 39
	}
@@ -46,7 +46,7 @@
Loading
46 46
	return result, nil
47 47
}
48 48
49 -
func (c Client) fetchChartsData(id uint, currency string, timeStart int64, timeEnd int64, interval string, ctx context.Context) (Charts, error) {
49 +
func (c Client) fetchChartsData(id uint, currency string, timeStart int64, timeEnd int64, interval string) (Charts, error) {
50 50
	values := req.Param{
51 51
		"convert":    currency,
52 52
		"format":     "chart_crypto_details",
@@ -56,7 +56,7 @@
Loading
56 56
		"interval":   interval,
57 57
	}
58 58
	var result Charts
59 -
	resp, err := c.r.Get(c.webApiURL+"/v1/cryptocurrency/quotes/historical", values, ctx)
59 +
	resp, err := c.r.Get(c.webApiURL+"/v1/cryptocurrency/quotes/historical", values)
60 60
	if err != nil {
61 61
		return Charts{}, err
62 62
	}
@@ -69,13 +69,13 @@
Loading
69 69
	return result, nil
70 70
}
71 71
72 -
func (c Client) fetchCoinData(id uint, currency string, ctx context.Context) (ChartInfo, error) {
72 +
func (c Client) fetchCoinData(id uint, currency string) (ChartInfo, error) {
73 73
	values := req.Param{
74 74
		"convert": currency,
75 75
		"ref":     "widget",
76 76
	}
77 77
	var result ChartInfo
78 -
	resp, err := c.r.Get(c.widgetApiURL+fmt.Sprintf("/v2/ticker/%d", id), values, ctx)
78 +
	resp, err := c.r.Get(c.widgetApiURL+fmt.Sprintf("/v2/ticker/%d", id), values)
79 79
	if err != nil {
80 80
		return ChartInfo{}, err
81 81
	}

@@ -1,9 +1,9 @@
Loading
1 1
package infocontroller
2 2
3 3
import (
4 -
	"context"
5 4
	"encoding/json"
6 5
	"errors"
6 +
7 7
	log "github.com/sirupsen/logrus"
8 8
	"github.com/trustwallet/watchmarket/config"
9 9
	"github.com/trustwallet/watchmarket/db"
@@ -43,7 +43,7 @@
Loading
43 43
	}
44 44
}
45 45
46 -
func (c Controller) HandleInfoRequest(dr controllers.DetailsRequest, ctx context.Context) (controllers.InfoResponse, error) {
46 +
func (c Controller) HandleInfoRequest(dr controllers.DetailsRequest) (controllers.InfoResponse, error) {
47 47
	var cd controllers.InfoResponse
48 48
49 49
	req, err := toDetailsRequestData(dr)
@@ -53,14 +53,14 @@
Loading
53 53
54 54
	key := c.cache.GenerateKey(info + dr.CoinQuery + dr.Token + dr.Currency)
55 55
56 -
	cachedDetails, err := c.cache.Get(key, ctx)
56 +
	cachedDetails, err := c.cache.Get(key)
57 57
	if err == nil && len(cachedDetails) > 0 {
58 58
		if json.Unmarshal(cachedDetails, &cd) == nil {
59 59
			return cd, nil
60 60
		}
61 61
	}
62 62
63 -
	result, err := c.getDetailsByPriority(req, ctx)
63 +
	result, err := c.getDetailsByPriority(req)
64 64
	if err != nil {
65 65
		return controllers.InfoResponse{}, errors.New(watchmarket.ErrInternal)
66 66
	}
@@ -75,7 +75,7 @@
Loading
75 75
	}
76 76
77 77
	if result.Info != nil {
78 -
		err = c.cache.Set(key, newCache, ctx)
78 +
		err = c.cache.Set(key, newCache)
79 79
		if err != nil {
80 80
			log.WithFields(log.Fields{"err": err}).Error("failed to save cache")
81 81
		}

@@ -1,17 +1,17 @@
Loading
1 1
package coingecko
2 2
3 3
import (
4 -
	"context"
5 -
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
6 4
	"strings"
5 +
6 +
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
7 7
)
8 8
9 -
func (p Provider) GetRates(ctx context.Context) (watchmarket.Rates, error) {
10 -
	coins, err := p.client.fetchCoins(ctx)
9 +
func (p Provider) GetRates() (watchmarket.Rates, error) {
10 +
	coins, err := p.client.fetchCoins()
11 11
	if err != nil {
12 12
		return watchmarket.Rates{}, err
13 13
	}
14 -
	prices := p.client.fetchRates(coins, p.currency, ctx)
14 +
	prices := p.client.fetchRates(coins, p.currency)
15 15
16 16
	return normalizeRates(prices, p.id), nil
17 17
}

@@ -1,15 +1,15 @@
Loading
1 1
package coinmarketcap
2 2
3 3
import (
4 -
	"context"
5 4
	"errors"
5 +
	"strings"
6 +
6 7
	"github.com/trustwallet/golibs/coin"
7 8
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
8 -
	"strings"
9 9
)
10 10
11 -
func (p Provider) GetTickers(ctx context.Context) (watchmarket.Tickers, error) {
12 -
	prices, err := p.client.fetchPrices(p.currency, ctx)
11 +
func (p Provider) GetTickers() (watchmarket.Tickers, error) {
12 +
	prices, err := p.client.fetchPrices(p.currency)
13 13
	if err != nil {
14 14
		return nil, err
15 15
	}

@@ -1,15 +1,15 @@
Loading
1 1
package tickerscontroller
2 2
3 3
import (
4 -
	"context"
4 +
	"strings"
5 +
	"sync"
6 +
5 7
	log "github.com/sirupsen/logrus"
6 8
	"github.com/trustwallet/golibs/asset"
7 9
	"github.com/trustwallet/watchmarket/config"
8 10
	"github.com/trustwallet/watchmarket/db/models"
9 11
	"github.com/trustwallet/watchmarket/pkg/watchmarket"
10 12
	"github.com/trustwallet/watchmarket/services/controllers"
11 -
	"strings"
12 -
	"sync"
13 13
)
14 14
15 15
func createResponse(tr controllers.TickerRequest, tickers watchmarket.Tickers) controllers.TickerResponse {
@@ -72,10 +72,10 @@
Loading
72 72
	return tickerQueries
73 73
}
74 74
75 -
func (c Controller) normalizeTickers(tickers watchmarket.Tickers, rate watchmarket.Rate, ctx context.Context) watchmarket.Tickers {
75 +
func (c Controller) normalizeTickers(tickers watchmarket.Tickers, rate watchmarket.Rate) watchmarket.Tickers {
76 76
	result := make(watchmarket.Tickers, 0, len(tickers))
77 77
	for _, t := range tickers {
78 -
		r, ok := c.rateToDefaultCurrency(t, rate, ctx)
78 +
		r, ok := c.rateToDefaultCurrency(t, rate)
79 79
		if !ok {
80 80
			continue
81 81
		}
Files Coverage
services 66%
api/api.go 95%
pkg/watchmarket/models.go 83%
redis/redis.go 50%
Project Totals (38 files) 66%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading