@quantform/core 0.6.5 → 0.6.7
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/adapter/adapter-aggregate.d.ts +2 -2
- package/dist/adapter/adapter-aggregate.d.ts.map +1 -1
- package/dist/adapter/adapter-aggregate.js +12 -11
- package/dist/adapter/adapter.d.ts +2 -3
- package/dist/adapter/adapter.d.ts.map +1 -1
- package/dist/adapter/backtester/backtester-adapter.d.ts +1 -5
- package/dist/adapter/backtester/backtester-adapter.d.ts.map +1 -1
- package/dist/adapter/backtester/backtester-adapter.js +2 -2
- package/dist/adapter/backtester/backtester-cursor.d.ts.map +1 -1
- package/dist/adapter/backtester/backtester-cursor.js +2 -2
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts +2 -0
- package/dist/adapter/backtester/backtester-cursor.spec.d.ts.map +1 -0
- package/dist/adapter/backtester/backtester-cursor.spec.js +47 -0
- package/dist/adapter/backtester/backtester-streamer.d.ts +1 -1
- package/dist/adapter/backtester/backtester-streamer.d.ts.map +1 -1
- package/dist/adapter/backtester/backtester-streamer.js +4 -5
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts +2 -0
- package/dist/adapter/backtester/backtester-streamer.spec.d.ts.map +1 -0
- package/dist/adapter/backtester/backtester-streamer.spec.js +45 -0
- package/dist/adapter/backtester/error.d.ts +6 -2
- package/dist/adapter/backtester/error.d.ts.map +1 -1
- package/dist/adapter/backtester/error.js +11 -7
- package/dist/adapter/backtester/index.d.ts +4 -2
- package/dist/adapter/backtester/index.d.ts.map +1 -1
- package/dist/adapter/backtester/index.js +4 -2
- package/dist/adapter/error.d.ts +9 -3
- package/dist/adapter/error.d.ts.map +1 -1
- package/dist/adapter/error.js +16 -10
- package/dist/adapter/index.d.ts +5 -4
- package/dist/adapter/index.d.ts.map +1 -1
- package/dist/adapter/index.js +5 -4
- package/dist/adapter/paper/engine/paper-engine.d.ts.map +1 -1
- package/dist/adapter/paper/engine/paper-engine.js +7 -8
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts +2 -0
- package/dist/adapter/paper/engine/paper-engine.spec.d.ts.map +1 -0
- package/dist/adapter/paper/engine/paper-engine.spec.js +63 -0
- package/dist/adapter/paper/index.d.ts +2 -2
- package/dist/adapter/paper/index.d.ts.map +1 -1
- package/dist/adapter/paper/index.js +2 -2
- package/dist/adapter/paper/paper-adapter.d.ts +1 -3
- package/dist/adapter/paper/paper-adapter.d.ts.map +1 -1
- package/dist/adapter/paper/paper-adapter.js +8 -7
- package/dist/cli/build.js +1 -1
- package/dist/cli/dev.js +6 -6
- package/dist/cli/index.js +5 -5
- package/dist/cli/internal/workspace.js +1 -1
- package/dist/cli/pull.js +6 -6
- package/dist/cli/run.js +6 -6
- package/dist/cli/test.d.ts.map +1 -1
- package/dist/cli/test.js +9 -8
- package/dist/domain/asset.d.ts +5 -1
- package/dist/domain/asset.d.ts.map +1 -1
- package/dist/domain/asset.js +13 -7
- package/dist/domain/asset.spec.d.ts +2 -0
- package/dist/domain/asset.spec.d.ts.map +1 -0
- package/dist/domain/asset.spec.js +54 -0
- package/dist/domain/balance-operator.d.ts +1 -3
- package/dist/domain/balance-operator.d.ts.map +1 -1
- package/dist/domain/balance-operator.js +2 -2
- package/dist/domain/balance-operator.spec.d.ts +2 -0
- package/dist/domain/balance-operator.spec.d.ts.map +1 -0
- package/dist/domain/balance-operator.spec.js +21 -0
- package/dist/domain/balance.d.ts +14 -15
- package/dist/domain/balance.d.ts.map +1 -1
- package/dist/domain/balance.js +30 -48
- package/dist/domain/balance.spec.d.ts +2 -0
- package/dist/domain/balance.spec.d.ts.map +1 -0
- package/dist/domain/balance.spec.js +32 -0
- package/dist/domain/commission.d.ts.map +1 -1
- package/dist/domain/commission.spec.d.ts +2 -0
- package/dist/domain/commission.spec.d.ts.map +1 -0
- package/dist/domain/commission.spec.js +30 -0
- package/dist/domain/component.d.ts +2 -2
- package/dist/domain/component.d.ts.map +1 -1
- package/dist/domain/error.d.ts +15 -5
- package/dist/domain/error.d.ts.map +1 -1
- package/dist/domain/error.js +26 -16
- package/dist/domain/index.d.ts +21 -21
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +21 -21
- package/dist/domain/instrument-operator.d.ts +1 -2
- package/dist/domain/instrument-operator.d.ts.map +1 -1
- package/dist/domain/instrument-operator.js +3 -3
- package/dist/domain/instrument-operator.spec.d.ts +2 -0
- package/dist/domain/instrument-operator.spec.d.ts.map +1 -0
- package/dist/domain/instrument-operator.spec.js +21 -0
- package/dist/domain/instrument.d.ts +3 -3
- package/dist/domain/instrument.d.ts.map +1 -1
- package/dist/domain/instrument.js +10 -8
- package/dist/domain/instrument.spec.d.ts +2 -0
- package/dist/domain/instrument.spec.d.ts.map +1 -0
- package/dist/domain/instrument.spec.js +51 -0
- package/dist/domain/ohlc-operator.d.ts +1 -1
- package/dist/domain/ohlc-operator.d.ts.map +1 -1
- package/dist/domain/ohlc-operator.js +4 -5
- package/dist/domain/ohlc-operator.spec.d.ts +2 -0
- package/dist/domain/ohlc-operator.spec.d.ts.map +1 -0
- package/dist/domain/ohlc-operator.spec.js +110 -0
- package/dist/domain/ohlc.d.ts.map +1 -1
- package/dist/domain/ohlc.spec.d.ts +2 -0
- package/dist/domain/ohlc.spec.d.ts.map +1 -0
- package/dist/domain/ohlc.spec.js +25 -0
- package/dist/domain/order-operator.d.ts +1 -3
- package/dist/domain/order-operator.d.ts.map +1 -1
- package/dist/domain/order-operator.js +3 -3
- package/dist/domain/order-operator.spec.d.ts +2 -0
- package/dist/domain/order-operator.spec.d.ts.map +1 -0
- package/dist/domain/order-operator.spec.js +61 -0
- package/dist/domain/order.d.ts +5 -8
- package/dist/domain/order.d.ts.map +1 -1
- package/dist/domain/order.js +14 -22
- package/dist/domain/order.spec.d.ts +2 -0
- package/dist/domain/order.spec.d.ts.map +1 -0
- package/dist/domain/order.spec.js +27 -0
- package/dist/domain/orderbook-operator.d.ts +1 -3
- package/dist/domain/orderbook-operator.d.ts.map +1 -1
- package/dist/domain/orderbook-operator.js +2 -2
- package/dist/domain/orderbook-operator.spec.d.ts +2 -0
- package/dist/domain/orderbook-operator.spec.d.ts.map +1 -0
- package/dist/domain/orderbook-operator.spec.js +19 -0
- package/dist/domain/orderbook.d.ts +3 -2
- package/dist/domain/orderbook.d.ts.map +1 -1
- package/dist/domain/orderbook.js +3 -0
- package/dist/domain/orderbook.spec.d.ts +2 -0
- package/dist/domain/orderbook.spec.d.ts.map +1 -0
- package/dist/domain/orderbook.spec.js +11 -0
- package/dist/domain/position-operator.d.ts +1 -3
- package/dist/domain/position-operator.d.ts.map +1 -1
- package/dist/domain/position-operator.js +3 -4
- package/dist/domain/position-operator.spec.d.ts +2 -0
- package/dist/domain/position-operator.spec.d.ts.map +1 -0
- package/dist/domain/position-operator.spec.js +44 -0
- package/dist/domain/position.d.ts +3 -2
- package/dist/domain/position.d.ts.map +1 -1
- package/dist/domain/position.js +2 -0
- package/dist/domain/position.spec.d.ts +2 -0
- package/dist/domain/position.spec.d.ts.map +1 -0
- package/dist/domain/position.spec.js +28 -0
- package/dist/domain/session-builder.d.ts +8 -4
- package/dist/domain/session-builder.d.ts.map +1 -1
- package/dist/domain/session-builder.js +10 -15
- package/dist/domain/session.d.ts +1 -1
- package/dist/domain/session.d.ts.map +1 -1
- package/dist/domain/session.js +11 -17
- package/dist/domain/session.spec.d.ts +2 -0
- package/dist/domain/session.spec.d.ts.map +1 -0
- package/dist/domain/session.spec.js +17 -0
- package/dist/domain/trade-operator.d.ts +1 -3
- package/dist/domain/trade-operator.d.ts.map +1 -1
- package/dist/domain/trade-operator.js +2 -2
- package/dist/domain/trade-operator.spec.d.ts +2 -0
- package/dist/domain/trade-operator.spec.d.ts.map +1 -0
- package/dist/domain/trade-operator.spec.js +21 -0
- package/dist/domain/trade.d.ts +3 -2
- package/dist/domain/trade.d.ts.map +1 -1
- package/dist/domain/trade.js +3 -0
- package/dist/domain/trade.spec.d.ts +2 -0
- package/dist/domain/trade.spec.d.ts.map +1 -0
- package/dist/domain/trade.spec.js +11 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -8
- package/dist/shared/collections.spec.d.ts +2 -0
- package/dist/shared/collections.spec.d.ts.map +1 -0
- package/dist/shared/collections.spec.js +29 -0
- package/dist/shared/decimals.spec.d.ts +2 -0
- package/dist/shared/decimals.spec.d.ts.map +1 -0
- package/dist/shared/decimals.spec.js +28 -0
- package/dist/shared/hash.d.ts +2 -0
- package/dist/shared/hash.d.ts.map +1 -0
- package/dist/shared/hash.js +12 -0
- package/dist/shared/index.d.ts +7 -7
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +7 -7
- package/dist/shared/logger.d.ts +8 -5
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/logger.js +23 -16
- package/dist/storage/cache.d.ts +1 -1
- package/dist/storage/cache.d.ts.map +1 -1
- package/dist/storage/cache.spec.d.ts +2 -0
- package/dist/storage/cache.spec.d.ts.map +1 -0
- package/dist/storage/cache.spec.js +25 -0
- package/dist/storage/feed.d.ts +1 -1
- package/dist/storage/feed.d.ts.map +1 -1
- 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/measurement.d.ts +1 -1
- package/dist/storage/measurement.d.ts.map +1 -1
- package/dist/store/error.d.ts +21 -7
- package/dist/store/error.d.ts.map +1 -1
- package/dist/store/error.js +36 -22
- package/dist/store/index.d.ts +10 -9
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +10 -9
- package/dist/store/store-balance-event.d.ts +10 -30
- package/dist/store/store-balance-event.d.ts.map +1 -1
- package/dist/store/store-balance-event.js +19 -94
- package/dist/store/store-balance-event.spec.d.ts +2 -0
- package/dist/store/store-balance-event.spec.d.ts.map +1 -0
- package/dist/store/store-balance-event.spec.js +24 -0
- package/dist/store/store-event.d.ts +1 -1
- package/dist/store/store-event.d.ts.map +1 -1
- package/dist/store/store-instrument-event.d.ts +1 -2
- package/dist/store/store-instrument-event.d.ts.map +1 -1
- package/dist/store/store-instrument-event.js +5 -6
- package/dist/store/store-instrument-event.spec.d.ts +2 -0
- package/dist/store/store-instrument-event.spec.d.ts.map +1 -0
- package/dist/store/store-instrument-event.spec.js +22 -0
- package/dist/store/store-order-event.d.ts +1 -2
- package/dist/store/store-order-event.d.ts.map +1 -1
- package/dist/store/store-order-event.js +60 -22
- package/dist/store/store-order-event.spec.d.ts +2 -0
- package/dist/store/store-order-event.spec.d.ts.map +1 -0
- package/dist/store/store-order-event.spec.js +23 -0
- package/dist/store/store-orderbook-event.d.ts +1 -2
- package/dist/store/store-orderbook-event.d.ts.map +1 -1
- package/dist/store/store-orderbook-event.js +3 -3
- package/dist/store/store-orderbook-event.spec.d.ts +2 -0
- package/dist/store/store-orderbook-event.spec.d.ts.map +1 -0
- package/dist/store/store-orderbook-event.spec.js +27 -0
- package/dist/store/store-position-event.d.ts +1 -2
- package/dist/store/store-position-event.d.ts.map +1 -1
- package/dist/store/store-position-event.js +5 -5
- package/dist/store/store-state.d.ts.map +1 -1
- package/dist/store/store-trade-event.d.ts +1 -2
- package/dist/store/store-trade-event.d.ts.map +1 -1
- package/dist/store/store-trade-event.js +3 -3
- package/dist/store/store-trade-event.spec.d.ts +2 -0
- package/dist/store/store-trade-event.spec.d.ts.map +1 -0
- package/dist/store/store-trade-event.spec.js +44 -0
- package/dist/store/store.d.ts +1 -2
- package/dist/store/store.d.ts.map +1 -1
- package/dist/store/store.js +5 -2
- package/dist/store/store.spec.d.ts +2 -0
- package/dist/store/store.spec.d.ts.map +1 -0
- package/dist/store/store.spec.js +122 -0
- package/jest.config.ts +23 -2
- package/package.json +2 -2
- package/src/adapter/adapter-aggregate.ts +35 -21
- package/src/adapter/adapter.ts +6 -7
- package/src/adapter/backtester/backtester-adapter.ts +12 -8
- package/src/adapter/backtester/backtester-cursor.spec.ts +6 -6
- package/src/adapter/backtester/backtester-cursor.ts +5 -5
- package/src/adapter/backtester/backtester-streamer.spec.ts +6 -6
- package/src/adapter/backtester/backtester-streamer.ts +12 -9
- package/src/adapter/backtester/error.ts +8 -4
- package/src/adapter/backtester/index.ts +4 -2
- package/src/adapter/error.ts +14 -8
- package/src/adapter/index.ts +5 -4
- package/src/adapter/paper/engine/paper-engine.spec.ts +6 -12
- package/src/adapter/paper/engine/paper-engine.ts +13 -28
- package/src/adapter/paper/index.ts +2 -2
- package/src/adapter/paper/paper-adapter.ts +18 -11
- package/src/cli/build.ts +1 -1
- package/src/cli/dev.ts +5 -5
- package/src/cli/index.ts +5 -5
- package/src/cli/internal/workspace.ts +1 -1
- package/src/cli/pull.ts +7 -7
- package/src/cli/run.ts +5 -5
- package/src/cli/test.ts +8 -7
- package/src/domain/asset.spec.ts +4 -4
- package/src/domain/asset.ts +13 -6
- package/src/domain/balance-operator.spec.ts +3 -6
- package/src/domain/balance-operator.ts +5 -6
- package/src/domain/balance.spec.ts +7 -77
- package/src/domain/balance.ts +51 -64
- package/src/domain/commission.spec.ts +3 -3
- package/src/domain/commission.ts +1 -1
- package/src/domain/component.ts +3 -3
- package/src/domain/error.ts +23 -18
- package/src/domain/index.ts +21 -21
- package/src/domain/instrument-operator.spec.ts +10 -7
- package/src/domain/instrument-operator.ts +6 -6
- package/src/domain/instrument.spec.ts +11 -6
- package/src/domain/instrument.ts +16 -7
- package/src/domain/ohlc-operator.spec.ts +5 -6
- package/src/domain/ohlc-operator.ts +2 -3
- package/src/domain/ohlc.spec.ts +2 -2
- package/src/domain/ohlc.ts +2 -2
- package/src/domain/order-operator.spec.ts +14 -10
- package/src/domain/order-operator.ts +8 -7
- package/src/domain/order.spec.ts +3 -6
- package/src/domain/order.ts +26 -29
- package/src/domain/orderbook-operator.spec.ts +11 -9
- package/src/domain/orderbook-operator.ts +5 -6
- package/src/domain/orderbook.spec.ts +3 -6
- package/src/domain/orderbook.ts +5 -3
- package/src/domain/position-operator.spec.ts +14 -11
- package/src/domain/position-operator.ts +12 -9
- package/src/domain/position.spec.ts +3 -6
- package/src/domain/position.ts +5 -3
- package/src/domain/session-builder.ts +14 -14
- package/src/domain/session.spec.ts +4 -4
- package/src/domain/session.ts +20 -15
- package/src/domain/trade-operator.spec.ts +4 -9
- package/src/domain/trade-operator.ts +5 -6
- package/src/domain/trade.spec.ts +3 -6
- package/src/domain/trade.ts +5 -3
- package/src/index.ts +15 -14
- package/src/shared/collections.spec.ts +2 -2
- package/src/shared/decimals.spec.ts +1 -1
- package/src/shared/hash.ts +10 -0
- package/src/shared/index.ts +7 -7
- package/src/shared/logger.ts +22 -15
- package/src/storage/cache.spec.ts +2 -3
- package/src/storage/cache.ts +2 -2
- package/src/storage/feed.ts +4 -4
- package/src/storage/index.ts +4 -4
- package/src/storage/measurement.ts +2 -2
- package/src/store/error.ts +33 -22
- package/src/store/index.ts +10 -9
- package/src/store/store-balance-event.spec.ts +5 -7
- package/src/store/store-balance-event.ts +20 -115
- package/src/store/store-event.ts +2 -2
- package/src/store/store-instrument-event.spec.ts +4 -5
- package/src/store/store-instrument-event.ts +13 -9
- package/src/store/store-order-event.spec.ts +6 -5
- package/src/store/store-order-event.ts +92 -23
- package/src/store/store-orderbook-event.spec.ts +4 -5
- package/src/store/store-orderbook-event.ts +11 -7
- package/src/store/store-position-event.ts +13 -9
- package/src/store/store-state.ts +2 -2
- package/src/store/store-trade-event.spec.ts +4 -5
- package/src/store/store-trade-event.ts +11 -7
- package/src/store/store.spec.ts +45 -31
- package/src/store/store.ts +6 -3
- package/tsconfig.json +7 -4
- package/dist/cli/error.d.ts +0 -2
- package/dist/cli/error.d.ts.map +0 -1
- package/dist/cli/error.js +0 -7
- package/dist/shared/pipe.d.ts +0 -5
- package/dist/shared/pipe.d.ts.map +0 -1
- package/dist/shared/pipe.js +0 -8
- package/src/cli/error.ts +0 -5
- package/src/shared/pipe.ts +0 -12
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Subject } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import {
|
|
4
|
+
Asset,
|
|
5
|
+
Commission,
|
|
6
|
+
Component,
|
|
7
|
+
Instrument,
|
|
8
|
+
Orderbook,
|
|
9
|
+
orderbook
|
|
10
|
+
} from '@lib/domain';
|
|
11
|
+
import { d } from '@lib/shared';
|
|
12
|
+
import { State } from '@lib/store';
|
|
11
13
|
|
|
12
|
-
describe(
|
|
14
|
+
describe(orderbook.name, () => {
|
|
13
15
|
const instrument = new Instrument(
|
|
14
16
|
0,
|
|
15
17
|
new Asset('abc', 'xyz', 4),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { filter, map, Observable, startWith } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { InstrumentSelector } from './instrument';
|
|
6
|
-
import { Orderbook } from './orderbook';
|
|
3
|
+
import { Component, InstrumentSelector, Orderbook } from '@lib/domain';
|
|
4
|
+
import { State } from '@lib/store';
|
|
7
5
|
|
|
8
6
|
export function orderbook(selector: InstrumentSelector, state: State) {
|
|
9
7
|
return (source$: Observable<Component>) =>
|
|
10
8
|
source$.pipe(
|
|
11
9
|
startWith(state.orderbook.get(selector.id)),
|
|
12
|
-
filter(it => it
|
|
13
|
-
map(it => it as Orderbook)
|
|
10
|
+
filter(it => it !== undefined && it.type === Orderbook.type),
|
|
11
|
+
map(it => it as Orderbook),
|
|
12
|
+
filter(it => it.instrument.id === selector.id)
|
|
14
13
|
);
|
|
15
14
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Commission } from './commission';
|
|
4
|
-
import { Instrument } from './instrument';
|
|
5
|
-
import { Orderbook } from './orderbook';
|
|
1
|
+
import { Asset, Commission, Instrument, Orderbook } from '@lib/domain';
|
|
2
|
+
import { d } from '@lib/shared';
|
|
6
3
|
|
|
7
|
-
describe(
|
|
4
|
+
describe(Orderbook.name, () => {
|
|
8
5
|
const instrument = new Instrument(
|
|
9
6
|
0,
|
|
10
7
|
new Asset('abc', 'xyz', 4),
|
package/src/domain/orderbook.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Instrument } from '
|
|
2
|
-
import { decimal } from '
|
|
3
|
-
import { Component } from './component';
|
|
1
|
+
import { Component, Instrument } from '@lib/domain';
|
|
2
|
+
import { decimal, hash } from '@lib/shared';
|
|
4
3
|
|
|
5
4
|
export interface Liquidity {
|
|
6
5
|
rate: decimal;
|
|
@@ -17,6 +16,9 @@ export const LiquidityBidComparer = (lhs: { rate: decimal }, rhs: { rate: decima
|
|
|
17
16
|
* Provides an access to pending buy and sell orders on the specific market.
|
|
18
17
|
*/
|
|
19
18
|
export class Orderbook implements Component {
|
|
19
|
+
static type = hash(Orderbook.name);
|
|
20
|
+
readonly type = Orderbook.type;
|
|
21
|
+
|
|
20
22
|
readonly id: string;
|
|
21
23
|
|
|
22
24
|
constructor(
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { BehaviorSubject, Subject } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import {
|
|
4
|
+
Asset,
|
|
5
|
+
Balance,
|
|
6
|
+
Commission,
|
|
7
|
+
Component,
|
|
8
|
+
Instrument,
|
|
9
|
+
Position,
|
|
10
|
+
position,
|
|
11
|
+
positions
|
|
12
|
+
} from '@lib/domain';
|
|
13
|
+
import { d } from '@lib/shared';
|
|
14
|
+
import { State } from '@lib/store';
|
|
12
15
|
|
|
13
16
|
const instrument = new Instrument(
|
|
14
17
|
0,
|
|
@@ -18,7 +21,7 @@ const instrument = new Instrument(
|
|
|
18
21
|
Commission.Zero
|
|
19
22
|
);
|
|
20
23
|
|
|
21
|
-
describe(
|
|
24
|
+
describe(position.name, () => {
|
|
22
25
|
test('should pipe a position', done => {
|
|
23
26
|
new BehaviorSubject<Component>(
|
|
24
27
|
new Position(0, '1', instrument, 'CROSS', d(10), d(2), 3)
|
|
@@ -40,7 +43,7 @@ describe('position', () => {
|
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
45
|
|
|
43
|
-
describe(
|
|
46
|
+
describe(positions.name, () => {
|
|
44
47
|
const state = new State();
|
|
45
48
|
const balance = new Balance(0, instrument.quote);
|
|
46
49
|
const position1 = new Position(0, '1', instrument, 'CROSS', d(10), d(2), 3);
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { filter, map, Observable, share, startWith } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import {
|
|
4
|
+
Component,
|
|
5
|
+
InstrumentSelector,
|
|
6
|
+
InvalidInstrumentSelectorError,
|
|
7
|
+
Position
|
|
8
|
+
} from '@lib/domain';
|
|
9
|
+
import { d, decimal, weightedMean } from '@lib/shared';
|
|
10
|
+
import { State } from '@lib/store';
|
|
9
11
|
|
|
10
12
|
export function position(selector: InstrumentSelector) {
|
|
11
13
|
return (source: Observable<Component>) =>
|
|
12
14
|
source.pipe(
|
|
13
|
-
filter(it => it
|
|
14
|
-
map(it => it as Readonly<Position>)
|
|
15
|
+
filter(it => it.type === Position.type),
|
|
16
|
+
map(it => it as Readonly<Position>),
|
|
17
|
+
filter(it => it.instrument.id === selector.id)
|
|
15
18
|
);
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
export function positions(selector: InstrumentSelector, state: State) {
|
|
19
22
|
const balance = state.balance.get(selector.quote.id);
|
|
20
23
|
if (!balance) {
|
|
21
|
-
throw
|
|
24
|
+
throw new InvalidInstrumentSelectorError(selector.id);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
const getter = () =>
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Commission } from './commission';
|
|
4
|
-
import { Instrument } from './instrument';
|
|
5
|
-
import { Position } from './position';
|
|
1
|
+
import { Asset, Commission, Instrument, Position } from '@lib/domain';
|
|
2
|
+
import { d } from '@lib/shared';
|
|
6
3
|
|
|
7
|
-
describe(
|
|
4
|
+
describe(Position.name, () => {
|
|
8
5
|
const instrument = new Instrument(
|
|
9
6
|
0,
|
|
10
7
|
new Asset('abc', 'xyz', 4),
|
package/src/domain/position.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { Instrument } from '
|
|
2
|
-
import { decimal, pnl } from '
|
|
3
|
-
import { Component } from './component';
|
|
1
|
+
import { Component, Instrument } from '@lib/domain';
|
|
2
|
+
import { decimal, hash, pnl } from '@lib/shared';
|
|
4
3
|
|
|
5
4
|
export type PositionMode = 'CROSS' | 'ISOLATED';
|
|
6
5
|
|
|
7
6
|
export class Position implements Component {
|
|
7
|
+
static type = hash(Position.name);
|
|
8
|
+
readonly type = Position.type;
|
|
9
|
+
|
|
8
10
|
estimatedUnrealizedPnL?: decimal;
|
|
9
11
|
|
|
10
12
|
get margin(): decimal {
|
|
@@ -6,30 +6,30 @@ import {
|
|
|
6
6
|
createBacktesterAdapterFactory,
|
|
7
7
|
createPaperAdapterFactory,
|
|
8
8
|
DefaultTimeProvider
|
|
9
|
-
} from '
|
|
10
|
-
import {
|
|
9
|
+
} from '@lib/adapter';
|
|
10
|
+
import { AssetSelector, Session } from '@lib/domain';
|
|
11
|
+
import { decimal, now } from '@lib/shared';
|
|
11
12
|
import {
|
|
12
13
|
Cache,
|
|
13
14
|
Feed,
|
|
14
15
|
inMemoryStorageFactory,
|
|
15
16
|
Measurement,
|
|
16
17
|
StorageFactory
|
|
17
|
-
} from '
|
|
18
|
-
import { Store } from '
|
|
19
|
-
import { AssetSelector } from './asset';
|
|
20
|
-
import { Session } from './session';
|
|
18
|
+
} from '@lib/storage';
|
|
19
|
+
import { Store } from '@lib/store';
|
|
21
20
|
|
|
22
21
|
export type SessionFeature = (builder: SessionBuilder) => void;
|
|
23
22
|
|
|
24
|
-
export function
|
|
23
|
+
export function simulate({
|
|
24
|
+
period,
|
|
25
|
+
balance
|
|
26
|
+
}: {
|
|
27
|
+
period: { from: Date; to?: Date };
|
|
28
|
+
balance: [AssetSelector, decimal][];
|
|
29
|
+
}): SessionFeature {
|
|
25
30
|
return (builder: SessionBuilder) => {
|
|
26
|
-
builder.
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function period(from: Date, to?: Date): SessionFeature {
|
|
31
|
-
return (builder: SessionBuilder) => {
|
|
32
|
-
builder.usePeriod(from.getTime(), to?.getTime() ?? now());
|
|
31
|
+
builder.usePeriod(period.from.getTime(), period.to?.getTime() ?? now());
|
|
32
|
+
balance.forEach(([selector, amount]) => builder.useBalance(selector, amount));
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Asset, Commission, SessionBuilder } from '
|
|
2
|
-
import { d, now } from '
|
|
3
|
-
import { InstrumentPatchEvent } from '
|
|
1
|
+
import { Asset, Commission, Session, SessionBuilder } from '@lib/domain';
|
|
2
|
+
import { d, now } from '@lib/shared';
|
|
3
|
+
import { InstrumentPatchEvent } from '@lib/store';
|
|
4
4
|
|
|
5
|
-
describe(
|
|
5
|
+
describe(Session.name, () => {
|
|
6
6
|
test('should trigger once', done => {
|
|
7
7
|
const session = new SessionBuilder().paper();
|
|
8
8
|
|
package/src/domain/session.ts
CHANGED
|
@@ -16,28 +16,31 @@ import {
|
|
|
16
16
|
} from 'rxjs';
|
|
17
17
|
import { v4 } from 'uuid';
|
|
18
18
|
|
|
19
|
-
import { AdapterAggregate } from '
|
|
19
|
+
import { AdapterAggregate } from '@lib/adapter';
|
|
20
20
|
import {
|
|
21
21
|
AssetSelector,
|
|
22
22
|
Balance,
|
|
23
|
+
balance,
|
|
23
24
|
Instrument,
|
|
25
|
+
instrument,
|
|
26
|
+
instruments,
|
|
24
27
|
InstrumentSelector,
|
|
25
|
-
|
|
28
|
+
InvalidInstrumentSelectorError,
|
|
26
29
|
Ohlc,
|
|
27
30
|
Order,
|
|
31
|
+
order,
|
|
28
32
|
Orderbook,
|
|
33
|
+
orderbook,
|
|
34
|
+
orders,
|
|
29
35
|
Position,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import { orderbook } from './orderbook-operator';
|
|
39
|
-
import { position, positions } from './position-operator';
|
|
40
|
-
import { trade } from './trade-operator';
|
|
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';
|
|
41
44
|
|
|
42
45
|
type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
43
46
|
|
|
@@ -96,7 +99,7 @@ export class Session {
|
|
|
96
99
|
}): Observable<Readonly<Order>> {
|
|
97
100
|
const instrument = this.store.snapshot.universe.instrument.get(order.instrument.id);
|
|
98
101
|
if (!instrument) {
|
|
99
|
-
throw
|
|
102
|
+
throw new InvalidInstrumentSelectorError(order.instrument.id);
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
const newOrder = new Order(
|
|
@@ -206,7 +209,9 @@ export class Session {
|
|
|
206
209
|
): Observable<Readonly<Ohlc>> {
|
|
207
210
|
return this.store.changes$.pipe(
|
|
208
211
|
startWith(this.store.snapshot.universe.instrument.get(selector.id)),
|
|
209
|
-
filter(it => it
|
|
212
|
+
filter(it => it !== undefined && it.type === Instrument.type),
|
|
213
|
+
map(it => it as Instrument),
|
|
214
|
+
filter(it => it.id === selector.id),
|
|
210
215
|
switchMap(() => from(this.aggregate.history(selector, timeframe, length))),
|
|
211
216
|
take(1),
|
|
212
217
|
shareReplay(),
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { Subject } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { Commission } from './commission';
|
|
7
|
-
import { Component } from './component';
|
|
8
|
-
import { Instrument } from './instrument';
|
|
9
|
-
import { Trade } from './trade';
|
|
10
|
-
import { trade } from './trade-operator';
|
|
3
|
+
import { Asset, Commission, Component, Instrument, Trade, trade } from '@lib/domain';
|
|
4
|
+
import { d } from '@lib/shared';
|
|
5
|
+
import { State } from '@lib/store';
|
|
11
6
|
|
|
12
|
-
describe(
|
|
7
|
+
describe(trade.name, () => {
|
|
13
8
|
const instrument = new Instrument(
|
|
14
9
|
0,
|
|
15
10
|
new Asset('abc', 'xyz', 4),
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { filter, map, Observable, startWith } from 'rxjs';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { InstrumentSelector } from './instrument';
|
|
6
|
-
import { Trade } from './trade';
|
|
3
|
+
import { Component, InstrumentSelector, Trade } from '@lib/domain';
|
|
4
|
+
import { State } from '@lib/store';
|
|
7
5
|
|
|
8
6
|
export function trade(selector: InstrumentSelector, state: State) {
|
|
9
7
|
return (source$: Observable<Component>) =>
|
|
10
8
|
source$.pipe(
|
|
11
9
|
startWith(state.trade.get(selector.id)),
|
|
12
|
-
filter(it => it
|
|
13
|
-
map(it => it as Trade)
|
|
10
|
+
filter(it => it !== undefined && it.type === Trade.type),
|
|
11
|
+
map(it => it as Trade),
|
|
12
|
+
filter(it => it.instrument.id === selector.id)
|
|
14
13
|
);
|
|
15
14
|
}
|
package/src/domain/trade.spec.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Commission } from './commission';
|
|
4
|
-
import { Instrument } from './instrument';
|
|
5
|
-
import { Trade } from './trade';
|
|
1
|
+
import { Asset, Commission, Instrument, Trade } from '@lib/domain';
|
|
2
|
+
import { d } from '@lib/shared';
|
|
6
3
|
|
|
7
|
-
describe(
|
|
4
|
+
describe(Trade.name, () => {
|
|
8
5
|
const instrument = new Instrument(
|
|
9
6
|
0,
|
|
10
7
|
new Asset('abc', 'xyz', 4),
|
package/src/domain/trade.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Component } from './component';
|
|
1
|
+
import { Component, Instrument } from '@lib/domain';
|
|
2
|
+
import { decimal, hash } from '@lib/shared';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Simple trade or ticker executed on the market, it's a match of buyer
|
|
7
6
|
* and seller of the same asset.
|
|
8
7
|
*/
|
|
9
8
|
export class Trade implements Component {
|
|
9
|
+
static type = hash(Trade.name);
|
|
10
|
+
readonly type = Trade.type;
|
|
11
|
+
|
|
10
12
|
readonly id: string;
|
|
11
13
|
|
|
12
14
|
constructor(
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import { finalize, forkJoin, Observable, of, switchMap } from 'rxjs';
|
|
3
3
|
|
|
4
|
-
import { Session, SessionBuilder, SessionFeature } from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
4
|
+
import { Session, SessionBuilder, SessionFeature } from '@lib/domain';
|
|
5
|
+
export * from '@lib/adapter';
|
|
6
|
+
export * from '@lib/domain';
|
|
7
|
+
export * from '@lib/shared';
|
|
8
|
+
export * from '@lib/storage';
|
|
9
|
+
export * from '@lib/store';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { log } from '@lib/shared';
|
|
12
12
|
|
|
13
13
|
const registry: Record<string, () => Array<SessionFeature>> = {};
|
|
14
14
|
|
|
@@ -22,14 +22,14 @@ export let rule: (name: string | undefined, describe: SessionHook) => void;
|
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
export let
|
|
25
|
+
export let awake: (describe: SessionHook) => void;
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
* @param name
|
|
30
30
|
* @param describe
|
|
31
31
|
*/
|
|
32
|
-
export function
|
|
32
|
+
export function strategy(name: string, describe: () => Array<SessionFeature>) {
|
|
33
33
|
registry[name] = describe;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -45,16 +45,17 @@ export async function spawn(name: string, builder: SessionBuilder) {
|
|
|
45
45
|
throw new Error(`missing strategy: ${name}`);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
const logger = log(name);
|
|
48
49
|
const ruleHooks = new Array<SessionHook>();
|
|
49
|
-
const
|
|
50
|
+
const awakeHooks = new Array<SessionHook>();
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
awake = (describe: SessionHook) => {
|
|
53
|
+
awakeHooks.push(describe);
|
|
53
54
|
};
|
|
54
55
|
|
|
55
56
|
rule = (ruleName: string | undefined, describe: SessionHook) => {
|
|
56
57
|
if (ruleName) {
|
|
57
|
-
|
|
58
|
+
logger.info(`${chalk.italic(ruleName)} rule found`);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
ruleHooks.push(describe);
|
|
@@ -65,7 +66,7 @@ export async function spawn(name: string, builder: SessionBuilder) {
|
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
return (session: Session) => {
|
|
68
|
-
const beforeAll$ =
|
|
69
|
+
const beforeAll$ = awakeHooks.map(it => it(session));
|
|
69
70
|
const rule$ = ruleHooks.map(it => it(session));
|
|
70
71
|
|
|
71
72
|
if (!beforeAll$.length) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Liquidity, LiquidityAskComparer } from '
|
|
2
|
-
import { d, PriorityList } from '
|
|
1
|
+
import { Liquidity, LiquidityAskComparer } from '@lib/domain';
|
|
2
|
+
import { d, PriorityList } from '@lib/shared';
|
|
3
3
|
|
|
4
4
|
describe('PriorityList', () => {
|
|
5
5
|
test('should patch a best bid and ask', () => {
|
package/src/shared/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
1
|
+
export * from '@lib/shared/datetime';
|
|
2
|
+
export * from '@lib/shared/decimals';
|
|
3
|
+
export * from '@lib/shared/environment';
|
|
4
|
+
export * from '@lib/shared/logger';
|
|
5
|
+
export * from '@lib/shared/policy';
|
|
6
|
+
export * from '@lib/shared/collections';
|
|
7
|
+
export * from '@lib/shared/hash';
|
package/src/shared/logger.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
|
|
3
|
-
import { now } from '
|
|
3
|
+
import { now } from '@lib/shared';
|
|
4
4
|
|
|
5
5
|
const colorize = (content: string) => {
|
|
6
6
|
let hash = 0x811c9dc5;
|
|
@@ -16,24 +16,31 @@ const colorize = (content: string) => {
|
|
|
16
16
|
const time = () => chalk.gray(new Date(now()).toISOString());
|
|
17
17
|
|
|
18
18
|
export class Logger {
|
|
19
|
-
|
|
20
|
-
console.info(`${this.prefix(context)}: ${message}`);
|
|
19
|
+
constructor(private readonly context: string) {}
|
|
21
20
|
|
|
22
|
-
public
|
|
23
|
-
|
|
21
|
+
public info = (message: any, ...params: unknown[]) =>
|
|
22
|
+
params?.length
|
|
23
|
+
? console.info(`${this.prefix()}: ${message}`, params)
|
|
24
|
+
: console.info(`${this.prefix()}: ${message}`);
|
|
24
25
|
|
|
25
|
-
public
|
|
26
|
-
|
|
26
|
+
public debug = (message: any, ...params: unknown[]) =>
|
|
27
|
+
params?.length
|
|
28
|
+
? console.debug(`${this.prefix()}: ${message}`, params)
|
|
29
|
+
: console.debug(`${this.prefix()}: ${message}`);
|
|
27
30
|
|
|
28
|
-
public
|
|
29
|
-
|
|
31
|
+
public warn = (message: any, ...params: unknown[]) =>
|
|
32
|
+
params?.length
|
|
33
|
+
? console.warn(`${this.prefix()}: ${message}`, params)
|
|
34
|
+
: console.warn(`${this.prefix()}: ${message}`);
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
public error = (message: any, ...params: unknown[]) =>
|
|
37
|
+
params?.length
|
|
38
|
+
? console.error(`${this.prefix()}: ${message}`, params)
|
|
39
|
+
: console.error(`${this.prefix()}: ${message}`);
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
public prefix = () => `${time()} ${colorize(this.context)}`;
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
export function log(context: string): Logger {
|
|
45
|
+
return new Logger(context);
|
|
39
46
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Cache } from '
|
|
2
|
-
import { InMemoryStorage } from './storage';
|
|
1
|
+
import { Cache, InMemoryStorage } from '@lib/storage';
|
|
3
2
|
|
|
4
|
-
describe(
|
|
3
|
+
describe(Cache.name, () => {
|
|
5
4
|
test('should return cached value', async () => {
|
|
6
5
|
const cache = new Cache(new InMemoryStorage());
|
|
7
6
|
|
package/src/storage/cache.ts
CHANGED
package/src/storage/feed.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InstrumentSelector } from '
|
|
2
|
-
import { d } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { InstrumentSelector } from '@lib/domain';
|
|
2
|
+
import { d } from '@lib/shared';
|
|
3
|
+
import { Storage, StorageDocument, StorageQueryOptions } from '@lib/storage';
|
|
4
|
+
import { OrderbookPatchEvent, TradePatchEvent } from '@lib/store';
|
|
5
5
|
|
|
6
6
|
export type StorageEvent = TradePatchEvent | OrderbookPatchEvent;
|
|
7
7
|
|
package/src/storage/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
1
|
+
export * from '@lib/storage/feed';
|
|
2
|
+
export * from '@lib/storage/measurement';
|
|
3
|
+
export * from '@lib/storage/storage';
|
|
4
|
+
export * from '@lib/storage/cache';
|