This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix zero usd price service exception (#102)
* fix: remove thrown exception in validation * test: update to cover amount down to 0 sats & cents Co-authored-by: Sebastien Verreault <sebver@pm.me>
- Loading branch information
1 parent
65fb314
commit e22cad5
Showing
3 changed files
with
240 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { baseLogger } from "../../services/logger" | ||
import { toCents, toSats } from "../../utils" | ||
import { DealerPriceService } from "./client_service" | ||
import { DealerPriceServiceError } from "./errors" | ||
|
||
const priceService = DealerPriceService() | ||
const fewMins = (2 * 60) as Seconds | ||
export const run = async function () { | ||
for (let sats = 100; sats >= 0; sats--) { | ||
const someSats = toSats(sats) | ||
const result = await priceService.getCentsFromSatsForImmediateBuy(someSats) | ||
baseLogger.info( | ||
{ someSats, result }, | ||
`GetCentsFromSatsForImmediateBuy({someSats}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let sats = 100; sats >= 0; sats--) { | ||
const someSats = toSats(sats) | ||
const result = await priceService.getCentsFromSatsForImmediateSell(someSats) | ||
baseLogger.info( | ||
{ someSats, result }, | ||
`GetCentsFromSatsForImmediateSell({someSats}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let sats = 100; sats >= 0; sats--) { | ||
const someSats = toSats(sats) | ||
const result = await priceService.getCentsFromSatsForFutureBuy(someSats, fewMins) | ||
baseLogger.info( | ||
{ someSats, fewMins, result }, | ||
`GetCentsFromSatsForFutureBuy({someSats}, {fewMins}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let sats = 100; sats >= 0; sats--) { | ||
const someSats = toSats(sats) | ||
const result = await priceService.getCentsFromSatsForFutureSell(someSats, fewMins) | ||
baseLogger.info( | ||
{ someSats, fewMins, result }, | ||
`getCentsFromSatsForFutureSell({someSats}, {fewMins}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
|
||
for (let cents = 100; cents >= 0; cents--) { | ||
const someUsd = toCents(cents) | ||
const result = await priceService.getSatsFromCentsForImmediateBuy(someUsd) | ||
baseLogger.info( | ||
{ someUsd, result }, | ||
`getSatsFromCentsForImmediateBuy({someUsd}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let cents = 100; cents >= 0; cents--) { | ||
const someUsd = toCents(cents) | ||
const result = await priceService.getSatsFromCentsForImmediateSell(someUsd) | ||
baseLogger.info( | ||
{ someUsd, result }, | ||
`getSatsFromCentsForImmediateSell({someUsd}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let cents = 100; cents >= 0; cents--) { | ||
const someUsd = toCents(cents) | ||
const result = await priceService.getSatsFromCentsForFutureBuy(someUsd, fewMins) | ||
baseLogger.info( | ||
{ someUsd, fewMins, result }, | ||
`getSatsFromCentsForFutureBuy({someUsd}, {fewMins}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
for (let cents = 100; cents >= 0; cents--) { | ||
const someUsd = toCents(cents) | ||
const result = await priceService.getSatsFromCentsForFutureSell(someUsd, fewMins) | ||
baseLogger.info( | ||
{ someUsd, fewMins, result }, | ||
`getSatsFromCentsForFutureSell({someUsd}, {fewMins}) returned: {result}`, | ||
) | ||
if (result instanceof DealerPriceServiceError) { | ||
break | ||
} | ||
} | ||
|
||
baseLogger.info( | ||
`getCentsPerSatsExchangeMidRate from service: ${await priceService.getCentsPerSatsExchangeMidRate()}`, | ||
) | ||
} | ||
|
||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters