diff --git a/history/src/app/history/index.types.d.ts b/history/src/app/history/index.types.d.ts index aadbd73..24def67 100644 --- a/history/src/app/history/index.types.d.ts +++ b/history/src/app/history/index.types.d.ts @@ -2,7 +2,3 @@ type GetPriceHistoryArgs = { currency: string range?: string } - -type NotifyPriceChangeArgs = { - range?: PriceRange -} diff --git a/history/src/app/history/notify-price-change.ts b/history/src/app/history/notify-price-change.ts index e150225..08973a2 100644 --- a/history/src/app/history/notify-price-change.ts +++ b/history/src/app/history/notify-price-change.ts @@ -4,14 +4,14 @@ import { checkedToCurrency } from "@domain/primitives" import { PriceRepository } from "@services/database" import { NotificationsService } from "@services/notifications" -export const notifyPriceChange = async ({ range }: NotifyPriceChangeArgs) => { +export const notifyPriceChange = async () => { const quote = checkedToCurrency("USD") if (quote instanceof Error) { return quote } - const rangeToQuery = range || PriceRange.OneDay + const rangeToQuery = PriceRange.OneDay const prices = await PriceRepository().listPrices({ base: defaultBaseCurrency, quote, diff --git a/history/src/config/process.ts b/history/src/config/process.ts index c432d6c..7c21b42 100644 --- a/history/src/config/process.ts +++ b/history/src/config/process.ts @@ -13,4 +13,5 @@ export const databaseConfig = { debug: process.env.DB_DEBUG === "true", } -export const notificationsEndpoint = process.env.notificationsEndpoint || "localhost:6685" +export const notificationsEndpoint = + process.env.NOTIFICATIONS_ENDPOINT || "localhost:6685" diff --git a/history/src/services/notifications/price-changed-event.ts b/history/src/services/notifications/price-changed-event.ts index 4c8c51f..ffa9f76 100644 --- a/history/src/services/notifications/price-changed-event.ts +++ b/history/src/services/notifications/price-changed-event.ts @@ -20,7 +20,7 @@ export const createPriceChangedEvent = ({ const usdMajorUnitToMinorUnit = (usd: number) => usd * 100 const calculatePriceChangePercentage = (initialPrice: Price, finalPrice: Price) => { - const percentage = ((finalPrice - initialPrice) / initialPrice) * 100 + const percentage = Math.abs(((finalPrice - initialPrice) / initialPrice) * 100) const direction = finalPrice > initialPrice ? PriceChangeDirection.UP : PriceChangeDirection.DOWN