From 21af6ecfe8215a5254826a92d8e9360befd077c7 Mon Sep 17 00:00:00 2001 From: Muhammad Junaid Zubair Malik Date: Fri, 8 Dec 2023 10:56:49 +0800 Subject: [PATCH] #483 small code clean-up and bug fix in vuu-data-test - also reverts the addition of prices column in simul instruments table in the previous commit. --- .../simul/reference-data/instrument-prices.ts | 10 +-- .../src/simul/reference-data/instruments.ts | 21 ++--- .../src/simul/reference-data/prices.ts | 80 ++++++++----------- .../vuu-data-test/src/simul/simul-schemas.ts | 1 - 4 files changed, 50 insertions(+), 62 deletions(-) diff --git a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instrument-prices.ts b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instrument-prices.ts index 963761644..0ef1fbd56 100644 --- a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instrument-prices.ts +++ b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instrument-prices.ts @@ -1,5 +1,5 @@ -import InstrumentReferenceData from "./instruments"; -import PriceReferenceData from "./prices"; +import { instrumentsData } from "./instruments"; +import { pricesData } from "./prices"; export type ask = number; export type askSize = number; @@ -61,11 +61,11 @@ const instrumentPrices: InstrumentPricesDataRow[] = []; // const start = performance.now(); // Create 100_000 Instruments -for (let i = 0; i < InstrumentReferenceData.length; i++) { +for (let i = 0; i < instrumentsData.length; i++) { // prettier-ignore - const [bbg,currency,description,exchange,isin,lotSize,ric] = InstrumentReferenceData[i]; + const [bbg,currency,description,exchange,isin,lotSize,ric] = instrumentsData[i]; const [ask, askSize, bid, bidSize, close, last, open, phase, , scenario] = - PriceReferenceData[i]; + pricesData[i]; instrumentPrices.push([ ask, diff --git a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instruments.ts b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instruments.ts index 05e4f97f4..9beb7eeec 100644 --- a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instruments.ts +++ b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/instruments.ts @@ -24,9 +24,9 @@ export type InstrumentsDataRow = [ string, number, ric, - price, supported, - wishlist + wishlist, + price ]; export const InstrumentColumnMap = { @@ -37,12 +37,12 @@ export const InstrumentColumnMap = { string: 4, number: 5, ric: 6, - price: 7, - supported: 8, - wishlist: 9, -}; + supported: 7, + wishlist: 8, + price: 9, +} as const; -const instruments: InstrumentsDataRow[] = []; +const instrumentsData: InstrumentsDataRow[] = []; const chars = Array.from("ABCEFGHKMNOPQRTUVWYZ"); @@ -73,7 +73,7 @@ for (const char of chars) { const supported = random(0, 1) === 1; const wishlist = random(0, 1) === 1; - instruments.push([ + instrumentsData.push([ bbg, currency, description, @@ -81,9 +81,9 @@ for (const char of chars) { String(isin), lotSize, ric, - price, supported, wishlist, + price, ]); } } @@ -92,8 +92,9 @@ for (const char of chars) { const instrumentsTable = new Table( schemas.instruments, - instruments, + instrumentsData, buildDataColumnMap(schemas.instruments) ); +export { instrumentsData }; export default instrumentsTable; diff --git a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/prices.ts b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/prices.ts index e367fb814..12ee91124 100644 --- a/vuu-ui/packages/vuu-data-test/src/simul/reference-data/prices.ts +++ b/vuu-ui/packages/vuu-data-test/src/simul/reference-data/prices.ts @@ -1,7 +1,7 @@ import { buildDataColumnMap, Table } from "../../Table"; import { BaseUpdateGenerator } from "../../UpdateGenerator"; import { schemas } from "../simul-schemas"; -import instrumentTable, { InstrumentsDataRow } from "./instruments"; +import { instrumentsData, InstrumentColumnMap } from "./instruments"; import { random } from "../../data-utils"; import basketConstituentData from "../../basket/reference-data/constituents"; @@ -37,15 +37,14 @@ const pricesUpdateGenerator = new BaseUpdateGenerator({ askSize, }); -const prices: PricesDataRow[] = []; - // const start = performance.now(); // Create 100_000 Instruments - -// prettier-ignore -for (const [,,,,,,ric, - priceSeed, -] of instrumentTable.data as InstrumentsDataRow[]) { +const requiredInstrumentFields = ["ric", "price"] as const; +const pricesData: Array = instrumentsData.map((instrument) => { + const { ric, price: priceSeed } = requiredInstrumentFields.reduce( + (obj, f) => ({ ...obj, [f]: instrument[InstrumentColumnMap[f]] }), + {} as { ric: string; price: number } + ); const spread = random(0, 10); const ask = priceSeed + spread / 2; @@ -57,47 +56,35 @@ for (const [,,,,,,ric, const open = priceSeed + random(0, 1) / 10; const phase = "C"; const scenario = "close"; - prices.push([ - ask, - askSize, - bid, - bidSize, - close, - last, - open, - phase, - ric, - scenario, - ]); -} + return [ask, askSize, bid, bidSize, close, last, open, phase, ric, scenario]; +}); // prettier-ignore for (const [,,,lastTrade,ric] of basketConstituentData) { const priceSeed = parseFloat(String(lastTrade)); - if (!isNaN(priceSeed)){ - const spread = random(0, 10); - const ask = priceSeed + spread / 2; - const askSize = random(1000, 3000); - const bid = priceSeed - spread / 2; - const bidSize = random(1000, 3000); - const close = priceSeed + random(0, 1) / 10; - const last = priceSeed + random(0, 1) / 10; - const open = priceSeed + random(0, 1) / 10; - const phase = "C"; - const scenario = "close"; - prices.push([ - ask, - askSize, - bid, - bidSize, - close, - last, - open, - phase, - ric, - scenario, - ]); - + if (!isNaN(priceSeed)) { + const spread = random(0, 10); + const ask = priceSeed + spread / 2; + const askSize = random(1000, 3000); + const bid = priceSeed - spread / 2; + const bidSize = random(1000, 3000); + const close = priceSeed + random(0, 1) / 10; + const last = priceSeed + random(0, 1) / 10; + const open = priceSeed + random(0, 1) / 10; + const phase = "C"; + const scenario = "close"; + pricesData.push([ + ask, + askSize, + bid, + bidSize, + close, + last, + open, + phase, + ric as string, + scenario, + ]); } } @@ -106,9 +93,10 @@ for (const [,,,lastTrade,ric] of basketConstituentData) { const pricesTable = new Table( schemas.prices, - prices, + pricesData, buildDataColumnMap(schemas.prices), pricesUpdateGenerator ); +export { pricesData }; export default pricesTable; diff --git a/vuu-ui/packages/vuu-data-test/src/simul/simul-schemas.ts b/vuu-ui/packages/vuu-data-test/src/simul/simul-schemas.ts index 8ffcebd63..3f429cbef 100644 --- a/vuu-ui/packages/vuu-data-test/src/simul/simul-schemas.ts +++ b/vuu-ui/packages/vuu-data-test/src/simul/simul-schemas.ts @@ -22,7 +22,6 @@ export const schemas: Readonly>> = { name: "isin", serverDataType: "string" }, { name: "lotSize", serverDataType: "int" }, { name: "ric", serverDataType: "string" }, - { name: "price", serverDataType: "double" }, { name: "supported", serverDataType: "boolean" }, { name: "wishlist", serverDataType: "boolean" }, ],