Add api key for coingecko api in notional jobs (#1259)
Co-authored-by: walker-16 <agpazos85@gmail.com>
This commit is contained in:
parent
e55f6e35e3
commit
36e6c0a715
|
@ -6,4 +6,6 @@ metadata:
|
||||||
namespace: {{ .NAMESPACE }}
|
namespace: {{ .NAMESPACE }}
|
||||||
data:
|
data:
|
||||||
aws-region: {{ .AWS_REGION }}
|
aws-region: {{ .AWS_REGION }}
|
||||||
aws-bucket: {{ .AWS_BUCKET }}
|
aws-bucket: {{ .AWS_BUCKET }}
|
||||||
|
coingecko-url: {{ .COINGECKO_URL }}
|
||||||
|
coingecko-header-key: {{ .COINGECKO_HEADER_KEY }}
|
||||||
|
|
|
@ -24,7 +24,20 @@ spec:
|
||||||
- name: JOB_ID
|
- name: JOB_ID
|
||||||
value: JOB_NOTIONAL_USD
|
value: JOB_NOTIONAL_USD
|
||||||
- name: COINGECKO_URL
|
- name: COINGECKO_URL
|
||||||
value: {{ .COINGECKO_URL }}
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: jobs
|
||||||
|
key: coingecko-url
|
||||||
|
- name: COINGECKO_HEADER_KEY
|
||||||
|
valueFrom:
|
||||||
|
configMapKeyRef:
|
||||||
|
name: jobs
|
||||||
|
key: coingecko-header-key
|
||||||
|
- name: COINGECKO_API_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: jobs
|
||||||
|
key: coingecko-api-key
|
||||||
- name: NOTIONAL_CHANNEL
|
- name: NOTIONAL_CHANNEL
|
||||||
value: {{ .NOTIONAL_CHANNEL }}
|
value: {{ .NOTIONAL_CHANNEL }}
|
||||||
- name: CACHE_URL
|
- name: CACHE_URL
|
||||||
|
|
|
@ -103,9 +103,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// initNotionalJob initializes notional job.
|
// initNotionalJob initializes notional job.
|
||||||
func initNotionalJob(ctx context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob {
|
func initNotionalJob(_ context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob {
|
||||||
// init coingecko api client.
|
// init coingecko api client.
|
||||||
api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, logger)
|
api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, cfg.CoingeckoHeaderKey, cfg.CoingeckoApiKey, logger)
|
||||||
// init redis client.
|
// init redis client.
|
||||||
redisClient := redis.NewClient(&redis.Options{Addr: cfg.CacheURL})
|
redisClient := redis.NewClient(&redis.Options{Addr: cfg.CacheURL})
|
||||||
// init token provider.
|
// init token provider.
|
||||||
|
|
|
@ -9,14 +9,16 @@ type Configuration struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotionalConfiguration struct {
|
type NotionalConfiguration struct {
|
||||||
Environment string `env:"ENVIRONMENT,required"`
|
Environment string `env:"ENVIRONMENT,required"`
|
||||||
CoingeckoURL string `env:"COINGECKO_URL,required"`
|
CoingeckoURL string `env:"COINGECKO_URL,required"`
|
||||||
CacheURL string `env:"CACHE_URL,required"`
|
CoingeckoHeaderKey string `env:"COINGECKO_HEADER_KEY"`
|
||||||
CachePrefix string `env:"CACHE_PREFIX,required"`
|
CoingeckoApiKey string `env:"COINGECKO_API_KEY"`
|
||||||
NotionalChannel string `env:"NOTIONAL_CHANNEL,required"`
|
CacheURL string `env:"CACHE_URL,required"`
|
||||||
P2pNetwork string `env:"P2P_NETWORK,required"`
|
CachePrefix string `env:"CACHE_PREFIX,required"`
|
||||||
AwsRegion string `env:"AWS_REGION"`
|
NotionalChannel string `env:"NOTIONAL_CHANNEL,required"`
|
||||||
AwsBucket string `env:"AWS_BUCKET"`
|
P2pNetwork string `env:"P2P_NETWORK,required"`
|
||||||
|
AwsRegion string `env:"AWS_REGION"`
|
||||||
|
AwsBucket string `env:"AWS_BUCKET"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TransferReportConfiguration struct {
|
type TransferReportConfiguration struct {
|
||||||
|
|
|
@ -17,14 +17,18 @@ type CoingeckoAPI struct {
|
||||||
chunkSize int
|
chunkSize int
|
||||||
client *http.Client
|
client *http.Client
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
|
headerKey string
|
||||||
|
apiKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCoingeckoAPI creates a new coingecko client
|
// NewCoingeckoAPI creates a new coingecko client
|
||||||
func NewCoingeckoAPI(url string, logger *zap.Logger) *CoingeckoAPI {
|
func NewCoingeckoAPI(url string, headerKey, apiKey string, logger *zap.Logger) *CoingeckoAPI {
|
||||||
return &CoingeckoAPI{
|
return &CoingeckoAPI{
|
||||||
url: url,
|
url: url,
|
||||||
chunkSize: 200,
|
chunkSize: 200,
|
||||||
client: http.DefaultClient,
|
client: http.DefaultClient,
|
||||||
|
headerKey: headerKey,
|
||||||
|
apiKey: apiKey,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,12 +49,16 @@ func (c *CoingeckoAPI) GetNotionalUSD(ids []string) (map[string]NotionalUSD, err
|
||||||
// iterate over chunks of ids.
|
// iterate over chunks of ids.
|
||||||
for i, chunk := range chunksIds {
|
for i, chunk := range chunksIds {
|
||||||
|
|
||||||
notionalUrl := fmt.Sprintf("%s/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ","))
|
notionalUrl := fmt.Sprintf("%s/api/v3/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ","))
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, notionalUrl, nil)
|
req, err := http.NewRequest(http.MethodGet, notionalUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
if c.headerKey != "" && c.apiKey != "" {
|
||||||
|
req.Header.Add(c.headerKey, c.apiKey)
|
||||||
|
}
|
||||||
|
|
||||||
res, err := c.client.Do(req)
|
res, err := c.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
|
|
Loading…
Reference in New Issue