diff --git a/packages/indexer-database/packages/indexer-database/src/migrations/1733941169940-HistoricPrice.ts b/packages/indexer-database/packages/indexer-database/src/migrations/1733941169940-HistoricPrice.ts deleted file mode 100644 index b6489e5..0000000 --- a/packages/indexer-database/packages/indexer-database/src/migrations/1733941169940-HistoricPrice.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class HistoricPrice1733941169940 implements MigrationInterface { - name = 'HistoricPrice1733941169940' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "historic_market_price" ("id" SERIAL NOT NULL, "baseCurrency" character varying NOT NULL, "quoteCurrency" character varying NOT NULL DEFAULT 'usd', "date" date NOT NULL, "price" numeric NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UK_historic_price_baseCurrency_quoteCurrency_date" UNIQUE ("baseCurrency", "quoteCurrency", "date"), CONSTRAINT "PK_b0a22436b47e742187aa7408561" PRIMARY KEY ("id"))`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "historic_market_price"`); - } - -} diff --git a/packages/indexer-database/packages/indexer-database/src/migrations/1734549610006-HistoricPrice.ts b/packages/indexer-database/packages/indexer-database/src/migrations/1734549610006-HistoricPrice.ts deleted file mode 100644 index b4986e5..0000000 --- a/packages/indexer-database/packages/indexer-database/src/migrations/1734549610006-HistoricPrice.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class HistoricPrice1734549610006 implements MigrationInterface { - name = 'HistoricPrice1734549610006' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE TABLE "historic_price" ("id" SERIAL NOT NULL, "baseCurrency" character varying NOT NULL, "quoteCurrency" character varying NOT NULL DEFAULT 'usd', "date" character varying NOT NULL, "price" numeric NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UK_historic_price_baseCurrency_quoteCurrency_date" UNIQUE ("baseCurrency", "quoteCurrency", "date"), CONSTRAINT "PK_77dc3f4978cdfb03f1bb3a7444b" PRIMARY KEY ("id"))`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP TABLE "historic_price"`); - } - -} diff --git a/packages/indexer-database/src/entities/HistoricPrice.ts b/packages/indexer-database/src/entities/HistoricPrice.ts index f11c4b7..f9124c1 100644 --- a/packages/indexer-database/src/entities/HistoricPrice.ts +++ b/packages/indexer-database/src/entities/HistoricPrice.ts @@ -24,8 +24,8 @@ export class HistoricPrice { quoteCurrency: string; // yyyy-LL-dd - @Column() - date: string; + @Column({ type: "date" }) + date: Date; @Column({ type: "decimal" }) price: string; diff --git a/packages/indexer-database/src/migrations/1734616435674-HistoricPrice.ts b/packages/indexer-database/src/migrations/1734616435674-HistoricPrice.ts new file mode 100644 index 0000000..1144242 --- /dev/null +++ b/packages/indexer-database/src/migrations/1734616435674-HistoricPrice.ts @@ -0,0 +1,15 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class HistoricPrice1734616435674 implements MigrationInterface { + name = "HistoricPrice1734616435674"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `CREATE TABLE "historic_price" ("id" SERIAL NOT NULL, "baseCurrency" character varying NOT NULL, "quoteCurrency" character varying NOT NULL DEFAULT 'usd', "date" date NOT NULL, "price" numeric NOT NULL, "createdAt" TIMESTAMP NOT NULL DEFAULT now(), CONSTRAINT "UK_historic_price_baseCurrency_quoteCurrency_date" UNIQUE ("baseCurrency", "quoteCurrency", "date"), CONSTRAINT "PK_77dc3f4978cdfb03f1bb3a7444b" PRIMARY KEY ("id"))`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP TABLE "historic_price"`); + } +} diff --git a/packages/indexer/README.md b/packages/indexer/README.md index 1e4de20..f1bcf7c 100644 --- a/packages/indexer/README.md +++ b/packages/indexer/README.md @@ -51,4 +51,8 @@ ENABLE_HUBPOOL_INDEXER=true ENABLE_BUNDLE_EVENTS_PROCESSOR=true ENABLE_BUNDLE_INCLUDED_EVENTS_SERVICE=true ENABLE_BUNDLE_BUILDER=true + +# use symbols defined in /home/dev/src/risklabs/indexer/packages/indexer/src/utils/coingeckoClient.ts +# separate them by comma, no spaces +COINGECKO_SYMBOLS=ethereum,optimism,across-protocol ``` diff --git a/packages/indexer/src/services/priceProcessor.ts b/packages/indexer/src/services/priceProcessor.ts index aac2695..8e392d5 100644 --- a/packages/indexer/src/services/priceProcessor.ts +++ b/packages/indexer/src/services/priceProcessor.ts @@ -27,7 +27,12 @@ export class CoingeckoPriceProcessor extends BaseIndexer { protected async indexerLogic(): Promise { const now = Date.now(); - const dbFormattedDate = DateTime.fromMillis(now).toFormat("yyyy-LL-dd"); + // we are always checking if we have the price for previous day, not the current day, so we go back + // to right before midnight of last day. + const previousDay = DateTime.fromMillis(now) + .minus({ days: 1 }) + .set({ hour: 23, minute: 59, second: 0, millisecond: 0 }); + const dbFormattedDate = previousDay.toJSDate(); const quoteCurrency = this.config.quoteCurrency ?? "usd"; const historicPriceRepository = this.deps.postgres.getRepository( entities.HistoricPrice,