@exodus/market-history 5.1.0 → 5.3.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 +12 -0
- package/api/index.js +15 -0
- package/index.js +2 -0
- package/package.json +8 -3
- package/redux/selectors/get-asset-daily-price.js +29 -0
- package/redux/selectors/get-asset-hourly-price.js +30 -0
- package/redux/selectors/get-daily-price.js +17 -0
- package/redux/selectors/get-hourly-price.js +17 -0
- package/redux/selectors/helpers/append-prices-with-rate.js +16 -0
- package/redux/selectors/helpers/date-utils.js +40 -0
- package/redux/selectors/helpers/memoize-get-asset-price.js +11 -0
- package/redux/selectors/helpers/memoize-get-price.js +20 -0
- package/redux/selectors/index.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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.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
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- more market-history selectors ([#3476](https://github.com/ExodusMovement/exodus-hydra/issues/3476)) ([fb4a2c7](https://github.com/ExodusMovement/exodus-hydra/commit/fb4a2c72666016b8624269268eefa3755b599d86))
|
|
11
|
+
|
|
12
|
+
## [5.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.1.0...@exodus/market-history@5.2.0) (2023-08-21)
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
- **@exodus/market-history:** add api definition ([#3488](https://github.com/ExodusMovement/exodus-hydra/issues/3488)) ([b9b1e8b](https://github.com/ExodusMovement/exodus-hydra/commit/b9b1e8b9cb61d94ad21274883b18f2f08dc7db53))
|
|
17
|
+
|
|
6
18
|
## [5.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/market-history@5.0.1...@exodus/market-history@5.1.0) (2023-08-17)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/api/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const createMarketHistoryApi = ({ marketHistoryMonitor }) => {
|
|
2
|
+
return {
|
|
3
|
+
marketHistory: {
|
|
4
|
+
update: marketHistoryMonitor.update,
|
|
5
|
+
},
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line @exodus/export-default/named
|
|
10
|
+
export default {
|
|
11
|
+
id: 'marketHistoryApi',
|
|
12
|
+
type: 'api',
|
|
13
|
+
factory: createMarketHistoryApi,
|
|
14
|
+
dependencies: ['marketHistoryMonitor'],
|
|
15
|
+
}
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import marketHistoryMonitorDefinition from './module'
|
|
8
8
|
|
|
9
9
|
import marketHistoryPluginDefinition from './plugin'
|
|
10
|
+
import marketHistoryApiDefinition from './api'
|
|
10
11
|
|
|
11
12
|
const marketHistory = () => {
|
|
12
13
|
return {
|
|
@@ -46,6 +47,7 @@ const marketHistory = () => {
|
|
|
46
47
|
},
|
|
47
48
|
{ definition: marketHistoryPluginDefinition },
|
|
48
49
|
{ definition: marketHistoryAtomDefinition },
|
|
50
|
+
{ definition: marketHistoryApiDefinition },
|
|
49
51
|
],
|
|
50
52
|
}
|
|
51
53
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/market-history",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.0",
|
|
4
4
|
"description": "Fetches historical prices for assets",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"main": "index.js",
|
|
13
13
|
"files": [
|
|
14
|
+
"api",
|
|
14
15
|
"module",
|
|
15
16
|
"atoms",
|
|
16
17
|
"plugin",
|
|
@@ -24,14 +25,18 @@
|
|
|
24
25
|
"@exodus/basic-utils": "^2.0.0",
|
|
25
26
|
"@exodus/module": "^1.1.0",
|
|
26
27
|
"@exodus/price-api": "^3.2.1",
|
|
28
|
+
"lodash": "^4.17.21",
|
|
27
29
|
"ms": "^0.7.1",
|
|
28
30
|
"reselect": "^3.0.1"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
|
-
"@exodus/assets": "^8.0.
|
|
33
|
+
"@exodus/assets": "^8.0.94",
|
|
32
34
|
"@exodus/assets-base": "^8.1.6",
|
|
33
35
|
"@exodus/atoms": "^5.5.0",
|
|
36
|
+
"@exodus/bitcoin-meta": "^1.0.1",
|
|
37
|
+
"@exodus/ethereum-meta": "^1.0.30",
|
|
34
38
|
"@exodus/locale": "^1.2.1",
|
|
39
|
+
"@exodus/rates-monitor": "^3.3.1",
|
|
35
40
|
"@exodus/redux-dependency-injection": "^1.0.2",
|
|
36
41
|
"@exodus/storage-memory": "^2.1.0",
|
|
37
42
|
"eslint": "^8.44.0",
|
|
@@ -50,5 +55,5 @@
|
|
|
50
55
|
"type": "git",
|
|
51
56
|
"url": "git+https://github.com/ExodusMovement/exodus-hydra.git"
|
|
52
57
|
},
|
|
53
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "ee684d008b5f2d2c1f9340d9c19a491e4d851f9f"
|
|
54
59
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { memoize } from 'lodash'
|
|
2
|
+
import { createSelector } from 'reselect'
|
|
3
|
+
import memoizeGetAssetPrice from './helpers/memoize-get-asset-price'
|
|
4
|
+
|
|
5
|
+
const createGetAssetDailyPriceSelector = {
|
|
6
|
+
id: 'getAssetDailyPrice',
|
|
7
|
+
selectorFactory: (
|
|
8
|
+
getAssetDailyPricesSelector,
|
|
9
|
+
createAssetRateSelector,
|
|
10
|
+
startOfHourTimeSelector
|
|
11
|
+
) =>
|
|
12
|
+
memoize((assetName) =>
|
|
13
|
+
createSelector(
|
|
14
|
+
(state) => getAssetDailyPricesSelector(state)(assetName),
|
|
15
|
+
createAssetRateSelector(assetName),
|
|
16
|
+
startOfHourTimeSelector,
|
|
17
|
+
(assetDailyPrices, rate, currentTime) =>
|
|
18
|
+
memoizeGetAssetPrice(assetDailyPrices, rate, 'daily', currentTime)
|
|
19
|
+
)
|
|
20
|
+
),
|
|
21
|
+
dependencies: [
|
|
22
|
+
//
|
|
23
|
+
{ selector: 'getAssetDailyPrices' },
|
|
24
|
+
{ selector: 'assetRate', module: 'rates' },
|
|
25
|
+
{ selector: 'startOfHourTime', module: 'external' },
|
|
26
|
+
],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default createGetAssetDailyPriceSelector
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { memoize } from 'lodash'
|
|
2
|
+
|
|
3
|
+
import { createSelector } from 'reselect'
|
|
4
|
+
import memoizeGetAssetPrices from './helpers/memoize-get-asset-price'
|
|
5
|
+
|
|
6
|
+
const createGetAssetHourlyPriceSelector = {
|
|
7
|
+
id: 'getAssetHourlyPrice',
|
|
8
|
+
selectorFactory: (
|
|
9
|
+
getAssetHourlyPricesSelector,
|
|
10
|
+
createAssetRateSelector,
|
|
11
|
+
startOfHourTimeSelector
|
|
12
|
+
) =>
|
|
13
|
+
memoize((assetName) =>
|
|
14
|
+
createSelector(
|
|
15
|
+
(state) => getAssetHourlyPricesSelector(state)(assetName),
|
|
16
|
+
createAssetRateSelector(assetName),
|
|
17
|
+
startOfHourTimeSelector,
|
|
18
|
+
(assetHourlyPrices, rate, currentTime) =>
|
|
19
|
+
memoizeGetAssetPrices(assetHourlyPrices, rate, 'hourly', currentTime)
|
|
20
|
+
)
|
|
21
|
+
),
|
|
22
|
+
dependencies: [
|
|
23
|
+
//
|
|
24
|
+
{ selector: 'getAssetHourlyPrices' },
|
|
25
|
+
{ selector: 'assetRate', module: 'rates' },
|
|
26
|
+
{ selector: 'startOfHourTime', module: 'external' },
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default createGetAssetHourlyPriceSelector
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import memoizeGetPrices from './helpers/memoize-get-price'
|
|
2
|
+
|
|
3
|
+
const resultFunction = (getAssetDailyPrices, rates, assets) =>
|
|
4
|
+
memoizeGetPrices(getAssetDailyPrices, rates, 'daily', assets)
|
|
5
|
+
|
|
6
|
+
const getDailyPriceSelector = {
|
|
7
|
+
id: 'getDailyPrice',
|
|
8
|
+
resultFunction,
|
|
9
|
+
dependencies: [
|
|
10
|
+
//
|
|
11
|
+
{ selector: 'getAssetDailyPrices' },
|
|
12
|
+
{ selector: 'fiatRates', module: 'rates' },
|
|
13
|
+
{ selector: 'allAssets', module: 'external' },
|
|
14
|
+
],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default getDailyPriceSelector
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import memoizeGetPrices from './helpers/memoize-get-price'
|
|
2
|
+
|
|
3
|
+
const resultFunction = (getAssetHourlyPrices, rates, assets) =>
|
|
4
|
+
memoizeGetPrices(getAssetHourlyPrices, rates, 'hourly', assets)
|
|
5
|
+
|
|
6
|
+
const getHourlyPriceSelector = {
|
|
7
|
+
id: 'getHourlyPrice',
|
|
8
|
+
resultFunction,
|
|
9
|
+
dependencies: [
|
|
10
|
+
//
|
|
11
|
+
{ selector: 'getAssetHourlyPrices' },
|
|
12
|
+
{ selector: 'fiatRates', module: 'rates' },
|
|
13
|
+
{ selector: 'allAssets', module: 'external' },
|
|
14
|
+
],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default getHourlyPriceSelector
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { prepareTime } from './date-utils'
|
|
2
|
+
|
|
3
|
+
const appendPricesWithRate = ({ historicalPrices = {}, rate, type, currentTime }) => {
|
|
4
|
+
if (historicalPrices instanceof Error) return null
|
|
5
|
+
if (rate && rate.price) {
|
|
6
|
+
const time = prepareTime(new Date(currentTime), type)
|
|
7
|
+
return {
|
|
8
|
+
...historicalPrices,
|
|
9
|
+
[time]: rate.price,
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return historicalPrices
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default appendPricesWithRate
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function cloneDate(date) {
|
|
2
|
+
return new Date(date.getTime())
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function startOfHour(date) {
|
|
6
|
+
return new Date(
|
|
7
|
+
Date.UTC(
|
|
8
|
+
date.getUTCFullYear(),
|
|
9
|
+
date.getUTCMonth(),
|
|
10
|
+
date.getUTCDate(),
|
|
11
|
+
date.getUTCHours(),
|
|
12
|
+
0,
|
|
13
|
+
0,
|
|
14
|
+
0
|
|
15
|
+
)
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function startOfDay(date) {
|
|
20
|
+
const cd = cloneDate(date)
|
|
21
|
+
cd.setUTCHours(0, 0, 0, 0)
|
|
22
|
+
return cd
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const prepareTime = (date, type) => {
|
|
26
|
+
let preparedTime
|
|
27
|
+
switch (type) {
|
|
28
|
+
case 'daily': {
|
|
29
|
+
preparedTime = startOfDay(date)
|
|
30
|
+
break
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
case 'hourly': {
|
|
34
|
+
preparedTime = startOfHour(date)
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return preparedTime.valueOf()
|
|
40
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import appendPricesWithRate from './append-prices-with-rate'
|
|
2
|
+
import { memoize } from 'lodash'
|
|
3
|
+
import { prepareTime } from './date-utils'
|
|
4
|
+
|
|
5
|
+
const memoizeGetAssetPrices = (historicalPrices, rate, type, currentTime) => {
|
|
6
|
+
const allPrices = appendPricesWithRate({ historicalPrices, rate, type, currentTime })
|
|
7
|
+
|
|
8
|
+
return memoize((time) => allPrices?.[prepareTime(time, type)] || null)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default memoizeGetAssetPrices
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import appendPricesWithRate from './append-prices-with-rate'
|
|
2
|
+
import { memoize } from 'lodash'
|
|
3
|
+
import { prepareTime } from './date-utils'
|
|
4
|
+
|
|
5
|
+
const memoizeGetPrices = (getAssetPrices, rates, type, assets) => {
|
|
6
|
+
const getHistoricalPrice = (assetName, time) => {
|
|
7
|
+
const rate = rates[assets[assetName].ticker]
|
|
8
|
+
const historicalPrices = getAssetPrices(assetName)
|
|
9
|
+
const pricesWithRate = appendPricesWithRate({ historicalPrices, rate, type })
|
|
10
|
+
|
|
11
|
+
return pricesWithRate?.[prepareTime(time, type)] || null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return memoize(
|
|
15
|
+
(assetName, time) => getHistoricalPrice(assetName, time),
|
|
16
|
+
(assetName, time) => `${time.valueOf()}-${assetName}`
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default memoizeGetPrices
|
package/redux/selectors/index.js
CHANGED
|
@@ -7,6 +7,10 @@ import dailyPricesSelector from './daily-prices'
|
|
|
7
7
|
import hourlyPricesSelector from './hourly-prices'
|
|
8
8
|
import getAssetDailyPricesSelector from './get-asset-daily-prices'
|
|
9
9
|
import getAssetHourlyPricesSelector from './get-asset-hourly-prices'
|
|
10
|
+
import createGetAssetDailyPriceSelector from './get-asset-daily-price'
|
|
11
|
+
import createGetAssetHourlyPriceSelector from './get-asset-hourly-price'
|
|
12
|
+
import getDailyPriceSelector from './get-daily-price'
|
|
13
|
+
import getHourlyPriceSelector from './get-hourly-price'
|
|
10
14
|
|
|
11
15
|
export default [
|
|
12
16
|
marketHistoryLoadingSelector,
|
|
@@ -17,4 +21,8 @@ export default [
|
|
|
17
21
|
hourlyPricesSelector,
|
|
18
22
|
getAssetDailyPricesSelector,
|
|
19
23
|
getAssetHourlyPricesSelector,
|
|
24
|
+
createGetAssetDailyPriceSelector,
|
|
25
|
+
createGetAssetHourlyPriceSelector,
|
|
26
|
+
getDailyPriceSelector,
|
|
27
|
+
getHourlyPriceSelector,
|
|
20
28
|
]
|