Skip to content

createCryptoPackage

function createCryptoPackage(config?): IEnginePackage;

Defined in: packages/engine/src/packages/crypto/CryptoPackage.ts:29

Live crypto prices, crypto("BTC"), returning the current price of one coin as a currency value.

Because the price comes back as ordinary money, the rest of the language does the conversion for free: 0.5 * crypto("BTC") is the value of half a coin, and crypto("ETH") in GBP converts through the currency package. So the “0.5 BTC in USD” a reader wants is 0.5 * crypto("BTC"), in whatever currency the provider quotes (US dollars by default).

A factory, not a constant, and not in BUILTIN_PACKAGES, for the same reason as stocks: there is no free, keyless crypto price API to bundle, so the host supplies fetchPrice (backed by whichever provider and key they have) via createCryptoPackage. Without it, a crypto expression resolves to a clearly-worded CRYPTO_NOT_CONFIGURED error, never a faked price. A host that wants it calls createCryptoPackage({ fetchPrice }) and adds the result to its engine’s packages array.

ParameterType
configCryptoPackageConfig

IEnginePackage