@exodus/市场历史
这个Exodus SDK的特性跟踪了不同间隔的每日和每小时的历史资产价格. 它会按时间间隔返回价格 close。 。 。 .
安装
pnpm add @exodus/market-history
使用量
此特性设计为与 @exodus/headless。见 使用 sdk。 。 。 .
来玩吧
- 打开游乐场 https://exodus-hydra.pages.dev/features/市场-历史
- 运行
selectors.marketHistory.getAssetDailyPrice('bitcoin')(store.getState())(new Date())在 Dev 工具控制台中. - 试试其他选择者
selectors.marketHistory。参见示例使用 测试。 。 。 .
API 边
见 使用 sdk 更多关于特性插入SDK的细节.
如果你正在建造一个需要历史资产价格的特征, 加上对 marketHistoryAtom,用于存储以下形状的数据:
{
// most recent data
data: {
USD: {
daily: {
bitcoin: {
1663668000000: 90000,
}
}
}
},
// changes since the last update
changes: {
USD: {
daily: {
bitcoin: {
1663671600000: 9000,
}
}
}
}
}
市场历史定期更新,但如果需要紧急调整特定颗粒的价格,可以使用:
exodus.marketHistory.update(granularity) // granularity = 'daily' | 'hourly'
如果您需要装入特定日期的价格 :
await exodus.marketHistory.fetchAssetPricesFromDate({
assetName: 'bitcoin',
granularity: 'day',
startTimestamp,
})
// `marketHistoryAtom` gets updated, new prices are available via selectors
UI 侧
见 使用 sdk 关于基本UI侧设置的更多细节.
import selectors from '~/ui/flux/selectors'
const MyComponent = () => {
const getBitcoinDailyPrice = useSelector(selectors.marketHistory.getAssetDailyPrice('bitcoin'))
const bitcoinPrice = getBitcoinDailyPrice(new Date()) // Number, in the user's current currency
}