@exodus/market-history 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [5.4.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.3.0...@exodus/market-history@5.4.0) (2023-08-22)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- get-price-with-fallback ([#3502](https://github.com/ExodusMovement/exodus-hydra/issues/3502)) ([a816c1d](https://github.com/ExodusMovement/exodus-hydra/commit/a816c1d9bf259119d962ce53d41f9b5087e821b4))
|
|
11
|
+
|
|
6
12
|
## [5.3.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.2.0...@exodus/market-history@5.3.0) (2023-08-21)
|
|
7
13
|
|
|
8
14
|
### Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/market-history",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.4.0",
|
|
4
4
|
"description": "Fetches historical prices for assets",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"type": "git",
|
|
56
56
|
"url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "7d0999f99995004e6898784dbbbc9c303a97806a"
|
|
59
59
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const getFiatValueWithFallbackSelector = {
|
|
2
|
+
id: 'getFiatValueWithFallback',
|
|
3
|
+
resultFunction: (getPriceWithFallback) => {
|
|
4
|
+
return ({ assetName, time, type, amount }) => {
|
|
5
|
+
if (!amount) return 0
|
|
6
|
+
const price = getPriceWithFallback(assetName, time, type)
|
|
7
|
+
if (!price) return 0
|
|
8
|
+
return price * amount
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
dependencies: [
|
|
12
|
+
//
|
|
13
|
+
{ selector: 'getPriceWithFallback' },
|
|
14
|
+
],
|
|
15
|
+
}
|
|
16
|
+
export default getFiatValueWithFallbackSelector
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { memoize } from 'lodash'
|
|
2
|
+
import ms from 'ms'
|
|
3
|
+
|
|
4
|
+
const PERIOD_TO_MS = {
|
|
5
|
+
hourly: ms('1h'),
|
|
6
|
+
daily: ms('1d'),
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const MAX_STEPS = 24
|
|
10
|
+
const STEPS_BY_TYPE = {
|
|
11
|
+
hourly: MAX_STEPS,
|
|
12
|
+
daily: 2,
|
|
13
|
+
}
|
|
14
|
+
const findLastPrice = ({ getPrice, assetName, time, period }) => {
|
|
15
|
+
let i = 0
|
|
16
|
+
const steps = STEPS_BY_TYPE[period]
|
|
17
|
+
while (i < steps) {
|
|
18
|
+
const newTime = time - PERIOD_TO_MS[period] * i
|
|
19
|
+
const price = getPrice(assetName, new Date(newTime))
|
|
20
|
+
if (price) return price
|
|
21
|
+
i++
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const getPriceWithFallbackSelector = {
|
|
28
|
+
id: 'getPriceWithFallback',
|
|
29
|
+
resultFunction: (getDailyPrice, getHourlyPrice) => {
|
|
30
|
+
const fnByType = {
|
|
31
|
+
daily: getDailyPrice,
|
|
32
|
+
hourly: getHourlyPrice,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return memoize(
|
|
36
|
+
(assetName, time, type) => {
|
|
37
|
+
const getPrice = fnByType[type]
|
|
38
|
+
|
|
39
|
+
return findLastPrice({ getPrice, assetName, time, period: type })
|
|
40
|
+
},
|
|
41
|
+
(assetName, time, type) => `${type}-${time.valueOf()}-${assetName}`
|
|
42
|
+
)
|
|
43
|
+
},
|
|
44
|
+
dependencies: [
|
|
45
|
+
//
|
|
46
|
+
{ selector: 'getDailyPrice' },
|
|
47
|
+
{ selector: 'getHourlyPrice' },
|
|
48
|
+
],
|
|
49
|
+
}
|
|
50
|
+
export default getPriceWithFallbackSelector
|
package/redux/selectors/index.js
CHANGED
|
@@ -11,6 +11,8 @@ import createGetAssetDailyPriceSelector from './get-asset-daily-price'
|
|
|
11
11
|
import createGetAssetHourlyPriceSelector from './get-asset-hourly-price'
|
|
12
12
|
import getDailyPriceSelector from './get-daily-price'
|
|
13
13
|
import getHourlyPriceSelector from './get-hourly-price'
|
|
14
|
+
import getPriceWithFallbackSelector from './get-price-with-fallback'
|
|
15
|
+
import getFiatValueWithFallbackSelector from './get-fiat-value-with-fallback'
|
|
14
16
|
|
|
15
17
|
export default [
|
|
16
18
|
marketHistoryLoadingSelector,
|
|
@@ -25,4 +27,6 @@ export default [
|
|
|
25
27
|
createGetAssetHourlyPriceSelector,
|
|
26
28
|
getDailyPriceSelector,
|
|
27
29
|
getHourlyPriceSelector,
|
|
30
|
+
getPriceWithFallbackSelector,
|
|
31
|
+
getFiatValueWithFallbackSelector,
|
|
28
32
|
]
|