@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
package/src/domain/session.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
concat,
|
|
3
|
-
defer,
|
|
4
|
-
filter,
|
|
5
|
-
from,
|
|
6
|
-
map,
|
|
7
|
-
mergeMap,
|
|
8
|
-
Observable,
|
|
9
|
-
of,
|
|
10
|
-
ReplaySubject,
|
|
11
|
-
share,
|
|
12
|
-
shareReplay,
|
|
13
|
-
startWith,
|
|
14
|
-
switchMap,
|
|
15
|
-
take
|
|
16
|
-
} from 'rxjs';
|
|
17
|
-
import { v4 } from 'uuid';
|
|
18
|
-
|
|
19
|
-
import { AdapterAggregate } from '@lib/adapter';
|
|
20
|
-
import {
|
|
21
|
-
AssetSelector,
|
|
22
|
-
Balance,
|
|
23
|
-
balance,
|
|
24
|
-
Instrument,
|
|
25
|
-
instrument,
|
|
26
|
-
instruments,
|
|
27
|
-
InstrumentSelector,
|
|
28
|
-
InvalidInstrumentSelectorError,
|
|
29
|
-
Ohlc,
|
|
30
|
-
Order,
|
|
31
|
-
order,
|
|
32
|
-
Orderbook,
|
|
33
|
-
orderbook,
|
|
34
|
-
orders,
|
|
35
|
-
Position,
|
|
36
|
-
position,
|
|
37
|
-
positions,
|
|
38
|
-
Trade,
|
|
39
|
-
trade
|
|
40
|
-
} from '@lib/domain';
|
|
41
|
-
import { decimal } from '@lib/shared';
|
|
42
|
-
import { Measurement } from '@lib/storage';
|
|
43
|
-
import { Store } from '@lib/store';
|
|
44
|
-
|
|
45
|
-
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
46
|
-
|
|
47
|
-
export class Session {
|
|
48
|
-
private initialized = false;
|
|
49
|
-
|
|
50
|
-
get timestamp(): number {
|
|
51
|
-
return this.store.snapshot.timestamp;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
constructor(
|
|
55
|
-
readonly id: number,
|
|
56
|
-
readonly store: Store,
|
|
57
|
-
readonly aggregate: AdapterAggregate,
|
|
58
|
-
readonly measurement: Measurement | undefined
|
|
59
|
-
) {}
|
|
60
|
-
|
|
61
|
-
async awake(): Promise<void> {
|
|
62
|
-
if (this.initialized) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.initialized = true;
|
|
67
|
-
|
|
68
|
-
// awake all adapters and synchronize trading accounts with store.
|
|
69
|
-
await this.aggregate.awake();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async dispose(): Promise<void> {
|
|
73
|
-
if (!this.initialized) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.store.dispose();
|
|
78
|
-
|
|
79
|
-
await this.aggregate.dispose();
|
|
80
|
-
|
|
81
|
-
this.initialized = false;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Subscribes to specific instrument. Usually forces adapter to subscribe
|
|
86
|
-
* for orderbook and ticker streams.
|
|
87
|
-
*/
|
|
88
|
-
subscribe(instrument: Array<InstrumentSelector>): Promise<void> {
|
|
89
|
-
return this.aggregate.subscribe(instrument);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Opens a new order.
|
|
94
|
-
*/
|
|
95
|
-
open(order: {
|
|
96
|
-
instrument: InstrumentSelector;
|
|
97
|
-
quantity: decimal;
|
|
98
|
-
rate?: decimal;
|
|
99
|
-
}): Observable<Readonly<Order>> {
|
|
100
|
-
const instrument = this.store.snapshot.universe.instrument.get(order.instrument.id);
|
|
101
|
-
if (!instrument) {
|
|
102
|
-
throw new InvalidInstrumentSelectorError(order.instrument.id);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const newOrder = new Order(
|
|
106
|
-
this.timestamp,
|
|
107
|
-
v4(),
|
|
108
|
-
instrument,
|
|
109
|
-
order.quantity,
|
|
110
|
-
this.timestamp,
|
|
111
|
-
order.rate
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
return of(newOrder).pipe(
|
|
115
|
-
switchMap(() => this.aggregate.open(newOrder)),
|
|
116
|
-
switchMap(() =>
|
|
117
|
-
this.order(order.instrument).pipe(filter(it => it.id == newOrder.id))
|
|
118
|
-
)
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Cancels specific order.
|
|
124
|
-
*/
|
|
125
|
-
cancel(order: Order): Observable<Readonly<Order>> {
|
|
126
|
-
return defer(() => from(this.aggregate.cancel(order))).pipe(
|
|
127
|
-
switchMap(() => this.order(order.instrument).pipe(filter(it => it.id == order.id)))
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Subscribes to specific instrument changes.
|
|
133
|
-
* When adapter awake then it will fetch collection of all available instruments.
|
|
134
|
-
*/
|
|
135
|
-
instrument(selector: InstrumentSelector): Observable<Readonly<Instrument>> {
|
|
136
|
-
this.subscribe([selector]);
|
|
137
|
-
|
|
138
|
-
return this.store.changes$.pipe(instrument(selector, this.store.snapshot));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Subscribes to instruments changes.
|
|
143
|
-
* When adapter awake then it will fetch collection of all available instruments.
|
|
144
|
-
*/
|
|
145
|
-
instruments(): Observable<Readonly<Instrument[]>> {
|
|
146
|
-
return this.store.changes$.pipe(instruments(this.store.snapshot));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Subscribes to balance changes.
|
|
151
|
-
*/
|
|
152
|
-
balance(selector: AssetSelector): Observable<Readonly<Balance>> {
|
|
153
|
-
return this.store.changes$.pipe(balance(selector, this.store.snapshot));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Subscribes to trade/ticker changes.
|
|
158
|
-
*/
|
|
159
|
-
trade(selector: InstrumentSelector): Observable<Readonly<Trade>> {
|
|
160
|
-
this.subscribe([selector]);
|
|
161
|
-
|
|
162
|
-
return this.store.changes$.pipe(trade(selector, this.store.snapshot));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Subscribes to orderbook changes.
|
|
167
|
-
* Right now you can access only best bid and best ask.
|
|
168
|
-
*/
|
|
169
|
-
orderbook(selector: InstrumentSelector): Observable<Readonly<Orderbook>> {
|
|
170
|
-
this.subscribe([selector]);
|
|
171
|
-
|
|
172
|
-
return this.store.changes$.pipe(orderbook(selector, this.store.snapshot));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Subscribes to position on leveraged market.
|
|
177
|
-
*/
|
|
178
|
-
position(selector: InstrumentSelector): Observable<Readonly<Position>> {
|
|
179
|
-
this.subscribe([selector]);
|
|
180
|
-
|
|
181
|
-
return this.store.changes$.pipe(position(selector));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Subscribes to positions on leveraged markets.
|
|
186
|
-
*/
|
|
187
|
-
positions(selector: InstrumentSelector): Observable<Readonly<Position[]>> {
|
|
188
|
-
this.subscribe([selector]);
|
|
189
|
-
|
|
190
|
-
return this.store.changes$.pipe(positions(selector, this.store.snapshot));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
order(selector: InstrumentSelector): Observable<Readonly<Order>> {
|
|
194
|
-
this.subscribe([selector]);
|
|
195
|
-
|
|
196
|
-
return this.store.changes$.pipe(order(selector));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
orders(selector: InstrumentSelector): Observable<Readonly<Order[]>> {
|
|
200
|
-
this.subscribe([selector]);
|
|
201
|
-
|
|
202
|
-
return this.store.changes$.pipe(orders(selector, this.store.snapshot));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
history(
|
|
206
|
-
selector: InstrumentSelector,
|
|
207
|
-
timeframe: number,
|
|
208
|
-
length: number
|
|
209
|
-
): Observable<Readonly<Ohlc>> {
|
|
210
|
-
return this.store.changes$.pipe(
|
|
211
|
-
startWith(this.store.snapshot.universe.instrument.get(selector.id)),
|
|
212
|
-
filter(it => it !== undefined && it.type === Instrument.type),
|
|
213
|
-
map(it => it as Instrument),
|
|
214
|
-
filter(it => it.id === selector.id),
|
|
215
|
-
switchMap(() => from(this.aggregate.history(selector, timeframe, length))),
|
|
216
|
-
take(1),
|
|
217
|
-
shareReplay(),
|
|
218
|
-
mergeMap(it => it)
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
measure<T extends { timestamp: number }>(
|
|
223
|
-
spec: {
|
|
224
|
-
kind: string;
|
|
225
|
-
timestamp?: number;
|
|
226
|
-
},
|
|
227
|
-
defaultValue?: Optional<T, 'timestamp'>
|
|
228
|
-
): [Observable<T>, (value: T) => void] {
|
|
229
|
-
if (!this.measurement) {
|
|
230
|
-
throw new Error();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const changes$ = new ReplaySubject<Optional<T, 'timestamp'>>();
|
|
234
|
-
const persisted$ = from(
|
|
235
|
-
this.measurement.query(this.id, {
|
|
236
|
-
to: spec.timestamp ?? this.timestamp,
|
|
237
|
-
kind: spec.kind,
|
|
238
|
-
count: 1
|
|
239
|
-
})
|
|
240
|
-
).pipe(
|
|
241
|
-
map(it =>
|
|
242
|
-
it.length ? { timestamp: it[0].timestamp, ...it[0].payload } : defaultValue
|
|
243
|
-
),
|
|
244
|
-
share()
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
const setter = (value: Optional<T, 'timestamp'>) => {
|
|
248
|
-
const timestamp = value.timestamp ?? this.timestamp;
|
|
249
|
-
const measure = { timestamp, kind: spec.kind, payload: value };
|
|
250
|
-
|
|
251
|
-
this.measurement?.save(this.id, [measure]);
|
|
252
|
-
|
|
253
|
-
changes$.next({ ...value, timestamp });
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
return [
|
|
257
|
-
concat(persisted$, changes$.asObservable()).pipe(filter(it => it !== undefined)),
|
|
258
|
-
setter
|
|
259
|
-
];
|
|
260
|
-
}
|
|
261
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Subject } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { Asset, Commission, Component, Instrument, Trade, trade } from '@lib/domain';
|
|
4
|
-
import { d } from '@lib/shared';
|
|
5
|
-
import { State } from '@lib/store';
|
|
6
|
-
|
|
7
|
-
describe(trade.name, () => {
|
|
8
|
-
const instrument = new Instrument(
|
|
9
|
-
0,
|
|
10
|
-
new Asset('abc', 'xyz', 4),
|
|
11
|
-
new Asset('def', 'xyz', 4),
|
|
12
|
-
'abc-def',
|
|
13
|
-
Commission.Zero
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const state = new State();
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
state.trade.upsert(new Trade(0, instrument, d.Zero, d.Zero));
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('should pipe an orderbook on subscription', done => {
|
|
23
|
-
new Subject<Component>().pipe(trade(instrument, state)).subscribe({
|
|
24
|
-
next: it => {
|
|
25
|
-
expect(it.id).toEqual(instrument.id);
|
|
26
|
-
done();
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { filter, map, Observable, startWith } from 'rxjs';
|
|
2
|
-
|
|
3
|
-
import { Component, InstrumentSelector, Trade } from '@lib/domain';
|
|
4
|
-
import { State } from '@lib/store';
|
|
5
|
-
|
|
6
|
-
export function trade(selector: InstrumentSelector, state: State) {
|
|
7
|
-
return (source$: Observable<Component>) =>
|
|
8
|
-
source$.pipe(
|
|
9
|
-
startWith(state.trade.get(selector.id)),
|
|
10
|
-
filter(it => it !== undefined && it.type === Trade.type),
|
|
11
|
-
map(it => it as Trade),
|
|
12
|
-
filter(it => it.instrument.id === selector.id)
|
|
13
|
-
);
|
|
14
|
-
}
|
package/src/domain/trade.spec.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Asset, Commission, Instrument, Trade } from '@lib/domain';
|
|
2
|
-
import { d } from '@lib/shared';
|
|
3
|
-
|
|
4
|
-
describe(Trade.name, () => {
|
|
5
|
-
const instrument = new Instrument(
|
|
6
|
-
0,
|
|
7
|
-
new Asset('abc', 'xyz', 4),
|
|
8
|
-
new Asset('def', 'xyz', 4),
|
|
9
|
-
'abc-def',
|
|
10
|
-
Commission.Zero
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
test('should construct an empty trade', () => {
|
|
14
|
-
const sut = new Trade(0, instrument, d.Zero, d.Zero);
|
|
15
|
-
|
|
16
|
-
expect(sut.id).toEqual(instrument.id);
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/domain/trade.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Component, Instrument } from '@lib/domain';
|
|
2
|
-
import { decimal, hash } from '@lib/shared';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Simple trade or ticker executed on the market, it's a match of buyer
|
|
6
|
-
* and seller of the same asset.
|
|
7
|
-
*/
|
|
8
|
-
export class Trade implements Component {
|
|
9
|
-
static type = hash(Trade.name);
|
|
10
|
-
readonly type = Trade.type;
|
|
11
|
-
|
|
12
|
-
readonly id: string;
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
public timestamp: number,
|
|
16
|
-
public readonly instrument: Instrument,
|
|
17
|
-
public rate: decimal,
|
|
18
|
-
public quantity: decimal
|
|
19
|
-
) {
|
|
20
|
-
this.id = instrument.id;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Liquidity, LiquidityAskComparer } from '@lib/domain';
|
|
2
|
-
import { d, PriorityList } from '@lib/shared';
|
|
3
|
-
|
|
4
|
-
describe('PriorityList', () => {
|
|
5
|
-
test('should patch a best bid and ask', () => {
|
|
6
|
-
const input = [
|
|
7
|
-
{ rate: d(2), quantity: d(2) },
|
|
8
|
-
{ rate: d(2), quantity: d(3) },
|
|
9
|
-
{ rate: d(5), quantity: d(1) },
|
|
10
|
-
{ rate: d(5), quantity: d(2) },
|
|
11
|
-
{ rate: d(3), quantity: d(1) },
|
|
12
|
-
{ rate: d(1), quantity: d(8) },
|
|
13
|
-
{ rate: d(1), quantity: d(0) },
|
|
14
|
-
{ rate: d(3), quantity: d(0) },
|
|
15
|
-
{ rate: d(5), quantity: d(0) }
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
const sut = new PriorityList<Liquidity>(LiquidityAskComparer, it =>
|
|
19
|
-
it.rate.toString()
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
input.forEach(it => (it.quantity.greaterThan(0) ? sut.enqueue(it) : sut.dequeue(it)));
|
|
23
|
-
|
|
24
|
-
const volume = sut.reduce((it, agg) => agg.add(it.quantity.mul(it.rate)), d.Zero);
|
|
25
|
-
|
|
26
|
-
const head = sut.head ?? fail();
|
|
27
|
-
|
|
28
|
-
expect(head.rate).toEqual(d(2));
|
|
29
|
-
expect(head.quantity).toEqual(d(3));
|
|
30
|
-
expect(volume).toEqual(d(6));
|
|
31
|
-
expect(sut.getByKey(d(2).toString()).quantity).toEqual(d(3));
|
|
32
|
-
expect(sut.getByKey(d(3).toString())).toEqual(undefined);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
export class Set<T extends { id: string }> {
|
|
2
|
-
private readonly array: Array<T> = [];
|
|
3
|
-
|
|
4
|
-
constructor(values?: ReadonlyArray<T>) {
|
|
5
|
-
if (values) {
|
|
6
|
-
values.forEach(it => this.upsert(it));
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get(id: string) {
|
|
11
|
-
return this.array.find(it => it.id == id);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
tryGetOrSet(id: string, setter: () => T): T {
|
|
15
|
-
return this.get(id) ?? this.upsert(setter());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
upsert(value: T) {
|
|
19
|
-
const index = this.array.findIndex(it => it.id == value.id);
|
|
20
|
-
|
|
21
|
-
if (index >= 0) {
|
|
22
|
-
this.array[index] = value;
|
|
23
|
-
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
this.array.push(value);
|
|
28
|
-
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
remove(value: T) {
|
|
33
|
-
const index = this.array.indexOf(value);
|
|
34
|
-
if (index > -1) {
|
|
35
|
-
this.array.splice(index, 1);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
asReadonlyArray(): ReadonlyArray<T> {
|
|
40
|
-
return this.array;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
clear() {
|
|
44
|
-
this.array.splice(0, this.array.length);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export class PriorityList<T extends { next: T | undefined }> {
|
|
49
|
-
private valueByKey: Record<string, T> = {};
|
|
50
|
-
|
|
51
|
-
head: T | undefined;
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
private readonly comparer: (lhs: Omit<T, 'next'>, rhs: Omit<T, 'next'>) => number,
|
|
55
|
-
private readonly getKeyFn: (key: Omit<T, 'next'>) => string
|
|
56
|
-
) {}
|
|
57
|
-
|
|
58
|
-
getByKey(key: string): T {
|
|
59
|
-
return this.valueByKey[key];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private make(value: Omit<T, 'next'>, next: T | undefined = undefined): T {
|
|
63
|
-
const node = { ...value, next } as T;
|
|
64
|
-
|
|
65
|
-
this.valueByKey[this.getKeyFn(node)] = node;
|
|
66
|
-
|
|
67
|
-
return node;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
enqueue(value: Omit<T, 'next'>) {
|
|
71
|
-
if (!this.head) {
|
|
72
|
-
this.head = this.make(value);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (this.comparer(this.head, value) > 0) {
|
|
76
|
-
this.head = this.make(value, this.head);
|
|
77
|
-
} else if (this.comparer(this.head, value) == 0) {
|
|
78
|
-
this.head = this.make(value, this.head.next);
|
|
79
|
-
} else {
|
|
80
|
-
this.visit(it => {
|
|
81
|
-
if (it.next) {
|
|
82
|
-
if (this.comparer(it.next, value) == 0) {
|
|
83
|
-
it.next = this.make(value, it.next.next);
|
|
84
|
-
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (this.comparer(it.next, value) > 0) {
|
|
89
|
-
it.next = this.make(value, it.next);
|
|
90
|
-
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return true;
|
|
95
|
-
} else {
|
|
96
|
-
it.next = this.make(value);
|
|
97
|
-
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
dequeue(value: Omit<T, 'next'>) {
|
|
105
|
-
if (!this.head) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (this.comparer(this.head, value) == 0) {
|
|
110
|
-
this.head = this.head.next;
|
|
111
|
-
|
|
112
|
-
delete this.valueByKey[this.getKeyFn(value)];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.visit(it => {
|
|
116
|
-
if (it.next && this.comparer(it.next, value) == 0) {
|
|
117
|
-
it.next = it.next.next;
|
|
118
|
-
|
|
119
|
-
delete this.valueByKey[this.getKeyFn(value)];
|
|
120
|
-
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return false;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
clear() {
|
|
129
|
-
this.head = undefined;
|
|
130
|
-
this.valueByKey = {};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
visit(fn: (value: T) => boolean) {
|
|
134
|
-
let top = this.head;
|
|
135
|
-
|
|
136
|
-
while (top) {
|
|
137
|
-
if (!fn(top)) {
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
top = top.next;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
reduce<K>(fn: (value: T, aggregate: K) => K, initValue: K) {
|
|
146
|
-
this.visit(it => {
|
|
147
|
-
initValue = fn(it, initValue);
|
|
148
|
-
|
|
149
|
-
return true;
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
return initValue;
|
|
153
|
-
}
|
|
154
|
-
}
|
package/src/shared/hash.ts
DELETED
package/src/shared/logger.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
|
|
3
|
-
import { now } from '@lib/shared';
|
|
4
|
-
|
|
5
|
-
const colorize = (content: string) => {
|
|
6
|
-
let hash = 0x811c9dc5;
|
|
7
|
-
|
|
8
|
-
for (let i = 0; i < content.length; i++) {
|
|
9
|
-
hash ^= content.charCodeAt(i);
|
|
10
|
-
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return chalk.hex('#' + (hash * 0xfffff * 1000000).toString(16).slice(0, 6))(content);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const time = () => chalk.gray(new Date(now()).toISOString());
|
|
17
|
-
|
|
18
|
-
export class Logger {
|
|
19
|
-
constructor(private readonly context: string) {}
|
|
20
|
-
|
|
21
|
-
public info = (message: any, ...params: unknown[]) =>
|
|
22
|
-
params?.length
|
|
23
|
-
? console.info(`${this.prefix()}: ${message}`, params)
|
|
24
|
-
: console.info(`${this.prefix()}: ${message}`);
|
|
25
|
-
|
|
26
|
-
public debug = (message: any, ...params: unknown[]) =>
|
|
27
|
-
params?.length
|
|
28
|
-
? console.debug(`${this.prefix()}: ${message}`, params)
|
|
29
|
-
: console.debug(`${this.prefix()}: ${message}`);
|
|
30
|
-
|
|
31
|
-
public warn = (message: any, ...params: unknown[]) =>
|
|
32
|
-
params?.length
|
|
33
|
-
? console.warn(`${this.prefix()}: ${message}`, params)
|
|
34
|
-
: console.warn(`${this.prefix()}: ${message}`);
|
|
35
|
-
|
|
36
|
-
public error = (message: any, ...params: unknown[]) =>
|
|
37
|
-
params?.length
|
|
38
|
-
? console.error(`${this.prefix()}: ${message}`, params)
|
|
39
|
-
: console.error(`${this.prefix()}: ${message}`);
|
|
40
|
-
|
|
41
|
-
public prefix = () => `${time()} ${colorize(this.context)}`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function log(context: string): Logger {
|
|
45
|
-
return new Logger(context);
|
|
46
|
-
}
|
package/src/shared/policy.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Cache, InMemoryStorage } from '@lib/storage';
|
|
2
|
-
|
|
3
|
-
describe(Cache.name, () => {
|
|
4
|
-
test('should return cached value', async () => {
|
|
5
|
-
const cache = new Cache(new InMemoryStorage());
|
|
6
|
-
|
|
7
|
-
const value1 = await cache.tryGet(() => Promise.resolve('quantform-1'), {
|
|
8
|
-
key: 'test'
|
|
9
|
-
});
|
|
10
|
-
const value2 = await cache.tryGet(() => Promise.resolve('quantform-2'), {
|
|
11
|
-
key: 'test'
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
expect(value1).toEqual('quantform-1');
|
|
15
|
-
expect(value2).toEqual('quantform-1');
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/storage/cache.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { now } from '@lib/shared';
|
|
2
|
-
import { Storage } from '@lib/storage';
|
|
3
|
-
|
|
4
|
-
export class Cache {
|
|
5
|
-
constructor(private readonly storage: Storage) {}
|
|
6
|
-
|
|
7
|
-
async tryGet<T>(
|
|
8
|
-
getter: () => Promise<T>,
|
|
9
|
-
options: { key: string; ttl?: number }
|
|
10
|
-
): Promise<T> {
|
|
11
|
-
const time = now();
|
|
12
|
-
|
|
13
|
-
const payload = await this.storage.query(options.key, {
|
|
14
|
-
kind: 'cache',
|
|
15
|
-
count: 1,
|
|
16
|
-
to: time + 1
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const ttl = options.ttl ?? 60 * 60 * 24;
|
|
20
|
-
|
|
21
|
-
if (!payload.length || payload[0].timestamp < time - ttl) {
|
|
22
|
-
const value = await getter();
|
|
23
|
-
|
|
24
|
-
await this.storage.save(options.key, [
|
|
25
|
-
{
|
|
26
|
-
timestamp: time,
|
|
27
|
-
kind: 'cache',
|
|
28
|
-
json: JSON.stringify(value)
|
|
29
|
-
}
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return JSON.parse(payload[0].json);
|
|
36
|
-
}
|
|
37
|
-
}
|