@quantform/core 0.6.7 → 0.7.0-beta.5
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/dist/as-readonly.d.ts +3 -0
- package/dist/as-readonly.d.ts.map +1 -0
- package/dist/as-readonly.js +8 -0
- package/dist/{domain → asset}/asset.d.ts +1 -0
- package/dist/asset/asset.d.ts.map +1 -0
- package/dist/{domain → asset}/asset.js +8 -5
- package/dist/{domain → asset}/asset.spec.d.ts.map +1 -1
- package/dist/{domain → asset}/asset.spec.js +12 -12
- package/dist/asset/index.d.ts +2 -0
- package/dist/asset/index.d.ts.map +1 -0
- package/dist/{adapter/paper → asset}/index.js +1 -2
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/dev.js +13 -9
- package/dist/cli/index.js +4 -4
- package/dist/cli/pull.d.ts.map +1 -1
- package/dist/cli/pull.js +48 -18
- package/dist/cli/{test.d.ts → replay.d.ts} +1 -1
- package/dist/cli/replay.d.ts.map +1 -0
- package/dist/cli/{test.js → replay.js} +16 -19
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +14 -9
- package/dist/component/distinct-until-timesamp-changed.d.ts +5 -0
- package/dist/component/distinct-until-timesamp-changed.d.ts.map +1 -0
- package/dist/component/distinct-until-timesamp-changed.js +9 -0
- package/dist/{domain → component}/error.d.ts +1 -1
- package/dist/component/error.d.ts.map +1 -0
- package/dist/component/index.d.ts +8 -0
- package/dist/component/index.d.ts.map +1 -0
- package/dist/{store → component}/index.js +7 -10
- package/dist/{domain → component}/ohlc-operator.d.ts +1 -1
- package/dist/component/ohlc-operator.d.ts.map +1 -0
- package/dist/{domain → component}/ohlc-operator.js +4 -4
- package/dist/component/ohlc-operator.spec.d.ts.map +1 -0
- package/dist/component/ohlc-operator.spec.js +110 -0
- package/dist/component/ohlc.d.ts.map +1 -0
- package/dist/{domain → component}/ohlc.spec.d.ts.map +1 -1
- package/dist/{domain → component}/ohlc.spec.js +3 -3
- package/dist/component/timeframe.d.ts.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +15 -0
- package/dist/defined.d.ts +3 -0
- package/dist/defined.d.ts.map +1 -0
- package/dist/defined.js +8 -0
- package/dist/exclude.d.ts +3 -0
- package/dist/exclude.d.ts.map +1 -0
- package/dist/exclude.js +8 -0
- package/dist/index.d.ts +25 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -67
- package/dist/{domain → instrument/commission}/commission.d.ts +1 -1
- package/dist/instrument/commission/commission.d.ts.map +1 -0
- package/dist/{domain → instrument/commission}/commission.js +2 -2
- package/dist/instrument/commission/commission.spec.d.ts.map +1 -0
- package/dist/{domain → instrument/commission}/commission.spec.js +6 -6
- package/dist/instrument/index.d.ts +3 -0
- package/dist/instrument/index.d.ts.map +1 -0
- package/dist/{adapter → instrument}/index.js +2 -5
- package/dist/{domain → instrument}/instrument.d.ts +4 -4
- package/dist/instrument/instrument.d.ts.map +1 -0
- package/dist/{domain → instrument}/instrument.js +11 -10
- package/dist/instrument/instrument.spec.d.ts.map +1 -0
- package/dist/{domain → instrument}/instrument.spec.js +10 -10
- package/dist/make-test-module.d.ts +13 -0
- package/dist/make-test-module.d.ts.map +1 -0
- package/dist/make-test-module.js +46 -0
- package/dist/module.d.ts +57 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +136 -0
- package/dist/module.spec.d.ts +2 -0
- package/dist/module.spec.d.ts.map +1 -0
- package/dist/module.spec.js +86 -0
- package/dist/not-found.d.ts +2 -0
- package/dist/not-found.d.ts.map +1 -0
- package/dist/{domain/component.js → not-found.js} +2 -0
- package/dist/replay/index.d.ts +7 -0
- package/dist/replay/index.d.ts.map +1 -0
- package/dist/replay/index.js +22 -0
- package/dist/replay/use-replay-coordinator.d.ts +10 -0
- package/dist/replay/use-replay-coordinator.d.ts.map +1 -0
- package/dist/replay/use-replay-coordinator.js +119 -0
- package/dist/replay/use-replay-options.d.ts +15 -0
- package/dist/replay/use-replay-options.d.ts.map +1 -0
- package/dist/replay/use-replay-options.js +20 -0
- package/dist/replay/use-replay-reader.d.ts +7 -0
- package/dist/replay/use-replay-reader.d.ts.map +1 -0
- package/dist/replay/use-replay-reader.js +32 -0
- package/dist/replay/use-replay-reader.spec.d.ts +2 -0
- package/dist/replay/use-replay-reader.spec.d.ts.map +1 -0
- package/dist/replay/use-replay-reader.spec.js +58 -0
- package/dist/replay/use-replay-storage.d.ts +10 -0
- package/dist/replay/use-replay-storage.d.ts.map +1 -0
- package/dist/replay/use-replay-storage.js +10 -0
- package/dist/replay/use-replay-writer.d.ts +6 -0
- package/dist/replay/use-replay-writer.d.ts.map +1 -0
- package/dist/replay/use-replay-writer.js +14 -0
- package/dist/replay/use-replay-writer.spec.d.ts +2 -0
- package/dist/replay/use-replay-writer.spec.d.ts.map +1 -0
- package/dist/replay/use-replay-writer.spec.js +53 -0
- package/dist/replay/use-replay.d.ts +10 -0
- package/dist/replay/use-replay.d.ts.map +1 -0
- package/dist/replay/use-replay.js +32 -0
- package/dist/replay/use-replay.spec.d.ts +2 -0
- package/dist/replay/use-replay.spec.d.ts.map +1 -0
- package/dist/replay/use-replay.spec.js +106 -0
- package/dist/replay/with-replay.d.ts +4 -0
- package/dist/replay/with-replay.d.ts.map +1 -0
- package/dist/replay/with-replay.js +8 -0
- package/dist/session/index.d.ts +4 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/{adapter/backtester → session}/index.js +3 -4
- package/dist/session/use-session-object.d.ts +18 -0
- package/dist/session/use-session-object.d.ts.map +1 -0
- package/dist/session/use-session-object.js +13 -0
- package/dist/session/use-session-storage.d.ts +2 -0
- package/dist/session/use-session-storage.d.ts.map +1 -0
- package/dist/session/use-session-storage.js +10 -0
- package/dist/session/use-session.d.ts +4 -0
- package/dist/session/use-session.d.ts.map +1 -0
- package/dist/session/use-session.js +7 -0
- package/dist/shared/datetime.d.ts +1 -1
- package/dist/shared/datetime.d.ts.map +1 -1
- package/dist/shared/decimals.d.ts.map +1 -1
- package/dist/shared/decimals.js +5 -0
- package/dist/shared/index.d.ts +0 -4
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +0 -4
- package/dist/simulator/index.d.ts +2 -0
- package/dist/simulator/index.d.ts.map +1 -0
- package/dist/simulator/index.js +17 -0
- package/dist/simulator/use-simulator.d.ts +2 -0
- package/dist/simulator/use-simulator.d.ts.map +1 -0
- package/dist/simulator/use-simulator.js +9 -0
- package/dist/simulator/use-simulator.spec.d.ts +2 -0
- package/dist/simulator/use-simulator.spec.d.ts.map +1 -0
- package/dist/simulator/use-simulator.spec.js +49 -0
- package/dist/storage/in-memory/in-memory-storage.d.ts +9 -0
- package/dist/storage/in-memory/in-memory-storage.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.factory.d.ts +6 -0
- package/dist/storage/in-memory/in-memory-storage.factory.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.factory.js +23 -0
- package/dist/storage/in-memory/in-memory-storage.js +72 -0
- package/dist/storage/in-memory/in-memory-storage.spec.d.ts +2 -0
- package/dist/storage/in-memory/in-memory-storage.spec.d.ts.map +1 -0
- package/dist/storage/in-memory/in-memory-storage.spec.js +167 -0
- package/dist/storage/in-memory/index.d.ts +3 -0
- package/dist/storage/in-memory/index.d.ts.map +1 -0
- package/dist/storage/in-memory/index.js +18 -0
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +4 -4
- package/dist/storage/storage.d.ts +51 -61
- package/dist/storage/storage.d.ts.map +1 -1
- package/dist/storage/storage.js +20 -85
- package/dist/storage/use-cache.d.ts +4 -0
- package/dist/storage/use-cache.d.ts.map +1 -0
- package/dist/storage/use-cache.js +34 -0
- package/dist/storage/use-cache.spec.d.ts +2 -0
- package/dist/storage/use-cache.spec.d.ts.map +1 -0
- package/dist/storage/use-cache.spec.js +36 -0
- package/dist/storage/use-storage-factory.d.ts +10 -0
- package/dist/storage/use-storage-factory.d.ts.map +1 -0
- package/dist/storage/use-storage-factory.js +14 -0
- package/dist/storage/use-storage.d.ts +3 -0
- package/dist/storage/use-storage.d.ts.map +1 -0
- package/dist/storage/use-storage.js +11 -0
- package/dist/strat.d.ts +7 -0
- package/dist/strat.d.ts.map +1 -0
- package/dist/strat.js +7 -0
- package/dist/use-execution-mode.d.ts +29 -0
- package/dist/use-execution-mode.d.ts.map +1 -0
- package/dist/use-execution-mode.js +37 -0
- package/dist/use-hash.d.ts +5 -0
- package/dist/use-hash.d.ts.map +1 -0
- package/dist/use-hash.js +7 -0
- package/dist/use-hash.spec.d.ts +2 -0
- package/dist/use-hash.spec.d.ts.map +1 -0
- package/dist/use-hash.spec.js +16 -0
- package/dist/use-lock.d.ts +9 -0
- package/dist/use-lock.d.ts.map +1 -0
- package/dist/use-lock.js +40 -0
- package/dist/{shared/logger.d.ts → use-logger.d.ts} +6 -7
- package/dist/use-logger.d.ts.map +1 -0
- package/dist/use-logger.js +37 -0
- package/dist/use-memo.d.ts +21 -0
- package/dist/use-memo.d.ts.map +1 -0
- package/dist/use-memo.js +35 -0
- package/dist/use-memo.spec.d.ts +2 -0
- package/dist/use-memo.spec.d.ts.map +1 -0
- package/dist/use-memo.spec.js +35 -0
- package/dist/use-request.d.ts +16 -0
- package/dist/use-request.d.ts.map +1 -0
- package/dist/use-request.js +27 -0
- package/dist/use-socket.d.ts +6 -0
- package/dist/use-socket.d.ts.map +1 -0
- package/dist/use-socket.js +52 -0
- package/dist/use-state.d.ts +4 -0
- package/dist/use-state.d.ts.map +1 -0
- package/dist/use-state.js +24 -0
- package/dist/use-state.spec.d.ts +2 -0
- package/dist/use-state.spec.d.ts.map +1 -0
- package/dist/use-state.spec.js +36 -0
- package/dist/use-timestamp.d.ts +2 -0
- package/dist/use-timestamp.d.ts.map +1 -0
- package/dist/use-timestamp.js +13 -0
- package/dist/use.d.ts +5 -0
- package/dist/use.d.ts.map +1 -0
- package/dist/use.js +20 -0
- package/dist/use.spec.d.ts +2 -0
- package/dist/use.spec.d.ts.map +1 -0
- package/dist/use.spec.js +47 -0
- package/package.json +13 -10
- package/src/as-readonly.ts +5 -0
- package/src/{domain → asset}/asset.spec.ts +1 -1
- package/src/{domain → asset}/asset.ts +5 -1
- package/src/asset/index.ts +1 -0
- package/src/cli/dev.ts +16 -11
- package/src/cli/index.ts +3 -3
- package/src/cli/pull.ts +20 -8
- package/src/cli/replay.ts +31 -0
- package/src/cli/run.ts +15 -11
- package/src/component/distinct-until-timesamp-changed.ts +11 -0
- package/src/{domain → component}/error.ts +1 -1
- package/src/component/index.ts +7 -0
- package/src/{domain → component}/ohlc-operator.spec.ts +1 -1
- package/src/{domain → component}/ohlc-operator.ts +1 -1
- package/src/{domain → component}/ohlc.spec.ts +1 -1
- package/src/core.ts +14 -0
- package/src/defined.ts +6 -0
- package/src/exclude.ts +9 -0
- package/src/index.ts +25 -79
- package/src/{domain → instrument/commission}/commission.spec.ts +2 -1
- package/src/instrument/index.ts +2 -0
- package/src/{domain → instrument}/instrument.spec.ts +1 -1
- package/src/{domain → instrument}/instrument.ts +9 -14
- package/src/make-test-module.ts +46 -0
- package/src/module.spec.ts +74 -0
- package/src/module.ts +156 -0
- package/src/not-found.ts +1 -0
- package/src/replay/index.ts +6 -0
- package/src/replay/use-replay-coordinator.ts +142 -0
- package/src/replay/use-replay-options.ts +23 -0
- package/src/replay/use-replay-reader.spec.ts +64 -0
- package/src/replay/use-replay-reader.ts +23 -0
- package/src/replay/use-replay-storage.ts +8 -0
- package/src/replay/use-replay-writer.spec.ts +56 -0
- package/src/replay/use-replay-writer.ts +17 -0
- package/src/replay/use-replay.spec.ts +132 -0
- package/src/replay/use-replay.ts +34 -0
- package/src/replay/with-replay.ts +10 -0
- package/src/session/index.ts +3 -0
- package/src/session/use-session-object.ts +26 -0
- package/src/session/use-session-storage.ts +9 -0
- package/src/session/use-session.ts +5 -0
- package/src/shared/decimals.ts +5 -0
- package/src/shared/index.ts +0 -4
- package/src/simulator/index.ts +1 -0
- package/src/simulator/use-simulator.spec.ts +54 -0
- package/src/simulator/use-simulator.ts +7 -0
- package/src/storage/in-memory/in-memory-storage.factory.ts +16 -0
- package/src/storage/in-memory/in-memory-storage.spec.ts +193 -0
- package/src/storage/in-memory/in-memory-storage.ts +80 -0
- package/src/storage/in-memory/index.ts +2 -0
- package/src/storage/index.ts +4 -4
- package/src/storage/storage.ts +63 -119
- package/src/storage/use-cache.spec.ts +31 -0
- package/src/storage/use-cache.ts +50 -0
- package/src/storage/use-storage-factory.ts +17 -0
- package/src/storage/use-storage.ts +11 -0
- package/src/strat.ts +7 -0
- package/src/use-execution-mode.ts +41 -0
- package/src/use-hash.spec.ts +16 -0
- package/src/use-hash.ts +5 -0
- package/src/use-lock.ts +52 -0
- package/src/use-logger.ts +47 -0
- package/src/use-memo.spec.ts +30 -0
- package/src/use-memo.ts +35 -0
- package/src/use-request.ts +47 -0
- package/src/use-socket.ts +59 -0
- package/src/use-state.spec.ts +31 -0
- package/src/use-state.ts +30 -0
- package/src/use-timestamp.ts +12 -0
- package/src/use.spec.ts +46 -0
- package/src/use.ts +33 -0
- package/dist/adapter/adapter-aggregate.d.ts +0 -57
- package/dist/adapter/adapter-aggregate.d.ts.map +0 -1
- package/dist/adapter/adapter-aggregate.js +0 -158
- package/dist/adapter/adapter.d.ts +0 -53
- package/dist/adapter/adapter.d.ts.map +0 -1
- package/dist/adapter/adapter.js +0 -20
- package/dist/adapter/backtester/backtester-adapter.d.ts +0 -26
- package/dist/adapter/backtester/backtester-adapter.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-adapter.js +0 -67
- package/dist/adapter/backtester/backtester-cursor.d.ts +0 -16
- package/dist/adapter/backtester/backtester-cursor.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-cursor.js +0 -52
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts +0 -2
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-cursor.spec.js +0 -47
- package/dist/adapter/backtester/backtester-streamer.d.ts +0 -50
- package/dist/adapter/backtester/backtester-streamer.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-streamer.js +0 -118
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts +0 -2
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts.map +0 -1
- package/dist/adapter/backtester/backtester-streamer.spec.js +0 -45
- package/dist/adapter/backtester/error.d.ts +0 -7
- package/dist/adapter/backtester/error.d.ts.map +0 -1
- package/dist/adapter/backtester/error.js +0 -15
- package/dist/adapter/backtester/index.d.ts +0 -5
- package/dist/adapter/backtester/index.d.ts.map +0 -1
- package/dist/adapter/error.d.ts +0 -10
- package/dist/adapter/error.d.ts.map +0 -1
- package/dist/adapter/error.js +0 -21
- package/dist/adapter/index.d.ts +0 -6
- package/dist/adapter/index.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.d.ts +0 -12
- package/dist/adapter/paper/engine/paper-engine.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.js +0 -108
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts +0 -2
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts.map +0 -1
- package/dist/adapter/paper/engine/paper-engine.spec.js +0 -63
- package/dist/adapter/paper/index.d.ts +0 -3
- package/dist/adapter/paper/index.d.ts.map +0 -1
- package/dist/adapter/paper/paper-adapter.d.ts +0 -28
- package/dist/adapter/paper/paper-adapter.d.ts.map +0 -1
- package/dist/adapter/paper/paper-adapter.js +0 -88
- package/dist/cli/test.d.ts.map +0 -1
- package/dist/domain/asset.d.ts.map +0 -1
- package/dist/domain/balance-operator.d.ts +0 -5
- package/dist/domain/balance-operator.d.ts.map +0 -1
- package/dist/domain/balance-operator.js +0 -9
- package/dist/domain/balance-operator.spec.d.ts +0 -2
- package/dist/domain/balance-operator.spec.d.ts.map +0 -1
- package/dist/domain/balance-operator.spec.js +0 -21
- package/dist/domain/balance.d.ts +0 -46
- package/dist/domain/balance.d.ts.map +0 -1
- package/dist/domain/balance.js +0 -79
- package/dist/domain/balance.spec.d.ts +0 -2
- package/dist/domain/balance.spec.d.ts.map +0 -1
- package/dist/domain/balance.spec.js +0 -32
- package/dist/domain/commission.d.ts.map +0 -1
- package/dist/domain/commission.spec.d.ts.map +0 -1
- package/dist/domain/component.d.ts +0 -6
- package/dist/domain/component.d.ts.map +0 -1
- package/dist/domain/error.d.ts.map +0 -1
- package/dist/domain/index.d.ts +0 -22
- package/dist/domain/index.d.ts.map +0 -1
- package/dist/domain/index.js +0 -37
- package/dist/domain/instrument-operator.d.ts +0 -6
- package/dist/domain/instrument-operator.d.ts.map +0 -1
- package/dist/domain/instrument-operator.js +0 -13
- package/dist/domain/instrument-operator.spec.d.ts +0 -2
- package/dist/domain/instrument-operator.spec.d.ts.map +0 -1
- package/dist/domain/instrument-operator.spec.js +0 -21
- package/dist/domain/instrument.d.ts.map +0 -1
- package/dist/domain/instrument.spec.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.spec.d.ts.map +0 -1
- package/dist/domain/ohlc-operator.spec.js +0 -110
- package/dist/domain/ohlc.d.ts.map +0 -1
- package/dist/domain/order-operator.d.ts +0 -6
- package/dist/domain/order-operator.d.ts.map +0 -1
- package/dist/domain/order-operator.js +0 -16
- package/dist/domain/order-operator.spec.d.ts +0 -2
- package/dist/domain/order-operator.spec.d.ts.map +0 -1
- package/dist/domain/order-operator.spec.js +0 -61
- package/dist/domain/order.d.ts +0 -21
- package/dist/domain/order.d.ts.map +0 -1
- package/dist/domain/order.js +0 -41
- package/dist/domain/order.spec.d.ts +0 -2
- package/dist/domain/order.spec.d.ts.map +0 -1
- package/dist/domain/order.spec.js +0 -27
- package/dist/domain/orderbook-operator.d.ts +0 -5
- package/dist/domain/orderbook-operator.d.ts.map +0 -1
- package/dist/domain/orderbook-operator.js +0 -9
- package/dist/domain/orderbook-operator.spec.d.ts +0 -2
- package/dist/domain/orderbook-operator.spec.d.ts.map +0 -1
- package/dist/domain/orderbook-operator.spec.js +0 -19
- package/dist/domain/orderbook.d.ts +0 -31
- package/dist/domain/orderbook.d.ts.map +0 -1
- package/dist/domain/orderbook.js +0 -23
- package/dist/domain/orderbook.spec.d.ts +0 -2
- package/dist/domain/orderbook.spec.d.ts.map +0 -1
- package/dist/domain/orderbook.spec.js +0 -11
- package/dist/domain/position-operator.d.ts +0 -11
- package/dist/domain/position-operator.d.ts.map +0 -1
- package/dist/domain/position-operator.js +0 -44
- package/dist/domain/position-operator.spec.d.ts +0 -2
- package/dist/domain/position-operator.spec.d.ts.map +0 -1
- package/dist/domain/position-operator.spec.js +0 -44
- package/dist/domain/position.d.ts +0 -19
- package/dist/domain/position.d.ts.map +0 -1
- package/dist/domain/position.js +0 -25
- package/dist/domain/position.spec.d.ts +0 -2
- package/dist/domain/position.spec.d.ts.map +0 -1
- package/dist/domain/position.spec.js +0 -28
- package/dist/domain/session-builder.d.ts +0 -58
- package/dist/domain/session-builder.d.ts.map +0 -1
- package/dist/domain/session-builder.js +0 -101
- package/dist/domain/session.d.ts +0 -77
- package/dist/domain/session.d.ts.map +0 -1
- package/dist/domain/session.js +0 -156
- package/dist/domain/session.spec.d.ts +0 -2
- package/dist/domain/session.spec.d.ts.map +0 -1
- package/dist/domain/session.spec.js +0 -17
- package/dist/domain/timeframe.d.ts.map +0 -1
- package/dist/domain/trade-operator.d.ts +0 -5
- package/dist/domain/trade-operator.d.ts.map +0 -1
- package/dist/domain/trade-operator.js +0 -9
- package/dist/domain/trade-operator.spec.d.ts +0 -2
- package/dist/domain/trade-operator.spec.d.ts.map +0 -1
- package/dist/domain/trade-operator.spec.js +0 -21
- package/dist/domain/trade.d.ts +0 -17
- package/dist/domain/trade.d.ts.map +0 -1
- package/dist/domain/trade.js +0 -20
- package/dist/domain/trade.spec.d.ts +0 -2
- package/dist/domain/trade.spec.d.ts.map +0 -1
- package/dist/domain/trade.spec.js +0 -11
- package/dist/shared/collections.d.ts +0 -29
- package/dist/shared/collections.d.ts.map +0 -1
- package/dist/shared/collections.js +0 -123
- package/dist/shared/collections.spec.d.ts +0 -2
- package/dist/shared/collections.spec.d.ts.map +0 -1
- package/dist/shared/collections.spec.js +0 -29
- package/dist/shared/hash.d.ts +0 -2
- package/dist/shared/hash.d.ts.map +0 -1
- package/dist/shared/hash.js +0 -12
- package/dist/shared/logger.d.ts.map +0 -1
- package/dist/shared/logger.js +0 -40
- package/dist/shared/policy.d.ts +0 -2
- package/dist/shared/policy.d.ts.map +0 -1
- package/dist/shared/policy.js +0 -8
- package/dist/storage/cache.d.ts +0 -10
- package/dist/storage/cache.d.ts.map +0 -1
- package/dist/storage/cache.js +0 -43
- package/dist/storage/cache.spec.d.ts +0 -2
- package/dist/storage/cache.spec.d.ts.map +0 -1
- package/dist/storage/cache.spec.js +0 -25
- package/dist/storage/feed.d.ts +0 -38
- package/dist/storage/feed.d.ts.map +0 -1
- package/dist/storage/feed.js +0 -108
- package/dist/storage/measurement.d.ts +0 -34
- package/dist/storage/measurement.d.ts.map +0 -1
- package/dist/storage/measurement.js +0 -59
- package/dist/store/error.d.ts +0 -23
- package/dist/store/error.d.ts.map +0 -1
- package/dist/store/error.js +0 -45
- package/dist/store/index.d.ts +0 -11
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/store-balance-event.d.ts +0 -26
- package/dist/store/store-balance-event.d.ts.map +0 -1
- package/dist/store/store-balance-event.js +0 -59
- package/dist/store/store-balance-event.spec.d.ts +0 -2
- package/dist/store/store-balance-event.spec.d.ts.map +0 -1
- package/dist/store/store-balance-event.spec.js +0 -24
- package/dist/store/store-event.d.ts +0 -7
- package/dist/store/store-event.d.ts.map +0 -1
- package/dist/store/store-event.js +0 -2
- package/dist/store/store-instrument-event.d.ts +0 -21
- package/dist/store/store-instrument-event.d.ts.map +0 -1
- package/dist/store/store-instrument-event.js +0 -59
- package/dist/store/store-instrument-event.spec.d.ts +0 -2
- package/dist/store/store-instrument-event.spec.d.ts.map +0 -1
- package/dist/store/store-instrument-event.spec.js +0 -22
- package/dist/store/store-order-event.d.ts +0 -63
- package/dist/store/store-order-event.d.ts.map +0 -1
- package/dist/store/store-order-event.js +0 -223
- package/dist/store/store-order-event.spec.d.ts +0 -2
- package/dist/store/store-order-event.spec.d.ts.map +0 -1
- package/dist/store/store-order-event.spec.js +0 -23
- package/dist/store/store-orderbook-event.d.ts +0 -12
- package/dist/store/store-orderbook-event.d.ts.map +0 -1
- package/dist/store/store-orderbook-event.js +0 -43
- package/dist/store/store-orderbook-event.spec.d.ts +0 -2
- package/dist/store/store-orderbook-event.spec.d.ts.map +0 -1
- package/dist/store/store-orderbook-event.spec.js +0 -27
- package/dist/store/store-position-event.d.ts +0 -21
- package/dist/store/store-position-event.d.ts.map +0 -1
- package/dist/store/store-position-event.js +0 -96
- package/dist/store/store-state.d.ts +0 -28
- package/dist/store/store-state.d.ts.map +0 -1
- package/dist/store/store-state.js +0 -29
- package/dist/store/store-trade-event.d.ts +0 -16
- package/dist/store/store-trade-event.d.ts.map +0 -1
- package/dist/store/store-trade-event.js +0 -34
- package/dist/store/store-trade-event.spec.d.ts +0 -2
- package/dist/store/store-trade-event.spec.d.ts.map +0 -1
- package/dist/store/store-trade-event.spec.js +0 -44
- package/dist/store/store.d.ts +0 -14
- package/dist/store/store.d.ts.map +0 -1
- package/dist/store/store.js +0 -35
- package/dist/store/store.spec.d.ts +0 -2
- package/dist/store/store.spec.d.ts.map +0 -1
- package/dist/store/store.spec.js +0 -122
- package/src/adapter/adapter-aggregate.ts +0 -185
- package/src/adapter/adapter.ts +0 -82
- package/src/adapter/backtester/backtester-adapter.ts +0 -100
- package/src/adapter/backtester/backtester-cursor.spec.ts +0 -44
- package/src/adapter/backtester/backtester-cursor.ts +0 -47
- package/src/adapter/backtester/backtester-streamer.spec.ts +0 -60
- package/src/adapter/backtester/backtester-streamer.ts +0 -158
- package/src/adapter/backtester/error.ts +0 -11
- package/src/adapter/backtester/index.ts +0 -4
- package/src/adapter/error.ts +0 -19
- package/src/adapter/index.ts +0 -5
- package/src/adapter/paper/engine/paper-engine.spec.ts +0 -110
- package/src/adapter/paper/engine/paper-engine.ts +0 -136
- package/src/adapter/paper/index.ts +0 -2
- package/src/adapter/paper/paper-adapter.ts +0 -118
- package/src/cli/test.ts +0 -41
- package/src/domain/balance-operator.spec.ts +0 -23
- package/src/domain/balance-operator.ts +0 -14
- package/src/domain/balance.spec.ts +0 -46
- package/src/domain/balance.ts +0 -110
- package/src/domain/component.ts +0 -6
- package/src/domain/index.ts +0 -21
- package/src/domain/instrument-operator.spec.ts +0 -38
- package/src/domain/instrument-operator.ts +0 -25
- package/src/domain/order-operator.spec.ts +0 -89
- package/src/domain/order-operator.ts +0 -24
- package/src/domain/order.spec.ts +0 -40
- package/src/domain/order.ts +0 -65
- package/src/domain/orderbook-operator.spec.ts +0 -42
- package/src/domain/orderbook-operator.ts +0 -14
- package/src/domain/orderbook.spec.ts +0 -23
- package/src/domain/orderbook.ts +0 -32
- package/src/domain/position-operator.spec.ts +0 -67
- package/src/domain/position-operator.ts +0 -74
- package/src/domain/position.spec.ts +0 -40
- package/src/domain/position.ts +0 -33
- package/src/domain/session-builder.ts +0 -158
- package/src/domain/session.spec.ts +0 -33
- package/src/domain/session.ts +0 -261
- package/src/domain/trade-operator.spec.ts +0 -30
- package/src/domain/trade-operator.ts +0 -14
- package/src/domain/trade.spec.ts +0 -18
- package/src/domain/trade.ts +0 -22
- package/src/shared/collections.spec.ts +0 -34
- package/src/shared/collections.ts +0 -154
- package/src/shared/hash.ts +0 -10
- package/src/shared/logger.ts +0 -46
- package/src/shared/policy.ts +0 -5
- package/src/storage/cache.spec.ts +0 -17
- package/src/storage/cache.ts +0 -37
- package/src/storage/feed.ts +0 -124
- package/src/storage/measurement.ts +0 -56
- package/src/store/error.ts +0 -47
- package/src/store/index.ts +0 -10
- package/src/store/store-balance-event.spec.ts +0 -28
- package/src/store/store-balance-event.ts +0 -72
- package/src/store/store-event.ts +0 -8
- package/src/store/store-instrument-event.spec.ts +0 -25
- package/src/store/store-instrument-event.ts +0 -87
- package/src/store/store-order-event.spec.ts +0 -33
- package/src/store/store-order-event.ts +0 -288
- package/src/store/store-orderbook-event.spec.ts +0 -38
- package/src/store/store-orderbook-event.ts +0 -60
- package/src/store/store-position-event.ts +0 -125
- package/src/store/store-state.ts +0 -48
- package/src/store/store-trade-event.spec.ts +0 -61
- package/src/store/store-trade-event.ts +0 -46
- package/src/store/store.spec.ts +0 -196
- package/src/store/store.ts +0 -40
- package/dist/{domain → asset}/asset.spec.d.ts +0 -0
- package/dist/{domain → component}/error.js +0 -0
- package/dist/{domain → component}/ohlc-operator.spec.d.ts +0 -0
- package/dist/{domain → component}/ohlc.d.ts +0 -0
- package/dist/{domain → component}/ohlc.js +0 -0
- package/dist/{domain → component}/ohlc.spec.d.ts +0 -0
- package/dist/{domain → component}/timeframe.d.ts +0 -0
- package/dist/{domain → component}/timeframe.js +1 -1
- /package/dist/{domain → instrument/commission}/commission.spec.d.ts +0 -0
- /package/dist/{domain → instrument}/instrument.spec.d.ts +0 -0
- /package/src/{domain → component}/ohlc.ts +0 -0
- /package/src/{domain → component}/timeframe.ts +0 -0
- /package/src/{domain → instrument/commission}/commission.ts +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Observable, tap } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
import { core } from '@lib/core';
|
|
4
|
+
import { Dependency, Module } from '@lib/module';
|
|
5
|
+
|
|
6
|
+
export async function makeTestModule(dependencies: Dependency[]) {
|
|
7
|
+
const module = new Module([...core(), ...dependencies]);
|
|
8
|
+
|
|
9
|
+
const { act } = await module.awake();
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
act,
|
|
13
|
+
get: module.get.bind(module)
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
type MockableFunction = (...args: any[]) => any;
|
|
18
|
+
|
|
19
|
+
export const mockedFunc = <Func extends MockableFunction>(mockedFunc: Func) =>
|
|
20
|
+
mockedFunc as jest.MockedFunction<typeof mockedFunc>;
|
|
21
|
+
|
|
22
|
+
export function toArray<T>(observable: Observable<T>) {
|
|
23
|
+
const array = Array.of<T>();
|
|
24
|
+
|
|
25
|
+
const clone = (it: T): T => {
|
|
26
|
+
if (typeof it === 'symbol') {
|
|
27
|
+
return it;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(it)) {
|
|
31
|
+
return it.map(it => clone(it)) as T;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof it === 'object') {
|
|
35
|
+
return { ...it };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return it;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
observable.pipe(tap(it => array.push(clone(it)))).subscribe();
|
|
42
|
+
|
|
43
|
+
return array;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type InferObservableType<T> = T extends Observable<infer U> ? U : never;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Dependency, Module, provider } from '@lib/module';
|
|
2
|
+
|
|
3
|
+
describe(Module.name, () => {
|
|
4
|
+
let fixtures: ReturnType<typeof getFixtures>;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
fixtures = getFixtures();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('builds empty module', async () => {
|
|
11
|
+
const module = fixtures.givenModuleCreated([]);
|
|
12
|
+
fixtures.whenModuleBuilt(module);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('builds module and resolves single value dependency', async () => {
|
|
16
|
+
const definition = fixtures.definitions.singleValue;
|
|
17
|
+
const module = fixtures.givenModuleCreated(definition);
|
|
18
|
+
fixtures.whenModuleBuilt(module);
|
|
19
|
+
fixtures.thenCanResolveDependencies(module, definition);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('builds module and resolves single class dependency', async () => {
|
|
23
|
+
const definition = fixtures.definitions.singleClass;
|
|
24
|
+
const module = fixtures.givenModuleCreated(definition);
|
|
25
|
+
fixtures.whenModuleBuilt(module);
|
|
26
|
+
fixtures.thenCanResolveDependencies(module, definition);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('builds module and resolves many class dependencies', async () => {
|
|
30
|
+
const definition = fixtures.definitions.manyClass;
|
|
31
|
+
const module = fixtures.givenModuleCreated(definition);
|
|
32
|
+
fixtures.whenModuleBuilt(module);
|
|
33
|
+
fixtures.thenCanResolveDependencies(module, definition);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function getFixtures() {
|
|
38
|
+
return {
|
|
39
|
+
definitions: {
|
|
40
|
+
singleClass: [
|
|
41
|
+
{
|
|
42
|
+
provide: FakeService,
|
|
43
|
+
useClass: FakeService
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
manyClass: [
|
|
47
|
+
{
|
|
48
|
+
provide: FakeService,
|
|
49
|
+
useClass: FakeService
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
provide: FakeService,
|
|
53
|
+
useClass: FakeService
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
singleValue: [
|
|
57
|
+
{
|
|
58
|
+
provide: FakeService,
|
|
59
|
+
useValue: new FakeService()
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
givenModuleCreated: (dependencies: Dependency[]) => new Module(dependencies),
|
|
64
|
+
whenModuleBuilt: (module: Module) => module.awake(),
|
|
65
|
+
thenCanResolveDependencies: (module: Module, dependencies: Dependency[]) => {
|
|
66
|
+
dependencies.forEach(it => {
|
|
67
|
+
expect(module.get<FakeService>(it.provide)).toBeTruthy();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@provider()
|
|
74
|
+
class FakeService {}
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
|
|
3
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
+
import {
|
|
5
|
+
container,
|
|
6
|
+
DependencyContainer,
|
|
7
|
+
inject,
|
|
8
|
+
injectable,
|
|
9
|
+
injectAll,
|
|
10
|
+
InjectionToken,
|
|
11
|
+
Lifecycle
|
|
12
|
+
} from 'tsyringe';
|
|
13
|
+
|
|
14
|
+
export const provider = injectable;
|
|
15
|
+
export const provide = inject;
|
|
16
|
+
export const provideAll = injectAll;
|
|
17
|
+
|
|
18
|
+
export type Dependency = {
|
|
19
|
+
provide: InjectionToken;
|
|
20
|
+
useClass?: any;
|
|
21
|
+
useValue?: any;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function noModuleError() {
|
|
25
|
+
return new Error('Please do not use dependency injection outside of hooks context.');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function withModuleError() {
|
|
29
|
+
return new Error('Please do not use with hooks in context.');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function notInitializedModuleError() {
|
|
33
|
+
return new Error('You need to initialize a module before use.');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function missingInjectionTokenError(token: InjectionToken) {
|
|
37
|
+
return new Error(`Unable to resolve unregistered dependency: ${token.toString()}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
const moduleLocalStorage = new AsyncLocalStorage();
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Hook to get access to current execution module dependencies.
|
|
47
|
+
*/
|
|
48
|
+
export const useContext = <T>(token: InjectionToken<T>) => {
|
|
49
|
+
const module = moduleLocalStorage.getStore() as Module | undefined;
|
|
50
|
+
|
|
51
|
+
if (!module) {
|
|
52
|
+
throw noModuleError();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return module.get<T>(token);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Hook to get access to current execution module dependencies.
|
|
60
|
+
*/
|
|
61
|
+
export const throwWithContext = () => {
|
|
62
|
+
if (moduleLocalStorage.getStore()) {
|
|
63
|
+
throw withModuleError();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A module is a collection of services, values, and factories that can be
|
|
69
|
+
* registered with a dependency container.
|
|
70
|
+
*/
|
|
71
|
+
export class Module {
|
|
72
|
+
private container?: DependencyContainer;
|
|
73
|
+
|
|
74
|
+
constructor(private readonly dependencies: Dependency[]) {}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Builds and initializes dependencies.
|
|
78
|
+
*/
|
|
79
|
+
async awake(): Promise<{ act: <T>(func: () => T) => T }> {
|
|
80
|
+
this.container = this.buildContainer();
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
/**
|
|
84
|
+
* Associate callback function with current executing module
|
|
85
|
+
*/
|
|
86
|
+
act: <T>(func: () => T) => moduleLocalStorage.run(this, func)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Disposes all dependencies instantiated by this module.
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
94
|
+
dispose() {
|
|
95
|
+
if (!this.container) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.container = undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Builds a new instance of dependency container based on module definition.
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
protected buildContainer(): DependencyContainer {
|
|
107
|
+
const childContainer = container.createChildContainer();
|
|
108
|
+
|
|
109
|
+
this.dependencies.forEach(it => {
|
|
110
|
+
if (it.useValue) {
|
|
111
|
+
childContainer.register(it.provide, { useValue: it.useValue });
|
|
112
|
+
} else {
|
|
113
|
+
childContainer.register(it.provide, it.useClass ?? it.provide, {
|
|
114
|
+
lifecycle: Lifecycle.Singleton
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return childContainer;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolves a dependency from the module.
|
|
124
|
+
* @param token represents the identifier for the dependency that you want to
|
|
125
|
+
* resolve from the container.
|
|
126
|
+
* @returns instance of the dependency.
|
|
127
|
+
*/
|
|
128
|
+
get<T>(token: InjectionToken<T>): T {
|
|
129
|
+
if (!this.container) {
|
|
130
|
+
throw notInitializedModuleError();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!this.container.isRegistered(token)) {
|
|
134
|
+
throw missingInjectionTokenError(token);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return this.container.resolve<T>(token);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Resolves a collection of dependencies from the module.
|
|
142
|
+
* @param token
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
145
|
+
getAll<T>(token: InjectionToken<T>): T[] {
|
|
146
|
+
if (!this.container) {
|
|
147
|
+
throw notInitializedModuleError();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!this.container.isRegistered(token)) {
|
|
151
|
+
throw missingInjectionTokenError(token);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return container.resolveAll<T>(token);
|
|
155
|
+
}
|
|
156
|
+
}
|
package/src/not-found.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const notFound = Symbol.for('not-found');
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { defer, filter, map, Subject } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
import { dependency } from '@lib/use-hash';
|
|
4
|
+
import { useMemo } from '@lib/use-memo';
|
|
5
|
+
|
|
6
|
+
import { between } from '..';
|
|
7
|
+
import { useReplayOptions } from './use-replay-options';
|
|
8
|
+
import { useReplayReader } from './use-replay-reader';
|
|
9
|
+
|
|
10
|
+
export function useReplayCoordinator() {
|
|
11
|
+
const options = useReplayOptions();
|
|
12
|
+
|
|
13
|
+
return useMemo(() => {
|
|
14
|
+
let timestamp = options.from;
|
|
15
|
+
let stopAcquire = 1;
|
|
16
|
+
let sequence = 0;
|
|
17
|
+
const subscriptions = Array.of<SampleCursor>();
|
|
18
|
+
const stream$ = new Subject<[SampleCursor, { timestamp: number }]>();
|
|
19
|
+
|
|
20
|
+
const subscribe = (dependencies: dependency[]) => {
|
|
21
|
+
const cursor = useSampleCursor(dependencies);
|
|
22
|
+
|
|
23
|
+
if (!subscriptions.includes(cursor)) {
|
|
24
|
+
subscriptions.push(cursor);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return defer(() => {
|
|
28
|
+
tryContinue();
|
|
29
|
+
|
|
30
|
+
return stream$.pipe(
|
|
31
|
+
filter(([cur]) => cur === cursor),
|
|
32
|
+
map(([, it]) => it)
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const current = async () => {
|
|
38
|
+
let next: SampleCursor | undefined;
|
|
39
|
+
|
|
40
|
+
for (const cursor of subscriptions) {
|
|
41
|
+
if (cursor.size() == 0 && !cursor.completed) {
|
|
42
|
+
await cursor.fetchNextPage(timestamp, options.to + 1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (cursor.peek()) {
|
|
46
|
+
if (!next || next.peek().timestamp > cursor.peek().timestamp) {
|
|
47
|
+
next = cursor;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return next;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const processNext = async () => {
|
|
56
|
+
const cursor = await current();
|
|
57
|
+
|
|
58
|
+
if (!cursor || !cursor.peek()) {
|
|
59
|
+
stream$.complete();
|
|
60
|
+
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const sample = cursor.dequeue();
|
|
65
|
+
|
|
66
|
+
timestamp = sample.timestamp;
|
|
67
|
+
sequence++;
|
|
68
|
+
|
|
69
|
+
stream$.next([cursor, sample]);
|
|
70
|
+
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const next = async () => {
|
|
75
|
+
if (await processNext()) {
|
|
76
|
+
if (stopAcquire === 0) {
|
|
77
|
+
setImmediate(next);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const stop = () => stopAcquire++;
|
|
83
|
+
const tryContinue = () => {
|
|
84
|
+
if (stopAcquire == 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
stopAcquire = Math.max(0, stopAcquire - 1);
|
|
89
|
+
|
|
90
|
+
if (stopAcquire != 0) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
next();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
timestamp: () => timestamp,
|
|
99
|
+
stop,
|
|
100
|
+
tryContinue,
|
|
101
|
+
subscribe
|
|
102
|
+
};
|
|
103
|
+
}, [useReplayCoordinator.name]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type SampleCursor = Awaited<ReturnType<typeof useSampleCursor>>;
|
|
107
|
+
|
|
108
|
+
function useSampleCursor<T>(dependencies: dependency[]) {
|
|
109
|
+
return useMemo(() => {
|
|
110
|
+
const read = useReplayReader<T>(dependencies);
|
|
111
|
+
let page = new Array<{ timestamp: number; payload: T }>();
|
|
112
|
+
let index = 0;
|
|
113
|
+
let completed = false;
|
|
114
|
+
|
|
115
|
+
const size = () => page.length - index;
|
|
116
|
+
const peek = () => page[index];
|
|
117
|
+
const dequeue = () => page[index++];
|
|
118
|
+
const fetchNextPage = async (from: number, to: number) => {
|
|
119
|
+
if (completed) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
index = 0;
|
|
124
|
+
|
|
125
|
+
page = await read({
|
|
126
|
+
where: {
|
|
127
|
+
timestamp: between(from, to)
|
|
128
|
+
},
|
|
129
|
+
limit: 10000
|
|
130
|
+
});
|
|
131
|
+
completed = page.length == 0;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
size,
|
|
136
|
+
peek,
|
|
137
|
+
dequeue,
|
|
138
|
+
fetchNextPage,
|
|
139
|
+
completed
|
|
140
|
+
};
|
|
141
|
+
}, [useSampleCursor.name, ...dependencies]);
|
|
142
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Dependency, useContext } from '@lib/module';
|
|
2
|
+
|
|
3
|
+
const injectionToken = Symbol('replay-options');
|
|
4
|
+
|
|
5
|
+
type ReplayOptions = {
|
|
6
|
+
from: number;
|
|
7
|
+
to: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export function replayOptions(options: ReplayOptions): Dependency {
|
|
14
|
+
return {
|
|
15
|
+
provide: injectionToken,
|
|
16
|
+
useValue: options
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Will return current replay execution options.
|
|
22
|
+
*/
|
|
23
|
+
export const useReplayOptions = () => useContext<ReplayOptions>(injectionToken);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { makeTestModule, mockedFunc } from '@lib/make-test-module';
|
|
2
|
+
import { gt, Storage } from '@lib/storage';
|
|
3
|
+
|
|
4
|
+
import { useReplayReader } from './use-replay-reader';
|
|
5
|
+
import { useReplayStorage } from './use-replay-storage';
|
|
6
|
+
|
|
7
|
+
jest.mock('./use-replay-storage', () => ({
|
|
8
|
+
...jest.requireActual('./use-replay-storage'),
|
|
9
|
+
useReplayStorage: jest.fn()
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe(useReplayReader.name, () => {
|
|
13
|
+
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
fixtures = await getFixtures();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('read sample candle data from storage', async () => {
|
|
20
|
+
await fixtures.givenDataStored(fixtures.sample);
|
|
21
|
+
const data = await fixtures.whenDataRequested();
|
|
22
|
+
|
|
23
|
+
expect(data).toEqual(fixtures.sample);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
async function getFixtures() {
|
|
28
|
+
const { act } = await makeTestModule([]);
|
|
29
|
+
|
|
30
|
+
const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
|
|
31
|
+
const query: jest.MockedFunction<Storage['query']> = jest.fn();
|
|
32
|
+
|
|
33
|
+
mockedFunc(useReplayStorage).mockReturnValue({ query } as any);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
sample: [
|
|
37
|
+
{ timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
|
|
38
|
+
{ timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
|
|
39
|
+
{ timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
givenDataStored<T>(data: { timestamp: number; payload: T }[]) {
|
|
43
|
+
return query.mockReturnValue(
|
|
44
|
+
Promise.resolve(
|
|
45
|
+
data.map(it => ({
|
|
46
|
+
kind: 'sample',
|
|
47
|
+
timestamp: it.timestamp,
|
|
48
|
+
json: JSON.stringify(it.payload)
|
|
49
|
+
}))
|
|
50
|
+
)
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
async whenDataRequested<T>() {
|
|
55
|
+
return await act(() =>
|
|
56
|
+
useReplayReader<T>(dependencies)({
|
|
57
|
+
where: {
|
|
58
|
+
timestamp: gt(0)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Query, QueryObject } from '@lib/storage';
|
|
2
|
+
import { dependency, useHash } from '@lib/use-hash';
|
|
3
|
+
|
|
4
|
+
import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
|
|
5
|
+
|
|
6
|
+
export function useReplayReader<T>(dependencies: dependency[]) {
|
|
7
|
+
const storage = useReplayStorage();
|
|
8
|
+
const key = useHash(dependencies);
|
|
9
|
+
|
|
10
|
+
return async (query: Query<QueryObject>) =>
|
|
11
|
+
(
|
|
12
|
+
await storage.query(replaySerializableObject(key), {
|
|
13
|
+
where: {
|
|
14
|
+
timestamp: query.where?.timestamp
|
|
15
|
+
},
|
|
16
|
+
limit: query.limit,
|
|
17
|
+
orderBy: query.orderBy
|
|
18
|
+
})
|
|
19
|
+
).map(it => ({
|
|
20
|
+
timestamp: it.timestamp,
|
|
21
|
+
payload: JSON.parse(it.json) as T
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { makeTestModule, mockedFunc } from '@lib/make-test-module';
|
|
2
|
+
import { Storage } from '@lib/storage';
|
|
3
|
+
import { useHash } from '@lib/use-hash';
|
|
4
|
+
|
|
5
|
+
import { useReplayStorage } from './use-replay-storage';
|
|
6
|
+
import { useReplayWriter } from './use-replay-writer';
|
|
7
|
+
|
|
8
|
+
jest.mock('./use-replay-storage', () => ({
|
|
9
|
+
...jest.requireActual('./use-replay-storage'),
|
|
10
|
+
useReplayStorage: jest.fn()
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe.skip(useReplayWriter.name, () => {
|
|
14
|
+
let fixtures: Awaited<ReturnType<typeof getFixtures>>;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
fixtures = await getFixtures();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('write sample candle data to storage', async () => {
|
|
21
|
+
await fixtures.whenReplayDataWritten(fixtures.sample);
|
|
22
|
+
await fixtures.thenReplayDataSaved(fixtures.sample);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
async function getFixtures() {
|
|
27
|
+
const { act } = await makeTestModule([]);
|
|
28
|
+
|
|
29
|
+
const dependencies = ['binance:btc-usdt', 'candle', 'h1'];
|
|
30
|
+
const save: Storage['save'] = jest.fn();
|
|
31
|
+
|
|
32
|
+
mockedFunc(useReplayStorage).mockReturnValue({ save } as any);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
sample: [
|
|
36
|
+
{ timestamp: 1, payload: { o: 1.1, h: 1.1, l: 1.1, c: 1.1 } },
|
|
37
|
+
{ timestamp: 2, payload: { o: 1.1, h: 2.2, l: 1.1, c: 2.2 } },
|
|
38
|
+
{ timestamp: 3, payload: { o: 1.1, h: 3.3, l: 1.1, c: 3.3 } }
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
whenReplayDataWritten<T>(data: { timestamp: number; payload: T }[]) {
|
|
42
|
+
return act(() => useReplayWriter(dependencies)(data));
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
async thenReplayDataSaved<T>(data: { timestamp: number; payload: T }[]) {
|
|
46
|
+
expect(save).toHaveBeenCalledWith(
|
|
47
|
+
useHash(dependencies),
|
|
48
|
+
data.map(it => ({
|
|
49
|
+
kind: 'sample',
|
|
50
|
+
timestamp: it.timestamp,
|
|
51
|
+
json: JSON.stringify(it.payload)
|
|
52
|
+
}))
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { dependency, useHash } from '@lib/use-hash';
|
|
2
|
+
|
|
3
|
+
import { replaySerializableObject, useReplayStorage } from './use-replay-storage';
|
|
4
|
+
|
|
5
|
+
export function useReplayWriter<T>(dependencies: dependency[]) {
|
|
6
|
+
const storage = useReplayStorage();
|
|
7
|
+
const key = useHash(dependencies);
|
|
8
|
+
|
|
9
|
+
return (samples: { timestamp: number; payload: T }[]) =>
|
|
10
|
+
storage.save(
|
|
11
|
+
replaySerializableObject(key),
|
|
12
|
+
samples.map(it => ({
|
|
13
|
+
timestamp: it.timestamp,
|
|
14
|
+
json: JSON.stringify(it.payload)
|
|
15
|
+
}))
|
|
16
|
+
);
|
|
17
|
+
}
|