Skip to content

Commit

Permalink
Merge pull request #26 from Cardinal-Cryptography/cmn-654_coingecko-i…
Browse files Browse the repository at this point in the history
…ntegration

QoF improvements
  • Loading branch information
deuszx authored May 27, 2024
2 parents 15489db + 4b8347f commit e3fcbe2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel=silent
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ format: # Formats the code.

.PHONY: local-up
local-up: # Starts the app.
npm run start
@npm run start

.PHONY: dev-up
dev-up: # Starts the app using dev environment GraphQL db.
export NODE_APP_INSTANCE=dev && npm run start

.PHONY: local-prod
local-prod: # Starts the app using prod environment GraphQL db.
export NODE_APP_INSTANCE=prod && npm run start

.PHONY: show-envs
show-envs: # Shows the environment variables that are set.
@(env | grep 'COMMON_API_' || true)
4 changes: 0 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const config = require("config");

export class Config {
enablePriceCache: boolean;
enableDemoMode: boolean;
enableGraphql: boolean;
http: {
Expand Down Expand Up @@ -46,9 +45,6 @@ export class Config {
? config.priceCacheInvaliditySeconds
: 3600);

this.enablePriceCache = process.env.COMMON_API_ENABLE_PRICE_CACHE
? process.env.COMMON_API_ENABLE_PRICE_CACHE === "true"
: true;
this.enableDemoMode = process.env.COMMON_API_ENABLE_DEMO_MODE
? process.env.COMMON_API_ENABLE_DEMO_MODE === "true"
: false;
Expand Down
64 changes: 31 additions & 33 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function updatePools(
import { Logger, ILogObj } from "tslog";

export const log: Logger<ILogObj> = new Logger({
stylePrettyLogs: false,
prettyLogTemplate:
"{{logLevelName}}\t{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t[{{filePathWithLine}}{{name}}]\t",
});
Expand Down Expand Up @@ -68,39 +69,36 @@ async function main(): Promise<void> {
rest.poolsV2Endpoints(app, pools);
rest.healthcheckEnpoint(app, config);

if (config.enablePriceCache) {
log.info("USD price cache enabled");

const azeroUsdPriceCache = new UsdPriceCache(
"aleph-zero",
config.priceCacheInvaliditySeconds,
);
const ethUsdPriceCache = new UsdPriceCache(
"ethereum",
config.priceCacheInvaliditySeconds,
);
const bitcoinUsdPriceCache = new UsdPriceCache(
"bitcoin",
config.priceCacheInvaliditySeconds,
);
const usdtUsdPriceCache = new UsdPriceCache(
"tether",
config.priceCacheInvaliditySeconds,
);
const usdcUsdPriceCache = new UsdPriceCache(
"usd-coin",
config.priceCacheInvaliditySeconds,
);

rest.usdPriceEndpoints(
app,
azeroUsdPriceCache,
ethUsdPriceCache,
bitcoinUsdPriceCache,
usdtUsdPriceCache,
usdcUsdPriceCache,
);
}
log.info("USD price cache enabled");
const azeroUsdPriceCache = new UsdPriceCache(
"aleph-zero",
config.priceCacheInvaliditySeconds,
);
const ethUsdPriceCache = new UsdPriceCache(
"ethereum",
config.priceCacheInvaliditySeconds,
);
const bitcoinUsdPriceCache = new UsdPriceCache(
"bitcoin",
config.priceCacheInvaliditySeconds,
);
const usdtUsdPriceCache = new UsdPriceCache(
"tether",
config.priceCacheInvaliditySeconds,
);
const usdcUsdPriceCache = new UsdPriceCache(
"usd-coin",
config.priceCacheInvaliditySeconds,
);

rest.usdPriceEndpoints(
app,
azeroUsdPriceCache,
ethUsdPriceCache,
bitcoinUsdPriceCache,
usdtUsdPriceCache,
usdcUsdPriceCache,
);

if (config.enableDemoMode || config.enableGraphql) {
const wsServer = new WebSocketServer(config.ws, () => {
Expand Down
1 change: 0 additions & 1 deletion src/servers/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const addressRegex = /[\w\d]{48}/;
export function healthcheckEnpoint(app: express.Express, config: Config) {
app.get("/health", (_req, res) => {
const status = {
priceCacheEnabled: config.enablePriceCache,
demoModeEnabled: config.enableDemoMode,
graphqlUpdatesEnabled: config.enableGraphql,
};
Expand Down

0 comments on commit e3fcbe2

Please sign in to comment.