@quantform/core 0.3.230 → 0.3.231
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.js.map +1 -1
- package/dist/bin.d.ts +0 -33
- package/dist/bin.js +1 -188
- package/dist/bin.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/ipc.d.ts +34 -0
- package/dist/ipc.js +193 -0
- package/dist/ipc.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapter/adapter.ts +10 -0
- package/src/bin.ts +22 -189
- package/src/index.ts +1 -0
- package/src/ipc.ts +277 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":";;;AAAA,sCAA2C;AAG3C,2CAAwC;
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/adapter/adapter.ts"],"names":[],"mappings":";;;AAAA,sCAA2C;AAG3C,2CAAwC;AAMxC,MAAa,cAAc;IAQzB,YAA6B,OAAgB,EAAW,KAAY;QAAvC,YAAO,GAAP,OAAO,CAAS;QAAW,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAJxE,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;IAClC,CAAC;CAGF;AATD,wCASC;AAMD,MAAsB,OAAQ,SAAQ,aAAuC;IAI3E,SAAS;QACP,OAAO,IAAA,YAAG,GAAE,CAAC;IACf,CAAC;CACF;AAPD,0BAOC"}
|
package/dist/bin.d.ts
CHANGED
|
@@ -1,39 +1,6 @@
|
|
|
1
1
|
import { BacktesterOptions, BacktesterStreamer } from './adapter/backtester';
|
|
2
2
|
import { PaperOptions } from './adapter/paper';
|
|
3
3
|
import { Session, SessionDescriptor } from './session';
|
|
4
|
-
export interface IpcCommand {
|
|
5
|
-
type: any;
|
|
6
|
-
}
|
|
7
|
-
export declare class IpcPaperModeCommand implements IpcCommand {
|
|
8
|
-
type: string;
|
|
9
|
-
id?: number;
|
|
10
|
-
balance: {
|
|
11
|
-
[key: string]: number;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
export declare class IpcBacktestModeCommand implements IpcCommand {
|
|
15
|
-
type: string;
|
|
16
|
-
from: number;
|
|
17
|
-
to: number;
|
|
18
|
-
balance: {
|
|
19
|
-
[key: string]: number;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export declare class IpcLiveModeCommand implements IpcCommand {
|
|
23
|
-
id?: number;
|
|
24
|
-
type: string;
|
|
25
|
-
}
|
|
26
|
-
export declare class IpcUniverseQuery implements IpcCommand {
|
|
27
|
-
type: string;
|
|
28
|
-
exchange: string;
|
|
29
|
-
}
|
|
30
|
-
export declare class IpcFeedCommand implements IpcCommand {
|
|
31
|
-
type: string;
|
|
32
|
-
instrument: string;
|
|
33
|
-
from: number;
|
|
34
|
-
to: number;
|
|
35
|
-
}
|
|
36
|
-
export declare function run(descriptor: SessionDescriptor, ...commands: IpcCommand[]): Promise<Session>;
|
|
37
4
|
export declare function backtest(descriptor: SessionDescriptor, options: BacktesterOptions): [Session, BacktesterStreamer];
|
|
38
5
|
export declare function paper(descriptor: SessionDescriptor, options: PaperOptions): Session;
|
|
39
6
|
export declare function live(descriptor: SessionDescriptor): Session;
|
package/dist/bin.js
CHANGED
|
@@ -1,198 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.idle = exports.live = exports.paper = exports.backtest =
|
|
3
|
+
exports.idle = exports.live = exports.paper = exports.backtest = void 0;
|
|
13
4
|
const backtester_1 = require("./adapter/backtester");
|
|
14
5
|
const adapter_1 = require("./adapter");
|
|
15
6
|
const paper_1 = require("./adapter/paper");
|
|
16
7
|
const session_1 = require("./session");
|
|
17
8
|
const store_1 = require("./store");
|
|
18
|
-
const domain_1 = require("./domain");
|
|
19
|
-
const topic_1 = require("./shared/topic");
|
|
20
|
-
const minimist = require("minimist");
|
|
21
|
-
const shared_1 = require("./shared");
|
|
22
|
-
let IpcPaperModeCommand = class IpcPaperModeCommand {
|
|
23
|
-
constructor() {
|
|
24
|
-
this.type = 'paper';
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
IpcPaperModeCommand = __decorate([
|
|
28
|
-
topic_1.event
|
|
29
|
-
], IpcPaperModeCommand);
|
|
30
|
-
exports.IpcPaperModeCommand = IpcPaperModeCommand;
|
|
31
|
-
let IpcBacktestModeCommand = class IpcBacktestModeCommand {
|
|
32
|
-
constructor() {
|
|
33
|
-
this.type = 'backtest';
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
IpcBacktestModeCommand = __decorate([
|
|
37
|
-
topic_1.event
|
|
38
|
-
], IpcBacktestModeCommand);
|
|
39
|
-
exports.IpcBacktestModeCommand = IpcBacktestModeCommand;
|
|
40
|
-
let IpcLiveModeCommand = class IpcLiveModeCommand {
|
|
41
|
-
constructor() {
|
|
42
|
-
this.type = 'live';
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
IpcLiveModeCommand = __decorate([
|
|
46
|
-
topic_1.event
|
|
47
|
-
], IpcLiveModeCommand);
|
|
48
|
-
exports.IpcLiveModeCommand = IpcLiveModeCommand;
|
|
49
|
-
let IpcUniverseQuery = class IpcUniverseQuery {
|
|
50
|
-
constructor() {
|
|
51
|
-
this.type = 'universe';
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
IpcUniverseQuery = __decorate([
|
|
55
|
-
topic_1.event
|
|
56
|
-
], IpcUniverseQuery);
|
|
57
|
-
exports.IpcUniverseQuery = IpcUniverseQuery;
|
|
58
|
-
let IpcFeedCommand = class IpcFeedCommand {
|
|
59
|
-
constructor() {
|
|
60
|
-
this.type = 'feed';
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
IpcFeedCommand = __decorate([
|
|
64
|
-
topic_1.event
|
|
65
|
-
], IpcFeedCommand);
|
|
66
|
-
exports.IpcFeedCommand = IpcFeedCommand;
|
|
67
|
-
class ExecutionAccessor {
|
|
68
|
-
}
|
|
69
|
-
class ExecutionHandler extends topic_1.Topic {
|
|
70
|
-
constructor(descriptor) {
|
|
71
|
-
super();
|
|
72
|
-
this.descriptor = descriptor;
|
|
73
|
-
}
|
|
74
|
-
async onLiveMode(command, accessor) {
|
|
75
|
-
if (command.id) {
|
|
76
|
-
this.descriptor.id = command.id;
|
|
77
|
-
}
|
|
78
|
-
accessor.session = live(this.descriptor);
|
|
79
|
-
await accessor.session.awake();
|
|
80
|
-
}
|
|
81
|
-
async onPaperMode(command, accessor) {
|
|
82
|
-
if (command.id) {
|
|
83
|
-
this.descriptor.id = command.id;
|
|
84
|
-
}
|
|
85
|
-
accessor.session = paper(this.descriptor, {
|
|
86
|
-
balance: command.balance
|
|
87
|
-
});
|
|
88
|
-
await accessor.session.awake();
|
|
89
|
-
}
|
|
90
|
-
onBacktestMode(command, accessor) {
|
|
91
|
-
return new Promise(async (resolve) => {
|
|
92
|
-
const [session, streamer] = backtest(this.descriptor, {
|
|
93
|
-
from: command.from,
|
|
94
|
-
to: command.to,
|
|
95
|
-
balance: command.balance,
|
|
96
|
-
progress: timestamp => this.notify({
|
|
97
|
-
type: 'backtest:updated',
|
|
98
|
-
timestamp,
|
|
99
|
-
from: command.from,
|
|
100
|
-
to: command.to
|
|
101
|
-
}),
|
|
102
|
-
completed: async () => {
|
|
103
|
-
const statement = {};
|
|
104
|
-
await accessor.session.dispose();
|
|
105
|
-
this.notify({ type: 'backtest:completed', statement });
|
|
106
|
-
resolve();
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
accessor.session = session;
|
|
110
|
-
this.notify({ type: 'backtest:started' });
|
|
111
|
-
await accessor.session.awake();
|
|
112
|
-
await streamer.tryContinue().catch(it => shared_1.Logger.error(it));
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
onUniverse(query, accessor) {
|
|
116
|
-
var _a;
|
|
117
|
-
accessor.session = (_a = accessor.session) !== null && _a !== void 0 ? _a : idle(this.descriptor);
|
|
118
|
-
}
|
|
119
|
-
async onFeed(command, accessor) {
|
|
120
|
-
var _a;
|
|
121
|
-
accessor.session = (_a = accessor.session) !== null && _a !== void 0 ? _a : idle(this.descriptor);
|
|
122
|
-
const instrument = (0, domain_1.instrumentOf)(command.instrument);
|
|
123
|
-
await accessor.session.awake();
|
|
124
|
-
this.notify({ type: 'feed:started' });
|
|
125
|
-
await accessor.session.aggregate.dispatch(instrument.base.exchange, new adapter_1.AdapterFeedCommand(instrument, command.from, command.to, this.descriptor.feed, timestamp => this.notify({
|
|
126
|
-
type: 'feed:updated',
|
|
127
|
-
timestamp,
|
|
128
|
-
from: command.from,
|
|
129
|
-
to: command.to
|
|
130
|
-
})));
|
|
131
|
-
this.notify({ type: 'feed:completed' });
|
|
132
|
-
await accessor.session.dispose();
|
|
133
|
-
}
|
|
134
|
-
notify(message) {
|
|
135
|
-
if (!process.send) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
process.send(message);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
__decorate([
|
|
142
|
-
(0, topic_1.handler)(IpcLiveModeCommand),
|
|
143
|
-
__metadata("design:type", Function),
|
|
144
|
-
__metadata("design:paramtypes", [IpcLiveModeCommand, ExecutionAccessor]),
|
|
145
|
-
__metadata("design:returntype", Promise)
|
|
146
|
-
], ExecutionHandler.prototype, "onLiveMode", null);
|
|
147
|
-
__decorate([
|
|
148
|
-
(0, topic_1.handler)(IpcPaperModeCommand),
|
|
149
|
-
__metadata("design:type", Function),
|
|
150
|
-
__metadata("design:paramtypes", [IpcPaperModeCommand, ExecutionAccessor]),
|
|
151
|
-
__metadata("design:returntype", Promise)
|
|
152
|
-
], ExecutionHandler.prototype, "onPaperMode", null);
|
|
153
|
-
__decorate([
|
|
154
|
-
(0, topic_1.handler)(IpcBacktestModeCommand),
|
|
155
|
-
__metadata("design:type", Function),
|
|
156
|
-
__metadata("design:paramtypes", [IpcBacktestModeCommand, ExecutionAccessor]),
|
|
157
|
-
__metadata("design:returntype", void 0)
|
|
158
|
-
], ExecutionHandler.prototype, "onBacktestMode", null);
|
|
159
|
-
__decorate([
|
|
160
|
-
(0, topic_1.handler)(IpcUniverseQuery),
|
|
161
|
-
__metadata("design:type", Function),
|
|
162
|
-
__metadata("design:paramtypes", [IpcUniverseQuery, ExecutionAccessor]),
|
|
163
|
-
__metadata("design:returntype", void 0)
|
|
164
|
-
], ExecutionHandler.prototype, "onUniverse", null);
|
|
165
|
-
__decorate([
|
|
166
|
-
(0, topic_1.handler)(IpcFeedCommand),
|
|
167
|
-
__metadata("design:type", Function),
|
|
168
|
-
__metadata("design:paramtypes", [IpcFeedCommand, ExecutionAccessor]),
|
|
169
|
-
__metadata("design:returntype", Promise)
|
|
170
|
-
], ExecutionHandler.prototype, "onFeed", null);
|
|
171
|
-
async function run(descriptor, ...commands) {
|
|
172
|
-
const handler = new ExecutionHandler(descriptor);
|
|
173
|
-
const accessor = new ExecutionAccessor();
|
|
174
|
-
const argv = minimist(process.argv.slice(2));
|
|
175
|
-
if (argv.command) {
|
|
176
|
-
const json = Buffer.from(argv.command, 'base64').toString('utf-8');
|
|
177
|
-
commands.push(JSON.parse(json));
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
if (!commands.length) {
|
|
181
|
-
commands.push(new IpcPaperModeCommand());
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
for (const command of commands) {
|
|
185
|
-
await handler.dispatch(command, accessor);
|
|
186
|
-
}
|
|
187
|
-
process.on('message', async (request) => {
|
|
188
|
-
const response = await handler.dispatch(request, accessor);
|
|
189
|
-
if (response) {
|
|
190
|
-
process.send(response);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
return accessor.session;
|
|
194
|
-
}
|
|
195
|
-
exports.run = run;
|
|
196
9
|
function backtest(descriptor, options) {
|
|
197
10
|
const store = new store_1.Store();
|
|
198
11
|
const streamer = new backtester_1.BacktesterStreamer(store, descriptor.feed, options);
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;;AAAA,qDAI8B;AAC9B,uCAA6C;AAC7C,2CAA6D;AAC7D,uCAAuD;AACvD,mCAAgC;AAQhC,SAAgB,QAAQ,CACtB,UAA6B,EAC7B,OAA0B;IAE1B,MAAM,KAAK,GAAG,IAAI,aAAK,EAAE,CAAC;IAE1B,MAAM,QAAQ,GAAG,IAAI,+BAAkB,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,SAAS,GAAG,IAAI,0BAAgB,CACpC,KAAK,EACL,UAAU,CAAC,OAAO,CAAC,GAAG,CACpB,EAAE,CAAC,EAAE,CAAC,IAAI,oBAAY,CAAC,IAAI,8BAAiB,CAAC,EAAE,E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names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,uDAAqC;AACrC,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB;AACxB,gDAA8B;AAC9B,wCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAC1B,uDAAqC;AACrC,kDAAgC;AAChC,8CAA4B;AAC5B,4CAA0B;AAC1B,4CAA0B;AAC1B,0CAAwB;AACxB,gDAA8B;AAC9B,wCAAsB;AACtB,wCAAsB"}
|
package/dist/ipc.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Session, SessionDescriptor } from './session';
|
|
2
|
+
export interface IpcCommand {
|
|
3
|
+
type: any;
|
|
4
|
+
}
|
|
5
|
+
export declare class IpcLiveCommand implements IpcCommand {
|
|
6
|
+
type: string;
|
|
7
|
+
id?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class IpcPaperCommand implements IpcCommand {
|
|
10
|
+
type: string;
|
|
11
|
+
id?: number;
|
|
12
|
+
balance: {
|
|
13
|
+
[key: string]: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare class IpcBacktestCommand implements IpcCommand {
|
|
17
|
+
type: string;
|
|
18
|
+
from: number;
|
|
19
|
+
to: number;
|
|
20
|
+
balance: {
|
|
21
|
+
[key: string]: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare class IpcUniverseQuery implements IpcCommand {
|
|
25
|
+
type: string;
|
|
26
|
+
exchange: string;
|
|
27
|
+
}
|
|
28
|
+
export declare class IpcFeedCommand implements IpcCommand {
|
|
29
|
+
type: string;
|
|
30
|
+
instrument: string;
|
|
31
|
+
from: number;
|
|
32
|
+
to: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function run(descriptor: SessionDescriptor, ...commands: IpcCommand[]): Promise<Session>;
|
package/dist/ipc.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.run = exports.IpcFeedCommand = exports.IpcUniverseQuery = exports.IpcBacktestCommand = exports.IpcPaperCommand = exports.IpcLiveCommand = void 0;
|
|
13
|
+
const adapter_1 = require("./adapter");
|
|
14
|
+
const domain_1 = require("./domain");
|
|
15
|
+
const topic_1 = require("./shared/topic");
|
|
16
|
+
const shared_1 = require("./shared");
|
|
17
|
+
const bin_1 = require("./bin");
|
|
18
|
+
const minimist = require("minimist");
|
|
19
|
+
let IpcLiveCommand = class IpcLiveCommand {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.type = 'live';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
IpcLiveCommand = __decorate([
|
|
25
|
+
topic_1.event
|
|
26
|
+
], IpcLiveCommand);
|
|
27
|
+
exports.IpcLiveCommand = IpcLiveCommand;
|
|
28
|
+
let IpcPaperCommand = class IpcPaperCommand {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.type = 'paper';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
IpcPaperCommand = __decorate([
|
|
34
|
+
topic_1.event
|
|
35
|
+
], IpcPaperCommand);
|
|
36
|
+
exports.IpcPaperCommand = IpcPaperCommand;
|
|
37
|
+
let IpcBacktestCommand = class IpcBacktestCommand {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.type = 'backtest';
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
IpcBacktestCommand = __decorate([
|
|
43
|
+
topic_1.event
|
|
44
|
+
], IpcBacktestCommand);
|
|
45
|
+
exports.IpcBacktestCommand = IpcBacktestCommand;
|
|
46
|
+
let IpcUniverseQuery = class IpcUniverseQuery {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.type = 'universe';
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
IpcUniverseQuery = __decorate([
|
|
52
|
+
topic_1.event
|
|
53
|
+
], IpcUniverseQuery);
|
|
54
|
+
exports.IpcUniverseQuery = IpcUniverseQuery;
|
|
55
|
+
let IpcFeedCommand = class IpcFeedCommand {
|
|
56
|
+
constructor() {
|
|
57
|
+
this.type = 'feed';
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
IpcFeedCommand = __decorate([
|
|
61
|
+
topic_1.event
|
|
62
|
+
], IpcFeedCommand);
|
|
63
|
+
exports.IpcFeedCommand = IpcFeedCommand;
|
|
64
|
+
class IpcSessionAccessor {
|
|
65
|
+
}
|
|
66
|
+
class IpcHandler extends topic_1.Topic {
|
|
67
|
+
constructor(descriptor) {
|
|
68
|
+
super();
|
|
69
|
+
this.descriptor = descriptor;
|
|
70
|
+
}
|
|
71
|
+
async onLiveMode(command, accessor) {
|
|
72
|
+
if (command.id) {
|
|
73
|
+
this.descriptor.id = command.id;
|
|
74
|
+
}
|
|
75
|
+
accessor.session = (0, bin_1.live)(this.descriptor);
|
|
76
|
+
await accessor.session.awake();
|
|
77
|
+
}
|
|
78
|
+
async onPaperMode(command, accessor) {
|
|
79
|
+
if (command.id) {
|
|
80
|
+
this.descriptor.id = command.id;
|
|
81
|
+
}
|
|
82
|
+
accessor.session = (0, bin_1.paper)(this.descriptor, {
|
|
83
|
+
balance: command.balance
|
|
84
|
+
});
|
|
85
|
+
await accessor.session.awake();
|
|
86
|
+
}
|
|
87
|
+
onBacktestMode(command, accessor) {
|
|
88
|
+
return new Promise(async (resolve) => {
|
|
89
|
+
const [session, streamer] = (0, bin_1.backtest)(this.descriptor, {
|
|
90
|
+
from: command.from,
|
|
91
|
+
to: command.to,
|
|
92
|
+
balance: command.balance,
|
|
93
|
+
progress: timestamp => this.notify({
|
|
94
|
+
type: 'backtest:updated',
|
|
95
|
+
timestamp,
|
|
96
|
+
from: command.from,
|
|
97
|
+
to: command.to
|
|
98
|
+
}),
|
|
99
|
+
completed: async () => {
|
|
100
|
+
const statement = {};
|
|
101
|
+
await accessor.session.dispose();
|
|
102
|
+
this.notify({ type: 'backtest:completed', statement });
|
|
103
|
+
resolve();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
accessor.session = session;
|
|
107
|
+
this.notify({ type: 'backtest:started' });
|
|
108
|
+
await accessor.session.awake();
|
|
109
|
+
await streamer.tryContinue().catch(it => shared_1.Logger.error(it));
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
onUniverse(query, accessor) {
|
|
113
|
+
var _a;
|
|
114
|
+
accessor.session = (_a = accessor.session) !== null && _a !== void 0 ? _a : (0, bin_1.idle)(this.descriptor);
|
|
115
|
+
}
|
|
116
|
+
async onFeed(command, accessor) {
|
|
117
|
+
var _a;
|
|
118
|
+
accessor.session = (_a = accessor.session) !== null && _a !== void 0 ? _a : (0, bin_1.idle)(this.descriptor);
|
|
119
|
+
const instrument = (0, domain_1.instrumentOf)(command.instrument);
|
|
120
|
+
await accessor.session.awake();
|
|
121
|
+
this.notify({ type: 'feed:started' });
|
|
122
|
+
await accessor.session.aggregate.dispatch(instrument.base.exchange, new adapter_1.AdapterFeedCommand(instrument, command.from, command.to, this.descriptor.feed, timestamp => this.notify({
|
|
123
|
+
type: 'feed:updated',
|
|
124
|
+
timestamp,
|
|
125
|
+
from: command.from,
|
|
126
|
+
to: command.to
|
|
127
|
+
})));
|
|
128
|
+
this.notify({ type: 'feed:completed' });
|
|
129
|
+
await accessor.session.dispose();
|
|
130
|
+
}
|
|
131
|
+
notify(message) {
|
|
132
|
+
if (!process.send) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
process.send(message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
__decorate([
|
|
139
|
+
(0, topic_1.handler)(IpcLiveCommand),
|
|
140
|
+
__metadata("design:type", Function),
|
|
141
|
+
__metadata("design:paramtypes", [IpcLiveCommand, IpcSessionAccessor]),
|
|
142
|
+
__metadata("design:returntype", Promise)
|
|
143
|
+
], IpcHandler.prototype, "onLiveMode", null);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, topic_1.handler)(IpcPaperCommand),
|
|
146
|
+
__metadata("design:type", Function),
|
|
147
|
+
__metadata("design:paramtypes", [IpcPaperCommand, IpcSessionAccessor]),
|
|
148
|
+
__metadata("design:returntype", Promise)
|
|
149
|
+
], IpcHandler.prototype, "onPaperMode", null);
|
|
150
|
+
__decorate([
|
|
151
|
+
(0, topic_1.handler)(IpcBacktestCommand),
|
|
152
|
+
__metadata("design:type", Function),
|
|
153
|
+
__metadata("design:paramtypes", [IpcBacktestCommand, IpcSessionAccessor]),
|
|
154
|
+
__metadata("design:returntype", void 0)
|
|
155
|
+
], IpcHandler.prototype, "onBacktestMode", null);
|
|
156
|
+
__decorate([
|
|
157
|
+
(0, topic_1.handler)(IpcUniverseQuery),
|
|
158
|
+
__metadata("design:type", Function),
|
|
159
|
+
__metadata("design:paramtypes", [IpcUniverseQuery, IpcSessionAccessor]),
|
|
160
|
+
__metadata("design:returntype", void 0)
|
|
161
|
+
], IpcHandler.prototype, "onUniverse", null);
|
|
162
|
+
__decorate([
|
|
163
|
+
(0, topic_1.handler)(IpcFeedCommand),
|
|
164
|
+
__metadata("design:type", Function),
|
|
165
|
+
__metadata("design:paramtypes", [IpcFeedCommand, IpcSessionAccessor]),
|
|
166
|
+
__metadata("design:returntype", Promise)
|
|
167
|
+
], IpcHandler.prototype, "onFeed", null);
|
|
168
|
+
async function run(descriptor, ...commands) {
|
|
169
|
+
const handler = new IpcHandler(descriptor);
|
|
170
|
+
const accessor = new IpcSessionAccessor();
|
|
171
|
+
const argv = minimist(process.argv.slice(2));
|
|
172
|
+
if (argv.command) {
|
|
173
|
+
const json = Buffer.from(argv.command, 'base64').toString('utf-8');
|
|
174
|
+
commands.push(JSON.parse(json));
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (!commands.length) {
|
|
178
|
+
commands.push(new IpcPaperCommand());
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const command of commands) {
|
|
182
|
+
await handler.dispatch(command, accessor);
|
|
183
|
+
}
|
|
184
|
+
process.on('message', async (request) => {
|
|
185
|
+
const response = await handler.dispatch(request, accessor);
|
|
186
|
+
if (response) {
|
|
187
|
+
process.send(response);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return accessor.session;
|
|
191
|
+
}
|
|
192
|
+
exports.run = run;
|
|
193
|
+
//# sourceMappingURL=ipc.js.map
|
package/dist/ipc.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc.js","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA+C;AAE/C,qCAAwC;AACxC,0CAAuD;AACvD,qCAAkC;AAClC,+BAAoD;AACpD,qCAAsC;AAgBtC,IAAa,cAAc,GAA3B,MAAa,cAAc;IAA3B;QACE,SAAI,GAAG,MAAM,CAAC;IAMhB,CAAC;CAAA,CAAA;AAPY,cAAc;IAD1B,aAAK;GACO,cAAc,CAO1B;AAPY,wCAAc;AAa3B,IAAa,eAAe,GAA5B,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