Skip to content

Commit

Permalink
fix migration, add docs, use date for database
Browse files Browse the repository at this point in the history
Signed-off-by: david <[email protected]>
  • Loading branch information
daywiss committed Dec 19, 2024
1 parent 141acc1 commit 4bb3196
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 31 deletions.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions packages/indexer-database/src/entities/HistoricPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class HistoricPrice1734616435674 implements MigrationInterface {
name = "HistoricPrice1734616435674";

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.query(`DROP TABLE "historic_price"`);
}
}
4 changes: 4 additions & 0 deletions packages/indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 6 additions & 1 deletion packages/indexer/src/services/priceProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export class CoingeckoPriceProcessor extends BaseIndexer {

protected async indexerLogic(): Promise<void> {
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,
Expand Down

0 comments on commit 4bb3196

Please sign in to comment.