@yuants/app-virtual-exchange 0.10.3 → 0.11.1
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/position.js +15 -7
- package/dist/position.js.map +1 -1
- package/dist/quote/__tests__/implementations.test.js +66 -0
- package/dist/quote/__tests__/implementations.test.js.map +1 -1
- package/dist/quote/implementations/v0.js +12 -1
- package/dist/quote/implementations/v0.js.map +1 -1
- package/dist/quote/implementations/v1.js +12 -1
- package/dist/quote/implementations/v1.js.map +1 -1
- package/dist/quote/implementations/v2.js +12 -1
- package/dist/quote/implementations/v2.js.map +1 -1
- package/dist/quote/implementations/v3.js +12 -1
- package/dist/quote/implementations/v3.js.map +1 -1
- package/dist/quote/service.js +1 -1
- package/dist/quote/service.js.map +1 -1
- package/dist/quote/types.js.map +1 -1
- package/lib/position.d.ts.map +1 -1
- package/lib/position.js +15 -7
- package/lib/position.js.map +1 -1
- package/lib/quote/__tests__/implementations.test.js +66 -0
- package/lib/quote/__tests__/implementations.test.js.map +1 -1
- package/lib/quote/implementations/v0.d.ts.map +1 -1
- package/lib/quote/implementations/v0.js +12 -1
- package/lib/quote/implementations/v0.js.map +1 -1
- package/lib/quote/implementations/v1.d.ts.map +1 -1
- package/lib/quote/implementations/v1.js +12 -1
- package/lib/quote/implementations/v1.js.map +1 -1
- package/lib/quote/implementations/v2.d.ts.map +1 -1
- package/lib/quote/implementations/v2.js +12 -1
- package/lib/quote/implementations/v2.js.map +1 -1
- package/lib/quote/implementations/v3.d.ts.map +1 -1
- package/lib/quote/implementations/v3.js +12 -1
- package/lib/quote/implementations/v3.js.map +1 -1
- package/lib/quote/service.js +1 -1
- package/lib/quote/service.js.map +1 -1
- package/lib/quote/types.d.ts +8 -0
- package/lib/quote/types.d.ts.map +1 -1
- package/lib/quote/types.js.map +1 -1
- package/package.json +3 -3
- package/temp/package-deps.json +13 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v3.js","source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AE,SAAS,CAAC,QAAQ;gBAE9C,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAAE,CAAC;gBACrC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;aAC3C;YAED,MAAM,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC;SACpC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,eAAe;IACf,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC;QACtB,YAAY,EAAE,QAAQ,CAAC,MAAM;QAC7B,UAAU,EAAE,UAAU;QACtB,cAAc,EAAE,UAAU,CAAC,MAAM;QACjC,aAAa,EAAE,UAAU,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM;QACrD,WAAW,EAAE,WAAW,CAAC,MAAM;QAC/B,cAAc,EAAE;YACd,IAAI,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC;YACrB,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1E,UAAU,EAAE,QAAQ,CAAC,MAAM,GAAG,EAAE,GAAG,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE,OAAO;SACnE;KACF,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;AACzD,CAAC,CAAC;AAvNW,QAAA,kBAAkB,sBAuN7B","sourcesContent":["import { newError } from '@yuants/utils';\nimport { IQuoteKey, IQuoteState, IQuoteUpdateAction } from '../types';\n\n// TRICK: 固定字段顺序,方便计算偏移量\nconst FIELDS = ((x: { [key in IQuoteKey]: number }) => Object.keys(x).sort() as IQuoteKey[])({\n // TS TRICK: 强制运行时数组具有 IQuoteKey 的所有字段。不重不漏,味道真是好极了\n last_price: 0,\n ask_price: 0,\n ask_volume: 0,\n bid_volume: 0,\n bid_price: 0,\n interest_rate_short: 0,\n open_interest: 0,\n interest_rate_prev_settled_at: 0,\n interest_rate_next_settled_at: 0,\n interest_rate_long: 0,\n});\n\nconst FIELD_COUNT = FIELDS.length;\nconst mapFieldNameToOffset = Object.fromEntries(FIELDS.map((field, index) => [field, index * 2])); // 每个字段占2个位置: [池索引, 时间戳]\n\n/**\n * 使用引用计数字符串池的行情状态管理器 v3\n * 保持 v1 的内存局部性,同时通过字符串池减少内存开销\n * 使用 Float64Array 连续存储 [池索引, 时间戳] 对\n */\nexport const createQuoteStateV3 = (): IQuoteState => {\n // 核心数据存储:连续存储 [池索引, 时间戳, 池索引, 时间戳...]\n let data: Float64Array = new Float64Array(1024 * FIELD_COUNT * 2); // 初始容量:1024产品\n let dataLength = 0; // 当前已分配的数据槽数量(以字段为单位)\n\n // 字符串池\n let stringPool: (string | undefined)[] = []; // 索引 -> 字符串(undefined 表示空闲)\n let refCounts: number[] = []; // 索引 -> 引用计数\n let stringToIndex = new Map<string, number>(); // 字符串 -> 索引\n let freeIndices: number[] = []; // 空闲索引列表\n\n const products: string[] = [];\n const mapProductIdToIndex = new Map<string, number>();\n\n // 确保 data 有足够容量\n const ensureDataCapacity = (requiredFields: number) => {\n if (requiredFields * 2 <= data.length) return;\n\n // 倍增扩容\n const newSize = Math.max(data.length * 2, requiredFields * 2 + 1024);\n const newData = new Float64Array(newSize);\n newData.set(data);\n data = newData;\n };\n\n // 获取字段偏移量(以 Float64 元素为单位)\n const getFieldOffset = (product_id: string, field: string): number => {\n let baseIndex = mapProductIdToIndex.get(product_id);\n if (baseIndex === undefined) {\n baseIndex = mapProductIdToIndex.size;\n products.push(product_id);\n mapProductIdToIndex.set(product_id, baseIndex);\n\n // 确保有足够空间存储该产品的所有字段\n const requiredFields = (baseIndex + 1) * FIELD_COUNT;\n ensureDataCapacity(requiredFields);\n\n // 初始化该产品的所有字段为 [-1, 0](空值)\n const startIdx = baseIndex * FIELD_COUNT * 2;\n for (let i = 0; i < FIELD_COUNT * 2; i += 2) {\n data[startIdx + i] = -1; // 池索引:-1 表示空值\n data[startIdx + i + 1] = 0; // 时间戳:0\n }\n dataLength = Math.max(dataLength, requiredFields);\n }\n const fieldOffset = mapFieldNameToOffset[field];\n if (fieldOffset === undefined) throw newError('INVALID_FIELD_NAME', { field, available_fields: FIELDS });\n return baseIndex * FIELD_COUNT * 2 + fieldOffset;\n };\n\n // 获取或分配字符串索引(增加引用计数)\n const acquireStringIndex = (value: string): number => {\n let index = stringToIndex.get(value);\n if (index !== undefined) {\n // 字符串已存在,增加引用计数\n refCounts[index]++;\n return index;\n }\n\n // 需要新索引\n if (freeIndices.length > 0) {\n // 重用空闲索引\n index = freeIndices.pop()!;\n stringPool[index] = value;\n refCounts[index] = 1;\n } else {\n // 分配新索引\n index = stringPool.length;\n stringPool.push(value);\n refCounts.push(1);\n }\n\n stringToIndex.set(value, index);\n return index;\n };\n\n // 释放字符串索引(减少引用计数)\n const releaseStringIndex = (index: number): void => {\n if (index === -1) return; // 空值索引\n\n refCounts[index]--;\n if (refCounts[index] === 0) {\n // 引用计数归零,可以回收\n const value = stringPool[index]!;\n stringToIndex.delete(value);\n // 清空池中的引用,允许 GC\n stringPool[index] = undefined;\n refCounts[index] = 0;\n freeIndices.push(index);\n }\n };\n\n const getValueTuple = (product_id: string, field: IQuoteKey): [string, number] | undefined => {\n const offset = getFieldOffset(product_id, field);\n const poolIndex = data[offset];\n if (poolIndex === -1) return undefined;\n\n const timestamp = data[offset + 1];\n const value = stringPool[poolIndex]!;\n return [value, timestamp];\n };\n\n const setValueTuple = (product_id: string, field: IQuoteKey, value: string, updated_at: number) => {\n const offset = getFieldOffset(product_id, field);\n const oldPoolIndex = data[offset];\n\n // 释放旧字符串的引用\n releaseStringIndex(oldPoolIndex);\n\n // 获取新字符串索引\n const newPoolIndex = acquireStringIndex(value);\n\n // 更新存储\n data[offset] = newPoolIndex;\n data[offset + 1] = updated_at;\n };\n\n const update = (action: IQuoteUpdateAction) => {\n for (const product_id in action) {\n const fields = action[product_id];\n for (const field_name in fields) {\n const field = field_name as IQuoteKey;\n const [value, updated_at] = fields[field]!;\n const oldTuple = getValueTuple(product_id, field);\n if (oldTuple === undefined || updated_at >= oldTuple[1]) {\n setValueTuple(product_id, field, value, updated_at);\n }\n }\n }\n };\n\n const dumpAsObject = (): IQuoteUpdateAction => {\n const result: IQuoteUpdateAction = {};\n\n // 初始化所有产品的结构\n for (const product_id of products) {\n result[product_id] = {};\n }\n\n // 遍历所有字段(dataLength 是以字段为单位)\n for (let fieldIdx = 0; fieldIdx < dataLength; fieldIdx++) {\n const poolIndex = data[fieldIdx * 2];\n if (poolIndex === -1) continue; // 空值\n\n const timestamp = data[fieldIdx * 2 + 1];\n const productIndex = Math.floor(fieldIdx / FIELD_COUNT);\n const product_id = products[productIndex];\n\n const fieldIndex = fieldIdx % FIELD_COUNT;\n const field_name = FIELDS[fieldIndex];\n\n const value = stringPool[poolIndex]!;\n result[product_id]![field_name] = [value, timestamp];\n }\n\n return result;\n };\n\n /**\n * 过滤状态,返回指定 product_id 列表和字段列表中,且更新时间不早于指定时间的字段数据\n * @param product_ids - 需要过滤的 product_id 列表\n * @param fields - 需要过滤的字段列表\n * @param updated_at - 需要过滤的更新时间阈值 (仅返回更新时间不早于该值的字段)\n * @returns 过滤后的数据\n */\n const filter = (product_ids: string[], fields: IQuoteKey[], updated_at: number): IQuoteUpdateAction => {\n const result: IQuoteUpdateAction = {};\n\n for (const product_id of product_ids) {\n const productIndex = mapProductIdToIndex.get(product_id);\n if (productIndex === undefined) {\n // 产品不存在,创建空对象\n result[product_id] = {};\n continue;\n }\n\n const productResult: Partial<Record<IQuoteKey, [string, number]>> = {};\n const baseOffset = productIndex * FIELD_COUNT * 2;\n\n for (const field of fields) {\n const fieldOffset = mapFieldNameToOffset[field];\n if (fieldOffset === undefined) continue;\n\n const offset = baseOffset + fieldOffset;\n const poolIndex = data[offset];\n if (poolIndex === -1) continue; // 空值\n\n const timestamp = data[offset + 1];\n if (timestamp < updated_at) continue; // 时间戳太旧\n\n const value = stringPool[poolIndex]!;\n productResult[field] = [value, timestamp];\n }\n\n result[product_id] = productResult;\n }\n\n return result;\n };\n\n // 导出内部统计信息用于调试\n const getStats = () => ({\n productCount: products.length,\n fieldCount: dataLength,\n stringPoolSize: stringPool.length,\n activeStrings: stringPool.length - freeIndices.length,\n freeIndices: freeIndices.length,\n memoryEstimate: {\n data: data.length * 8, // Float64Array 每个元素8字节\n pool: stringPool.reduce((sum, str) => sum + (str ? str.length * 2 : 0), 0),\n structures: products.length * 50 + stringPool.length * 16, // 粗略估计\n },\n });\n\n return { update, dumpAsObject, getValueTuple, filter };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"v3.js","sourceRoot":"","sources":["../../../src/quote/implementations/v3.ts"],"names":[],"mappings":";;;AAAA,yCAAyC;AAGzC,wBAAwB;AACxB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAiC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAiB,CAAC,CAAC;IAC3F,mDAAmD;IACnD,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,CAAC;IACZ,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,CAAC;IACb,SAAS,EAAE,CAAC;IACZ,mBAAmB,EAAE,CAAC;IACtB,aAAa,EAAE,CAAC;IAChB,6BAA6B,EAAE,CAAC;IAChC,6BAA6B,EAAE,CAAC;IAChC,kBAAkB,EAAE,CAAC;CACtB,CAAC,CAAC;AAEH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;AAClC,MAAM,oBAAoB,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CA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M,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1E,UAAU,EAAE,QAAQ,CAAC,MAAM,GAAG,EAAE,GAAG,UAAU,CAAC,MAAM,GAAG,EAAE,EAAE,OAAO;SACnE;KACF,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,CACnB,WAAqB,EACrB,MAAW,EACwB,EAAE;QACrC,MAAM,MAAM,GAAsC,EAAE,CAAC;QACrD,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;YACpC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAuB,CAAC;YAC7C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;gBAC1B,MAAM,KAAK,GAAG,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;gBAC/C,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aACnD;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AACvE,CAAC,CAAC;AAtOW,QAAA,kBAAkB,sBAsO7B","sourcesContent":["import { newError } from '@yuants/utils';\nimport { IQuoteKey, IQuoteState, IQuoteUpdateAction } from '../types';\n\n// TRICK: 固定字段顺序,方便计算偏移量\nconst FIELDS = ((x: { [key in IQuoteKey]: number }) => Object.keys(x).sort() as IQuoteKey[])({\n // TS TRICK: 强制运行时数组具有 IQuoteKey 的所有字段。不重不漏,味道真是好极了\n last_price: 0,\n ask_price: 0,\n ask_volume: 0,\n bid_volume: 0,\n bid_price: 0,\n interest_rate_short: 0,\n open_interest: 0,\n interest_rate_prev_settled_at: 0,\n interest_rate_next_settled_at: 0,\n interest_rate_long: 0,\n});\n\nconst FIELD_COUNT = FIELDS.length;\nconst mapFieldNameToOffset = Object.fromEntries(FIELDS.map((field, index) => [field, index * 2])); // 每个字段占2个位置: [池索引, 时间戳]\n\n/**\n * 使用引用计数字符串池的行情状态管理器 v3\n * 保持 v1 的内存局部性,同时通过字符串池减少内存开销\n * 使用 Float64Array 连续存储 [池索引, 时间戳] 对\n */\nexport const createQuoteStateV3 = (): IQuoteState => {\n // 核心数据存储:连续存储 [池索引, 时间戳, 池索引, 时间戳...]\n let data: Float64Array = new Float64Array(1024 * FIELD_COUNT * 2); // 初始容量:1024产品\n let dataLength = 0; // 当前已分配的数据槽数量(以字段为单位)\n\n // 字符串池\n let stringPool: (string | undefined)[] = []; // 索引 -> 字符串(undefined 表示空闲)\n let refCounts: number[] = []; // 索引 -> 引用计数\n let stringToIndex = new Map<string, number>(); // 字符串 -> 索引\n let freeIndices: number[] = []; // 空闲索引列表\n\n const products: string[] = [];\n const mapProductIdToIndex = new Map<string, number>();\n\n // 确保 data 有足够容量\n const ensureDataCapacity = (requiredFields: number) => {\n if (requiredFields * 2 <= data.length) return;\n\n // 倍增扩容\n const newSize = Math.max(data.length * 2, requiredFields * 2 + 1024);\n const newData = new Float64Array(newSize);\n newData.set(data);\n data = newData;\n };\n\n // 获取字段偏移量(以 Float64 元素为单位)\n const getFieldOffset = (product_id: string, field: string): number => {\n let baseIndex = mapProductIdToIndex.get(product_id);\n if (baseIndex === undefined) {\n baseIndex = mapProductIdToIndex.size;\n products.push(product_id);\n mapProductIdToIndex.set(product_id, baseIndex);\n\n // 确保有足够空间存储该产品的所有字段\n const requiredFields = (baseIndex + 1) * FIELD_COUNT;\n ensureDataCapacity(requiredFields);\n\n // 初始化该产品的所有字段为 [-1, 0](空值)\n const startIdx = baseIndex * FIELD_COUNT * 2;\n for (let i = 0; i < FIELD_COUNT * 2; i += 2) {\n data[startIdx + i] = -1; // 池索引:-1 表示空值\n data[startIdx + i + 1] = 0; // 时间戳:0\n }\n dataLength = Math.max(dataLength, requiredFields);\n }\n const fieldOffset = mapFieldNameToOffset[field];\n if (fieldOffset === undefined) throw newError('INVALID_FIELD_NAME', { field, available_fields: FIELDS });\n return baseIndex * FIELD_COUNT * 2 + fieldOffset;\n };\n\n // 获取或分配字符串索引(增加引用计数)\n const acquireStringIndex = (value: string): number => {\n let index = stringToIndex.get(value);\n if (index !== undefined) {\n // 字符串已存在,增加引用计数\n refCounts[index]++;\n return index;\n }\n\n // 需要新索引\n if (freeIndices.length > 0) {\n // 重用空闲索引\n index = freeIndices.pop()!;\n stringPool[index] = value;\n refCounts[index] = 1;\n } else {\n // 分配新索引\n index = stringPool.length;\n stringPool.push(value);\n refCounts.push(1);\n }\n\n stringToIndex.set(value, index);\n return index;\n };\n\n // 释放字符串索引(减少引用计数)\n const releaseStringIndex = (index: number): void => {\n if (index === -1) return; // 空值索引\n\n refCounts[index]--;\n if (refCounts[index] === 0) {\n // 引用计数归零,可以回收\n const value = stringPool[index]!;\n stringToIndex.delete(value);\n // 清空池中的引用,允许 GC\n stringPool[index] = undefined;\n refCounts[index] = 0;\n freeIndices.push(index);\n }\n };\n\n const getValueTuple = (product_id: string, field: IQuoteKey): [string, number] | undefined => {\n const offset = getFieldOffset(product_id, field);\n const poolIndex = data[offset];\n if (poolIndex === -1) return undefined;\n\n const timestamp = data[offset + 1];\n const value = stringPool[poolIndex]!;\n return [value, timestamp];\n };\n\n const setValueTuple = (product_id: string, field: IQuoteKey, value: string, updated_at: number) => {\n const offset = getFieldOffset(product_id, field);\n const oldPoolIndex = data[offset];\n\n // 释放旧字符串的引用\n releaseStringIndex(oldPoolIndex);\n\n // 获取新字符串索引\n const newPoolIndex = acquireStringIndex(value);\n\n // 更新存储\n data[offset] = newPoolIndex;\n data[offset + 1] = updated_at;\n };\n\n const update = (action: IQuoteUpdateAction) => {\n for (const product_id in action) {\n const fields = action[product_id];\n for (const field_name in fields) {\n const field = field_name as IQuoteKey;\n const [value, updated_at] = fields[field]!;\n const oldTuple = getValueTuple(product_id, field);\n if (oldTuple === undefined || updated_at >= oldTuple[1]) {\n setValueTuple(product_id, field, value, updated_at);\n }\n }\n }\n };\n\n const dumpAsObject = (): IQuoteUpdateAction => {\n const result: IQuoteUpdateAction = {};\n\n // 初始化所有产品的结构\n for (const product_id of products) {\n result[product_id] = {};\n }\n\n // 遍历所有字段(dataLength 是以字段为单位)\n for (let fieldIdx = 0; fieldIdx < dataLength; fieldIdx++) {\n const poolIndex = data[fieldIdx * 2];\n if (poolIndex === -1) continue; // 空值\n\n const timestamp = data[fieldIdx * 2 + 1];\n const productIndex = Math.floor(fieldIdx / FIELD_COUNT);\n const product_id = products[productIndex];\n\n const fieldIndex = fieldIdx % FIELD_COUNT;\n const field_name = FIELDS[fieldIndex];\n\n const value = stringPool[poolIndex]!;\n result[product_id]![field_name] = [value, timestamp];\n }\n\n return result;\n };\n\n /**\n * 过滤状态,返回指定 product_id 列表和字段列表中,且更新时间不早于指定时间的字段数据\n * @param product_ids - 需要过滤的 product_id 列表\n * @param fields - 需要过滤的字段列表\n * @param updated_at - 需要过滤的更新时间阈值 (仅返回更新时间不早于该值的字段)\n * @returns 过滤后的数据\n */\n const filter = (product_ids: string[], fields: IQuoteKey[], updated_at: number): IQuoteUpdateAction => {\n const result: IQuoteUpdateAction = {};\n\n for (const product_id of product_ids) {\n const productIndex = mapProductIdToIndex.get(product_id);\n if (productIndex === undefined) {\n // 产品不存在,创建空对象\n result[product_id] = {};\n continue;\n }\n\n const productResult: Partial<Record<IQuoteKey, [string, number]>> = {};\n const baseOffset = productIndex * FIELD_COUNT * 2;\n\n for (const field of fields) {\n const fieldOffset = mapFieldNameToOffset[field];\n if (fieldOffset === undefined) continue;\n\n const offset = baseOffset + fieldOffset;\n const poolIndex = data[offset];\n if (poolIndex === -1) continue; // 空值\n\n const timestamp = data[offset + 1];\n if (timestamp < updated_at) continue; // 时间戳太旧\n\n const value = stringPool[poolIndex]!;\n productResult[field] = [value, timestamp];\n }\n\n result[product_id] = productResult;\n }\n\n return result;\n };\n\n // 导出内部统计信息用于调试\n const getStats = () => ({\n productCount: products.length,\n fieldCount: dataLength,\n stringPoolSize: stringPool.length,\n activeStrings: stringPool.length - freeIndices.length,\n freeIndices: freeIndices.length,\n memoryEstimate: {\n data: data.length * 8, // Float64Array 每个元素8字节\n pool: stringPool.reduce((sum, str) => sum + (str ? str.length * 2 : 0), 0),\n structures: products.length * 50 + stringPool.length * 16, // 粗略估计\n },\n });\n\n const filterValues = <K extends IQuoteKey>(\n product_ids: string[],\n fields: K[],\n ): Record<string, Record<K, string>> => {\n const result: Record<string, Record<K, string>> = {};\n for (const product_id of product_ids) {\n result[product_id] = {} as Record<K, string>;\n for (const field of fields) {\n const tuple = getValueTuple(product_id, field);\n result[product_id][field] = tuple ? tuple[0] : '';\n }\n }\n return result;\n };\n\n return { update, dumpAsObject, getValueTuple, filter, filterValues };\n};\n"]}
|
package/lib/quote/service.js
CHANGED
|
@@ -111,7 +111,7 @@ terminal.server.provideService('VEX/QueryQuotes', {
|
|
|
111
111
|
if (needUpdate.length > 0) {
|
|
112
112
|
enqueueUpdateTask({ product_ids, fields, updated_at });
|
|
113
113
|
}
|
|
114
|
-
const data = quoteState.
|
|
114
|
+
const data = quoteState.filterValues(product_ids, fields);
|
|
115
115
|
return { res: { code: 0, message: 'OK', data } };
|
|
116
116
|
});
|
|
117
117
|
terminal.server.provideService('VEX/QuoteUpdateQueueStatus', {}, async () => {
|
package/lib/quote/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/quote/service.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,yCAA2C;AAC3C,+BAAiD;AACjD,mCAA2C;AAE3C,yCAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,wBAAgB,GAAE,CAAC;AACtC,MAAM,qBAAqB,GAAG,IAAA,sCAA2B,EAAC,QAAQ,CAAC,CAAC;AAgBpE,MAAM,gBAAgB,GAAG,CA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,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;AACnD,CAAC,CACF,CAAC;AAEF,QAAQ,CAAC,MAAM,CAAC,cAAc,CAA8B,4BAA4B,EAAE,EAAE,EAAE,KAAK,IAAI,EAAE;IACvG,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;AACrE,CAAC,CAAC,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { formatTime } from '@yuants/utils';\nimport { Subject, concatMap, defer } from 'rxjs';\nimport { createQuoteState } from './state';\nimport { IQuoteKey, IQuoteRequire, IQuoteState, IQuoteUpdateAction } from './types';\nimport { createQuoteProviderRegistry } from './upstream';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst quoteState = createQuoteState();\nconst quoteProviderRegistry = createQuoteProviderRegistry(terminal);\n\ntype UpdateTask = { product_ids: string[]; fields: IQuoteKey[]; updated_at: number };\n\ntype IQuoteUpdateQueueStatus = {\n pending: number;\n in_flight: number;\n queued_total: number;\n started_total: number;\n processed_total: number;\n last_enqueued_at?: number;\n last_started_at?: number;\n last_processed_at?: number;\n last_error?: { at: number; code?: string; message?: string };\n};\n\nconst normalizeStrings = (values: string[]) => [...new Set(values)].sort();\nconst normalizeFields = (values: IQuoteKey[]) => [...new Set(values)].sort();\n\nconst analyzeRequestedQuotes = (\n quoteState: IQuoteState,\n product_ids: string[],\n fields: IQuoteKey[],\n updated_at: number,\n): { needUpdate: IQuoteRequire[] } => {\n const needUpdate: IQuoteRequire[] = [];\n for (const product_id of product_ids) {\n for (const field of fields) {\n const tuple = quoteState.getValueTuple(product_id, field);\n if (tuple === undefined) {\n needUpdate.push({ product_id, field });\n continue;\n }\n if (tuple[1] < updated_at) {\n needUpdate.push({ product_id, field });\n }\n }\n }\n return { needUpdate };\n};\n\nconst updateQueue$ = new Subject<UpdateTask>();\nconst updateQueueStats: Omit<IQuoteUpdateQueueStatus, 'pending' | 'in_flight'> = {\n queued_total: 0,\n started_total: 0,\n processed_total: 0,\n};\n\nconst getQueueStatus = (): IQuoteUpdateQueueStatus => {\n const pending = updateQueueStats.queued_total - updateQueueStats.started_total;\n const in_flight = updateQueueStats.started_total - updateQueueStats.processed_total;\n return {\n pending,\n in_flight,\n ...updateQueueStats,\n };\n};\n\nconst enqueueUpdateTask = (task: UpdateTask) => {\n updateQueueStats.queued_total++;\n updateQueueStats.last_enqueued_at = Date.now();\n updateQueue$.next(task);\n};\n\nconst summarizeError = (error: unknown): { code?: string; message?: string } => {\n if (typeof error === 'object' && error !== null) {\n const code = 'code' in error ? (error as any).code : undefined;\n const message = 'message' in error ? (error as any).message : undefined;\n return {\n code: typeof code === 'string' ? code : undefined,\n message: typeof message === 'string' ? message : undefined,\n };\n }\n return {};\n};\n\nconst processUpdateTask = async (task: UpdateTask) => {\n const { needUpdate } = analyzeRequestedQuotes(quoteState, task.product_ids, task.fields, task.updated_at);\n await quoteProviderRegistry.fillQuoteStateFromUpstream({\n quoteState,\n cacheMissed: needUpdate,\n updated_at: task.updated_at,\n });\n};\n\nupdateQueue$\n .pipe(\n concatMap((task) =>\n defer(async () => {\n updateQueueStats.started_total++;\n updateQueueStats.last_started_at = Date.now();\n\n try {\n await processUpdateTask(task);\n } catch (error) {\n const summary = summarizeError(error);\n updateQueueStats.last_error = { at: Date.now(), ...summary };\n console.info(\n formatTime(Date.now()),\n `[VEX][Quote]UpdateQueueTaskFailed`,\n `product_ids=${task.product_ids.length} fields=${task.fields.length} updated_at=${task.updated_at}`,\n JSON.stringify(summary),\n );\n } finally {\n updateQueueStats.processed_total++;\n updateQueueStats.last_processed_at = Date.now();\n }\n }),\n ),\n )\n .subscribe();\n\nterminal.server.provideService<IQuoteUpdateAction>('VEX/UpdateQuotes', {}, async (msg) => {\n quoteState.update(msg.req);\n return { res: { code: 0, message: 'OK' } };\n});\n\nterminal.server.provideService<{}, IQuoteUpdateAction>('VEX/DumpQuoteState', {}, async () => {\n return { res: { code: 0, message: 'OK', data: quoteState.dumpAsObject() } };\n});\n\nterminal.server.provideService<\n { product_ids: string[]; fields: IQuoteKey[]; updated_at: number },\n IQuoteUpdateAction\n>(\n 'VEX/QueryQuotes',\n {\n type: 'object',\n required: ['product_ids', 'fields', 'updated_at'],\n properties: {\n product_ids: {\n type: 'array',\n items: { type: 'string' },\n },\n fields: {\n type: 'array',\n items: { type: 'string' },\n },\n updated_at: { type: 'number' },\n },\n },\n async (msg) => {\n const product_ids = normalizeStrings(msg.req.product_ids);\n const fields = normalizeFields(msg.req.fields);\n const { updated_at } = msg.req;\n\n // SWR strategy: if we have stale or missing data, enqueue an update task,\n // but still return the current data immediately.\n const { needUpdate } = analyzeRequestedQuotes(quoteState, product_ids, fields, updated_at);\n if (needUpdate.length > 0) {\n enqueueUpdateTask({ product_ids, fields, updated_at });\n }\n\n const data = quoteState.filter(product_ids, fields, 0);\n return { res: { code: 0, message: 'OK', data } };\n },\n);\n\nterminal.server.provideService<{}, IQuoteUpdateQueueStatus>('VEX/QuoteUpdateQueueStatus', {}, async () => {\n return { res: { code: 0, message: 'OK', data: getQueueStatus() } };\n});\n"]}
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/quote/service.ts"],"names":[],"mappings":";;AAAA,+CAA4C;AAC5C,yCAA2C;AAC3C,+BAAiD;AACjD,mCAA2C;AAE3C,yCAAyD;AAEzD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,UAAU,GAAG,IAAA,wBAAgB,GAAE,CAAC;AACtC,MAAM,qBAAqB,GAAG,IAAA,sCAA2B,EAAC,QAAQ,CAAC,CAAC;AAgBpE,MAAM,gBAAgB,GAAG,CAAC,MAAgB,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3E,MAAM,eAAe,GAAG,CAAC,MAAm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,EAAE;IACvG,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC;AACrE,CAAC,CAAC,CAAC","sourcesContent":["import { Terminal } from '@yuants/protocol';\nimport { formatTime } from '@yuants/utils';\nimport { Subject, concatMap, defer } from 'rxjs';\nimport { createQuoteState } from './state';\nimport { IQuoteKey, IQuoteRequire, IQuoteState, IQuoteUpdateAction } from './types';\nimport { createQuoteProviderRegistry } from './upstream';\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst quoteState = createQuoteState();\nconst quoteProviderRegistry = createQuoteProviderRegistry(terminal);\n\ntype UpdateTask = { product_ids: string[]; fields: IQuoteKey[]; updated_at: number };\n\ntype IQuoteUpdateQueueStatus = {\n pending: number;\n in_flight: number;\n queued_total: number;\n started_total: number;\n processed_total: number;\n last_enqueued_at?: number;\n last_started_at?: number;\n last_processed_at?: number;\n last_error?: { at: number; code?: string; message?: string };\n};\n\nconst normalizeStrings = (values: string[]) => [...new Set(values)].sort();\nconst normalizeFields = (values: IQuoteKey[]) => [...new Set(values)].sort();\n\nconst analyzeRequestedQuotes = (\n quoteState: IQuoteState,\n product_ids: string[],\n fields: IQuoteKey[],\n updated_at: number,\n): { needUpdate: IQuoteRequire[] } => {\n const needUpdate: IQuoteRequire[] = [];\n for (const product_id of product_ids) {\n for (const field of fields) {\n const tuple = quoteState.getValueTuple(product_id, field);\n if (tuple === undefined) {\n needUpdate.push({ product_id, field });\n continue;\n }\n if (tuple[1] < updated_at) {\n needUpdate.push({ product_id, field });\n }\n }\n }\n return { needUpdate };\n};\n\nconst updateQueue$ = new Subject<UpdateTask>();\nconst updateQueueStats: Omit<IQuoteUpdateQueueStatus, 'pending' | 'in_flight'> = {\n queued_total: 0,\n started_total: 0,\n processed_total: 0,\n};\n\nconst getQueueStatus = (): IQuoteUpdateQueueStatus => {\n const pending = updateQueueStats.queued_total - updateQueueStats.started_total;\n const in_flight = updateQueueStats.started_total - updateQueueStats.processed_total;\n return {\n pending,\n in_flight,\n ...updateQueueStats,\n };\n};\n\nconst enqueueUpdateTask = (task: UpdateTask) => {\n updateQueueStats.queued_total++;\n updateQueueStats.last_enqueued_at = Date.now();\n updateQueue$.next(task);\n};\n\nconst summarizeError = (error: unknown): { code?: string; message?: string } => {\n if (typeof error === 'object' && error !== null) {\n const code = 'code' in error ? (error as any).code : undefined;\n const message = 'message' in error ? (error as any).message : undefined;\n return {\n code: typeof code === 'string' ? code : undefined,\n message: typeof message === 'string' ? message : undefined,\n };\n }\n return {};\n};\n\nconst processUpdateTask = async (task: UpdateTask) => {\n const { needUpdate } = analyzeRequestedQuotes(quoteState, task.product_ids, task.fields, task.updated_at);\n await quoteProviderRegistry.fillQuoteStateFromUpstream({\n quoteState,\n cacheMissed: needUpdate,\n updated_at: task.updated_at,\n });\n};\n\nupdateQueue$\n .pipe(\n concatMap((task) =>\n defer(async () => {\n updateQueueStats.started_total++;\n updateQueueStats.last_started_at = Date.now();\n\n try {\n await processUpdateTask(task);\n } catch (error) {\n const summary = summarizeError(error);\n updateQueueStats.last_error = { at: Date.now(), ...summary };\n console.info(\n formatTime(Date.now()),\n `[VEX][Quote]UpdateQueueTaskFailed`,\n `product_ids=${task.product_ids.length} fields=${task.fields.length} updated_at=${task.updated_at}`,\n JSON.stringify(summary),\n );\n } finally {\n updateQueueStats.processed_total++;\n updateQueueStats.last_processed_at = Date.now();\n }\n }),\n ),\n )\n .subscribe();\n\nterminal.server.provideService<IQuoteUpdateAction>('VEX/UpdateQuotes', {}, async (msg) => {\n quoteState.update(msg.req);\n return { res: { code: 0, message: 'OK' } };\n});\n\nterminal.server.provideService<{}, IQuoteUpdateAction>('VEX/DumpQuoteState', {}, async () => {\n return { res: { code: 0, message: 'OK', data: quoteState.dumpAsObject() } };\n});\n\nterminal.server.provideService<\n { product_ids: string[]; fields: IQuoteKey[]; updated_at: number },\n Record<string, Partial<Record<IQuoteKey, string>>>\n>(\n 'VEX/QueryQuotes',\n {\n type: 'object',\n required: ['product_ids', 'fields', 'updated_at'],\n properties: {\n product_ids: {\n type: 'array',\n items: { type: 'string' },\n },\n fields: {\n type: 'array',\n items: { type: 'string' },\n },\n updated_at: { type: 'number' },\n },\n },\n async (msg) => {\n const product_ids = normalizeStrings(msg.req.product_ids);\n const fields = normalizeFields(msg.req.fields);\n const { updated_at } = msg.req;\n\n // SWR strategy: if we have stale or missing data, enqueue an update task,\n // but still return the current data immediately.\n const { needUpdate } = analyzeRequestedQuotes(quoteState, product_ids, fields, updated_at);\n if (needUpdate.length > 0) {\n enqueueUpdateTask({ product_ids, fields, updated_at });\n }\n\n const data = quoteState.filterValues(product_ids, fields);\n return { res: { code: 0, message: 'OK', data } };\n },\n);\n\nterminal.server.provideService<{}, IQuoteUpdateQueueStatus>('VEX/QuoteUpdateQueueStatus', {}, async () => {\n return { res: { code: 0, message: 'OK', data: getQueueStatus() } };\n});\n"]}
|
package/lib/quote/types.d.ts
CHANGED
|
@@ -27,6 +27,14 @@ export interface IQuoteState {
|
|
|
27
27
|
dumpAsObject: () => IQuoteUpdateAction;
|
|
28
28
|
getValueTuple: (product_id: string, field: IQuoteKey) => [string, number] | undefined;
|
|
29
29
|
filter: (product_ids: string[], fields: IQuoteKey[], updated_at: number) => IQuoteUpdateAction;
|
|
30
|
+
/**
|
|
31
|
+
* 过滤并获取指定产品和字段的值,即便对应字段不存在或未更新也会返回空字符串
|
|
32
|
+
*
|
|
33
|
+
* @param product_ids
|
|
34
|
+
* @param fields
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
filterValues: <K extends IQuoteKey>(product_ids: string[], fields: K[]) => Record<string, Record<K, string>>;
|
|
30
38
|
}
|
|
31
39
|
export interface IQuoteProviderInstance {
|
|
32
40
|
terminal_id: string;
|
package/lib/quote/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["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E,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAChE,CAAC;AACF,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC7C,YAAY,EAAE,MAAM,kBAAkB,CAAC;IACvC,aAAa,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACtF,MAAM,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,KAAK,kBAAkB,CAAC;IAC/F;;;;;;OAMG;IACH,YAAY,EAAE,CAAC,CAAC,SAAS,SAAS,EAChC,WAAW,EAAE,MAAM,EAAE,EACrB,MAAM,EAAE,CAAC,EAAE,KACR,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CACxC;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,qBAAqB,CAAC;IAC5B,uBAAuB,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,SAAS,CAAC;CAClB"}
|
package/lib/quote/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/quote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { IQuote } from '@yuants/data-quote';\nimport { IQuoteServiceMetadata } from '@yuants/exchange';\n\nexport type IQuoteKey = Exclude<keyof IQuote, 'datasource_id' | 'product_id' | 'updated_at'>;\n\n/**\n * 用于批量更新的数据结构\n * 结构为:\n * product_id -> field_name (keyof IQuote) -> [value: string, updated_at: number]\n * 这样设计的目的是为了减少更新的数据量,同时保留每个字段的更新时间\n *\n * 例如:\n * ```json\n * {\n * \"product_123\": {\n * \"last_price\": [\"100.5\", 1627890123456],\n * \"volume\": [\"1500\", 1627890123456]\n * },\n * \"product_456\": {\n * \"last_price\": [\"200.0\", 1627890123456]\n * }\n * }\n * ```\n * @public\n */\nexport type IQuoteUpdateAction = Record<\n string,\n Partial<Record<IQuoteKey, [value: string, updated_at: number]>>\n>;\nexport interface IQuoteState {\n update: (action: IQuoteUpdateAction) => void;\n dumpAsObject: () => IQuoteUpdateAction;\n getValueTuple: (product_id: string, field: IQuoteKey) => [string, number] | undefined;\n filter: (product_ids: string[], fields: IQuoteKey[], updated_at: number) => IQuoteUpdateAction;\n}\n\nexport interface IQuoteProviderInstance {\n terminal_id: string;\n service_id: string;\n}\n\n/**\n * A \"provider group\" is a capability signature of `GetQuotes`.\n * Multiple vendor terminals may provide the same capability; VEX load-balances across instances.\n */\nexport interface IQuoteProviderGroup {\n group_id: string;\n meta: IQuoteServiceMetadata;\n mapTerminalIdToInstance: Map<string, IQuoteProviderInstance>;\n}\n\nexport interface IQuoteRequire {\n product_id: string;\n field: IQuoteKey;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/quote/types.ts"],"names":[],"mappings":"","sourcesContent":["import { IQuote } from '@yuants/data-quote';\nimport { IQuoteServiceMetadata } from '@yuants/exchange';\n\nexport type IQuoteKey = Exclude<keyof IQuote, 'datasource_id' | 'product_id' | 'updated_at'>;\n\n/**\n * 用于批量更新的数据结构\n * 结构为:\n * product_id -> field_name (keyof IQuote) -> [value: string, updated_at: number]\n * 这样设计的目的是为了减少更新的数据量,同时保留每个字段的更新时间\n *\n * 例如:\n * ```json\n * {\n * \"product_123\": {\n * \"last_price\": [\"100.5\", 1627890123456],\n * \"volume\": [\"1500\", 1627890123456]\n * },\n * \"product_456\": {\n * \"last_price\": [\"200.0\", 1627890123456]\n * }\n * }\n * ```\n * @public\n */\nexport type IQuoteUpdateAction = Record<\n string,\n Partial<Record<IQuoteKey, [value: string, updated_at: number]>>\n>;\nexport interface IQuoteState {\n update: (action: IQuoteUpdateAction) => void;\n dumpAsObject: () => IQuoteUpdateAction;\n getValueTuple: (product_id: string, field: IQuoteKey) => [string, number] | undefined;\n filter: (product_ids: string[], fields: IQuoteKey[], updated_at: number) => IQuoteUpdateAction;\n /**\n * 过滤并获取指定产品和字段的值,即便对应字段不存在或未更新也会返回空字符串\n *\n * @param product_ids\n * @param fields\n * @returns\n */\n filterValues: <K extends IQuoteKey>(\n product_ids: string[],\n fields: K[],\n ) => Record<string, Record<K, string>>;\n}\n\nexport interface IQuoteProviderInstance {\n terminal_id: string;\n service_id: string;\n}\n\n/**\n * A \"provider group\" is a capability signature of `GetQuotes`.\n * Multiple vendor terminals may provide the same capability; VEX load-balances across instances.\n */\nexport interface IQuoteProviderGroup {\n group_id: string;\n meta: IQuoteServiceMetadata;\n mapTerminalIdToInstance: Map<string, IQuoteProviderInstance>;\n}\n\nexport interface IQuoteRequire {\n product_id: string;\n field: IQuoteKey;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuants/app-virtual-exchange",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"@yuants/data-product": "0.5.1",
|
|
14
14
|
"@yuants/data-account": "0.11.0",
|
|
15
15
|
"@yuants/data-order": "0.7.1",
|
|
16
|
-
"@yuants/data-quote": "0.
|
|
16
|
+
"@yuants/data-quote": "0.4.0",
|
|
17
17
|
"@yuants/secret": "0.4.1",
|
|
18
18
|
"@yuants/sql": "0.9.31",
|
|
19
|
-
"@yuants/exchange": "0.7.
|
|
19
|
+
"@yuants/exchange": "0.7.1",
|
|
20
20
|
"@yuants/cache": "0.3.4",
|
|
21
21
|
"rxjs": "~7.5.6",
|
|
22
22
|
"ajv": "~8.12.0"
|
package/temp/package-deps.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/virtual-exchange/CHANGELOG.json": "
|
|
3
|
-
"apps/virtual-exchange/CHANGELOG.md": "
|
|
2
|
+
"apps/virtual-exchange/CHANGELOG.json": "e6d256897299fcf53e06a8fafdfc2858e7cf8a2c",
|
|
3
|
+
"apps/virtual-exchange/CHANGELOG.md": "28bc28afb1ba1b3637b25ddece4fea9067e6aa60",
|
|
4
4
|
"apps/virtual-exchange/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
5
5
|
"apps/virtual-exchange/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
6
6
|
"apps/virtual-exchange/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
7
7
|
"apps/virtual-exchange/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
8
8
|
"apps/virtual-exchange/etc/app-virtual-exchange.api.md": "6cb40ec1fa2d40a31a7b0dd3f02b8b24a4d7c4de",
|
|
9
|
-
"apps/virtual-exchange/package.json": "
|
|
9
|
+
"apps/virtual-exchange/package.json": "1261fe420dfbc5b030709e7670eeab63d83363d3",
|
|
10
10
|
"apps/virtual-exchange/src/credential.ts": "7ff9cfe06e46005b2a69e60b5596eb1f59d42bba",
|
|
11
11
|
"apps/virtual-exchange/src/general.ts": "b3d0cd8c57975b9711008beaa05ad7f6812bd57e",
|
|
12
12
|
"apps/virtual-exchange/src/index.ts": "67e1963facf0ee2aedd871496361cff90bf49356",
|
|
13
13
|
"apps/virtual-exchange/src/legacy-services.ts": "a9f6b6c61b7a0efc909a443e6fde88c2766562bf",
|
|
14
|
-
"apps/virtual-exchange/src/position.ts": "
|
|
14
|
+
"apps/virtual-exchange/src/position.ts": "0a0eeac4356bdad82f0e6b58d51d3fbad6c0b9ff",
|
|
15
15
|
"apps/virtual-exchange/src/product-collector.ts": "15ba0a692d694d20b607eaad0287a864577ef30c",
|
|
16
16
|
"apps/virtual-exchange/src/quote/DESIGN.md": "4b952e24f77a7429fd82cdf29155a725bbebe583",
|
|
17
17
|
"apps/virtual-exchange/src/quote/QUOTE_STATE_PERFORMANCE_REPORT.md": "b90b7b77a70bb5f4b503d03ccba8f1d07edf7d37",
|
|
18
|
-
"apps/virtual-exchange/src/quote/__tests__/implementations.test.ts": "
|
|
18
|
+
"apps/virtual-exchange/src/quote/__tests__/implementations.test.ts": "2ab7a385eaffe344d5ebfc87689399c096831b54",
|
|
19
19
|
"apps/virtual-exchange/src/quote/benchmark/ForkedQuoteStateComparisonTest.ts": "de83e52651e4ca3a330719e805298af3f195c696",
|
|
20
20
|
"apps/virtual-exchange/src/quote/benchmark/PerformanceTester.ts": "5de2f97bf856804bb98309939dab273334b373cc",
|
|
21
21
|
"apps/virtual-exchange/src/quote/benchmark/QuoteStateComparisonTest.ts": "1d9c11444333d6a27898d6c1209b1b84d37a9bab",
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"apps/virtual-exchange/src/quote/benchmark/worker.ts": "936e4332139e15d1278fcefaf0bb0c5fb66a38d2",
|
|
26
26
|
"apps/virtual-exchange/src/quote/implementations/README.md": "da3afe60c9bc16576cc226d63c233bb2d2fd7c38",
|
|
27
27
|
"apps/virtual-exchange/src/quote/implementations/index.ts": "99d8c99b24e5e7f14293f489916c83a0bac192d7",
|
|
28
|
-
"apps/virtual-exchange/src/quote/implementations/v0.ts": "
|
|
29
|
-
"apps/virtual-exchange/src/quote/implementations/v1.ts": "
|
|
30
|
-
"apps/virtual-exchange/src/quote/implementations/v2.ts": "
|
|
31
|
-
"apps/virtual-exchange/src/quote/implementations/v3.ts": "
|
|
32
|
-
"apps/virtual-exchange/src/quote/service.ts": "
|
|
28
|
+
"apps/virtual-exchange/src/quote/implementations/v0.ts": "cbc6aa7b7356b18d83a219241e9070e2aeed1365",
|
|
29
|
+
"apps/virtual-exchange/src/quote/implementations/v1.ts": "f8c5bd941659c4a8b6dff0541f44133f123fc78a",
|
|
30
|
+
"apps/virtual-exchange/src/quote/implementations/v2.ts": "8723cede6cee6092ec0b8ce9b273ee92f47790cf",
|
|
31
|
+
"apps/virtual-exchange/src/quote/implementations/v3.ts": "f5e4f31c5592d84206d0a27ee51107ba9a91a53d",
|
|
32
|
+
"apps/virtual-exchange/src/quote/service.ts": "f74bb5f0fb776839d84e55709f3971301b3fdeb3",
|
|
33
33
|
"apps/virtual-exchange/src/quote/state.benchmark.ts": "075d3c5bab0ae6f7b61accfe977f7d35233b06ad",
|
|
34
34
|
"apps/virtual-exchange/src/quote/state.ts": "a13be6e84d30b54de16f90e1cb3feeeab75957df",
|
|
35
|
-
"apps/virtual-exchange/src/quote/types.ts": "
|
|
35
|
+
"apps/virtual-exchange/src/quote/types.ts": "4894fd3df8b5bb92e7aaacda9136fa3e70d45835",
|
|
36
36
|
"apps/virtual-exchange/src/quote/upstream/executor.ts": "f7acd3ced6114f1a20ad72c746a9dfbf67b495ec",
|
|
37
37
|
"apps/virtual-exchange/src/quote/upstream/index.ts": "10439c0fa997c61fcca1763aae40fddba3daa3da",
|
|
38
38
|
"apps/virtual-exchange/src/quote/upstream/prefix-matcher.ts": "079066de8c1d5d91b63ffc2bf67c2163e7b8a540",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"libraries/data-product/temp/package-deps.json": "899bba8ace3f04b2035488ff9059e40732ef1d97",
|
|
46
46
|
"libraries/data-account/temp/package-deps.json": "d49586cd2fc2d6d025e585e5a5dd04d37c41263c",
|
|
47
47
|
"libraries/data-order/temp/package-deps.json": "8aa3e27ff80629d417bfe920e85d8525fbb52f42",
|
|
48
|
-
"libraries/data-quote/temp/package-deps.json": "
|
|
48
|
+
"libraries/data-quote/temp/package-deps.json": "c2f009f818a503342bef588da21c9abd52beea00",
|
|
49
49
|
"libraries/secret/temp/package-deps.json": "360293dbcad7870a579c7c043d7f8f87a1b68c48",
|
|
50
50
|
"libraries/sql/temp/package-deps.json": "041074e0102f9a01820c0fddcf82b9eaee226c79",
|
|
51
|
-
"libraries/exchange/temp/package-deps.json": "
|
|
51
|
+
"libraries/exchange/temp/package-deps.json": "8e1be9c0b37755b28288f53265acf9e27f99c943",
|
|
52
52
|
"libraries/cache/temp/package-deps.json": "e1f94620bc6245add32a4f9d379ed2901129d818",
|
|
53
53
|
"tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
|
|
54
54
|
}
|