in web/frontend/src/app/pages/order-book/order-book/order-book.component.ts [286:438]
private runBook({quantityPrecision, pricePrecision, baseCurrency, termCurrency}) {
this.initialized = true;
const emitExchanges = !this.hiddenExchanges?.length;
if (emitExchanges) {
this.exchanges$.next(new Set<string>());
}
this.destroy.next();
this.facade?.destroy();
this.runBook$.next();
const params = {
default: {
resource: {
resources: [
{
name: 'RobotoCondensed_regular',
path: '/Assets/fonts/TTF/RobotoCondensed_regular.ttf',
type: EResourceType.font,
},
{
name: 'RobotoMono_300_10',
path: '/Assets/fonts/Bitmap/RobotoMono_300_10.xml',
type: EResourceType.bitmap,
},
{
name: 'RobotoCondensed_300_10',
path: '/Assets/fonts/Bitmap/RobotoCondensed_300_10.xml',
type: EResourceType.bitmap,
},
{
name: 'RobotoCondensed_300_16',
path: '/Assets/fonts/Bitmap/RobotoCondensed_300_16.xml',
type: EResourceType.bitmap,
},
],
},
},
};
this.dataReady$.next(false);
this.ready$.next(false);
const orderGridKernel = new OrderGridEmbeddableKernel(params);
const feed$: Observable<IL2Package> = this.getFeed(this.symbol, this.streams, this.hiddenExchanges)
.pipe(
tap((message) => {
const data = this.exchanges$.getValue();
message.entries.forEach((entry) => data.add(entry.exchange_id));
if (emitExchanges) {
this.exchanges$.next(data);
}
}),
takeUntil(merge(this.destroy$, this.runBook$)),
shareReplay({bufferSize: 1, refCount: true}),
);
feed$.pipe(take(1), takeUntil(this.destroy)).subscribe(() => {
this.dataReady$.next(true);
});
this.lastMessageTime$ = combineLatest([this.globalFiltersService.getFilters(), feed$]).pipe(
map(([filters, message]) =>
formatHDate(
new Date(message.timestamp).toISOString(),
filters.dateFormat,
filters.timeFormat,
filters.timezone,
),
),
);
const orderBook = new OrderBook(
{
subscribe: (symbol: string, appId: string): Observable<IL2Package> =>
feed$.pipe(takeUntil(this.destroy)),
} as any,
() =>
new Worker(new URL('../../streams/workers/order-book.worker.ts', import.meta.url), {
type: 'module',
}),
);
const kernels: AbstractEmbeddableKernel<unknown>[] = [orderGridKernel];
if (this.inDepthChart) {
kernels.push(new DepthChartEmbeddableKernel(params));
}
kernels.forEach((kernel) =>
kernel.addExtension({
processApp: (containerBuilder: ContainerBuilder, parameters: any) => null,
processGlobal: (containerBuilder: ContainerBuilder) =>
containerBuilder.set('orderBook', orderBook),
getName: () => '',
} as any),
);
this.facade = new MultiAppFacade(
kernels,
this.container.nativeElement,
true,
{},
{
resolveResource: (name: string, path: string) => path.replace('Assets', 'assets'),
},
);
const apps = [
this.facade.createApp('orderGrid', this.bookId, this.bookSizes(), {
showExchangeId: true,
mapExchangeCode: true,
parameters: {},
formatFunctions: {
price: defaultFormatFunction,
spread: defaultFormatFunction,
},
symbol: this.symbol,
quantityPrecision,
pricePrecision,
termCode: termCurrency,
}),
];
if (this.inDepthChart) {
apps.push(
this.facade.createApp('depthChart', this.depthChartId, this.chartSizes(), {
parameters: {
orientation: this.orientation,
},
formatFunctions: {
price: defaultFormatFunction,
spread: defaultFormatFunction,
},
symbol: {
symbol: this.symbol,
base: {
code: baseCurrency,
decimalPart: pricePrecision,
},
term: {
code: termCurrency,
decimalPart: pricePrecision,
},
},
}),
);
}
combineLatest(apps.map((app) => app.pipe(filter((e) => e === 'initialized'))))
.pipe(take(1), takeUntil(this.destroy))
.subscribe(() => {
this.initialized = true;
this.updateSize();
this.cdRef.detectChanges();
this.ready.emit();
this.ready$.next(true);
});
}