@yuants/exchange 0.7.0 → 0.8.0

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.
Files changed (45) hide show
  1. package/dist/exchange.d.ts +90 -0
  2. package/dist/index.js +2 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/interest_rate.js +129 -0
  5. package/dist/interest_rate.js.map +1 -0
  6. package/dist/interest_rate.test.js +24 -0
  7. package/dist/interest_rate.test.js.map +1 -0
  8. package/dist/ohlc.js +152 -0
  9. package/dist/ohlc.js.map +1 -0
  10. package/dist/ohlc.test.js +26 -0
  11. package/dist/ohlc.test.js.map +1 -0
  12. package/dist/quote.test.js +31 -0
  13. package/dist/quote.test.js.map +1 -0
  14. package/dist/types.js.map +1 -1
  15. package/lib/index.d.ts +2 -0
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +2 -0
  18. package/lib/index.js.map +1 -1
  19. package/lib/interest_rate.d.ts +34 -0
  20. package/lib/interest_rate.d.ts.map +1 -0
  21. package/lib/interest_rate.js +134 -0
  22. package/lib/interest_rate.js.map +1 -0
  23. package/lib/interest_rate.test.d.ts +2 -0
  24. package/lib/interest_rate.test.d.ts.map +1 -0
  25. package/lib/interest_rate.test.js +26 -0
  26. package/lib/interest_rate.test.js.map +1 -0
  27. package/lib/ohlc.d.ts +36 -0
  28. package/lib/ohlc.d.ts.map +1 -0
  29. package/lib/ohlc.js +157 -0
  30. package/lib/ohlc.js.map +1 -0
  31. package/lib/ohlc.test.d.ts +2 -0
  32. package/lib/ohlc.test.d.ts.map +1 -0
  33. package/lib/ohlc.test.js +28 -0
  34. package/lib/ohlc.test.js.map +1 -0
  35. package/lib/quote.test.d.ts +2 -0
  36. package/lib/quote.test.d.ts.map +1 -0
  37. package/lib/quote.test.js +33 -0
  38. package/lib/quote.test.js.map +1 -0
  39. package/lib/types.d.ts +16 -0
  40. package/lib/types.d.ts.map +1 -1
  41. package/lib/types.js.map +1 -1
  42. package/package.json +4 -2
  43. package/temp/exchange.api.json +752 -0
  44. package/temp/exchange.api.md +80 -0
  45. package/temp/package-deps.json +15 -8
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { IQuote } from '@yuants/data-quote';\n\n/**\n * Quote 字段类型,排除掉 product_id, updated_at, datasource_id 三个字段\n * @public\n */\nexport type IQuoteField = Exclude<keyof IQuote, 'product_id' | 'updated_at' | 'datasource_id'>;\n\n/**\n * Quote Service Metadata\n * @public\n */\nexport interface IQuoteServiceMetadata<K extends IQuoteField = IQuoteField> {\n product_id_prefix: string;\n fields: K[];\n max_products_per_request?: number;\n}\n\n/**\n * Quote Service Request from VEX to Vendor\n * @public\n */\nexport interface IQuoteServiceRequestByVEX {\n product_ids: string[];\n fields: IQuoteField[];\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<K extends IQuoteField = IQuoteField> = Record<\n string,\n Partial<Record<K, [value: string, updated_at: number]>>\n>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { IQuote } from '@yuants/data-quote';\n\n/**\n * 历史数据翻页方向\n * @public\n */\nexport type SeriesFetchDirection = 'backward' | 'forward';\n\n/**\n * 历史数据写库结果(不返回数据本体)\n * @public\n */\nexport interface ISeriesIngestResult {\n wrote_count: number;\n range?: { start_time: string; end_time: string };\n}\n\n/**\n * Quote 字段类型,排除掉 product_id, updated_at, datasource_id 三个字段\n * @public\n */\nexport type IQuoteField = Exclude<keyof IQuote, 'product_id' | 'updated_at' | 'datasource_id'>;\n\n/**\n * Quote Service Metadata\n * @public\n */\nexport interface IQuoteServiceMetadata<K extends IQuoteField = IQuoteField> {\n product_id_prefix: string;\n fields: K[];\n max_products_per_request?: number;\n}\n\n/**\n * Quote Service Request from VEX to Vendor\n * @public\n */\nexport interface IQuoteServiceRequestByVEX {\n product_ids: string[];\n fields: IQuoteField[];\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<K extends IQuoteField = IQuoteField> = Record<\n string,\n Partial<Record<K, [value: string, updated_at: number]>>\n>;\n"]}
package/lib/index.d.ts CHANGED
@@ -4,6 +4,8 @@ import { IProduct } from '@yuants/data-product';
4
4
  import { IResponse, Terminal } from '@yuants/protocol';
5
5
  import { JSONSchema7 } from 'json-schema';
6
6
  export * from './quote';
7
+ export * from './ohlc';
8
+ export * from './interest_rate';
7
9
  export * from './types';
8
10
  /**
9
11
  * Exchange Interface
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,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BAAuB,gBAAiB,QAAQ,iCAwI5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,gBAChB,QAAQ;UACE,MAAM;;MACzB,QAAQ,UAAU,MAAM,CAAC,CAE3B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,aAAoB,QAAQ,QAAQ,MAAM,KAAG,QAAQ,UAAU,QAAQ,EAAE,CAAC,CAElG,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,YAAY,gBACb,QAAQ;UACE,MAAM;;gBACb,MAAM,KAClB,QAAQ,UAAU,SAAS,EAAE,CAAC,CAEhC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,gBACV,QAAQ;UACE,MAAM;;gBACb,MAAM,KAClB,QAAQ,UAAU,MAAM,EAAE,CAAC,CAE7B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,gBACZ,QAAQ;UACE,MAAM;;UACnB,MAAM,KACZ,QAAQ,UAAU;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAEzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,gBACZ,QAAQ;UACE,MAAM;;UACnB,MAAM,KACZ,QAAQ,UAAU,IAAI,CAAC,CAEzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,gBACZ,QAAQ;UACE,MAAM;;UACnB,MAAM,KACZ,QAAQ,UAAU,IAAI,CAAC,CAEzB,CAAC"}
package/lib/index.js CHANGED
@@ -16,6 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.cancelOrder = exports.modifyOrder = exports.submitOrder = exports.getOrders = exports.getPositions = exports.listProducts = exports.getCredentialId = exports.provideExchangeServices = void 0;
18
18
  __exportStar(require("./quote"), exports);
19
+ __exportStar(require("./ohlc"), exports);
20
+ __exportStar(require("./interest_rate"), exports);
19
21
  __exportStar(require("./types"), exports);
20
22
  const makeCredentialSchema = (type, payloadSchema) => {
21
23
  return {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKA,0CAAwB;AACxB,0CAAwB;AAqFxB,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAE,aAA0B,EAAe,EAAE;IACrF,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;QAC7B,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE;YACrC,OAAO,EAAE,aAAa;SACvB;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CAAI,QAAkB,EAAE,QAAsB,EAAE,EAAE;IACvF,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,QAAQ,CAAC;IAElD,kBAAkB;IAClB,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,iBAAiB,EACjB;QACE,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,YAAY,CAAC;QACxB,UAAU,EAAE;YACV,UAAU,EAAE,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,CAAC;SACzD;KACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;QACZ,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAChF,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,CAAC;IACjE,CAAC,CACF,CAAC;IAEF,eAAe;IACf,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,cAAc,EACd;QACE,IAAI,EAAE,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,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB;AAEF;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAkB,EAClB,UAAwC,EACxC,KAAa,EACa,EAAE;IAC5B,OAAO,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB;AAEF;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAkB,EAClB,UAAwC,EACxC,KAAa,EACa,EAAE;IAC5B,OAAO,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { IProduct } from '@yuants/data-product';\nimport { IResponse, Terminal } from '@yuants/protocol';\nimport { JSONSchema7 } from 'json-schema';\nexport * from './quote';\nexport * from './types';\n\n/**\n * Exchange Interface\n *\n * @public\n */\nexport interface IExchange<T = any> {\n /**\n * Exchange name / type (e.g. 'Binance', 'OKX')\n */\n name: string;\n\n /**\n * JSON Schema for the credential payload\n */\n credentialSchema: JSONSchema7;\n\n /**\n * Get credential ID from credential\n *\n * @param credential - The credential object\n */\n getCredentialId(credential: T): Promise<string>;\n\n /**\n * List all products\n */\n listProducts(): Promise<IProduct[]>;\n\n /**\n * Get all positions\n *\n * @param credential - The credential object\n */\n getPositions(credential: T): Promise<IPosition[]>;\n\n /**\n * Get all orders\n *\n * @param credential - The credential object\n */\n getOrders(credential: T): Promise<IOrder[]>;\n\n /**\n * Get positions by product_id\n *\n * @param credential - The credential object\n * @param product_id - The product ID\n */\n getPositionsByProductId(credential: T, product_id: string): Promise<IPosition[]>;\n\n /**\n * Get orders by product_id\n *\n * @param credential - The credential object\n * @param product_id - The product ID\n */\n getOrdersByProductId(credential: T, product_id: string): Promise<IOrder[]>;\n\n /**\n * Submit an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n submitOrder(credential: T, order: IOrder): Promise<{ order_id: string }>;\n\n /**\n * Modify an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n modifyOrder(credential: T, order: IOrder): Promise<void>;\n\n /**\n * Cancel an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n cancelOrder(credential: T, order: IOrder): Promise<void>;\n}\n\nconst makeCredentialSchema = (type: string, payloadSchema: JSONSchema7): JSONSchema7 => {\n return {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string', const: type },\n payload: payloadSchema,\n },\n };\n};\n\n/**\n * Provide exchange services\n *\n * @public\n */\nexport const provideExchangeServices = <T>(terminal: Terminal, exchange: IExchange<T>) => {\n const { name: type, credentialSchema } = exchange;\n\n // GetCredentialId\n terminal.server.provideService<{ credential: { type: string; payload: T } }, string>(\n 'GetCredentialId',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n },\n },\n async (msg) => {\n const credentialId = await exchange.getCredentialId(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: credentialId } };\n },\n );\n\n // ListProducts\n terminal.server.provideService<void, IProduct[]>(\n 'ListProducts',\n {\n type: 'object',\n required: ['type'],\n properties: {\n type: { const: exchange.name },\n },\n },\n async () => {\n const products = await exchange.listProducts();\n return { res: { code: 0, message: 'OK', data: products } };\n },\n );\n\n // GetPositions\n terminal.server.provideService<\n { credential: { type: string; payload: T }; product_id?: string },\n IPosition[]\n >(\n 'GetPositions',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n if (msg.req.product_id) {\n const positions = await exchange.getPositionsByProductId(\n msg.req.credential.payload,\n msg.req.product_id,\n );\n return { res: { code: 0, message: 'OK', data: positions } };\n }\n const positions = await exchange.getPositions(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: positions } };\n },\n );\n\n // GetOrders\n terminal.server.provideService<{ credential: { type: string; payload: T }; product_id?: string }, IOrder[]>(\n 'GetOrders',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n if (msg.req.product_id) {\n const orders = await exchange.getOrdersByProductId(msg.req.credential.payload, msg.req.product_id);\n return { res: { code: 0, message: 'OK', data: orders } };\n }\n const orders = await exchange.getOrders(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: orders } };\n },\n );\n\n // SubmitOrder\n terminal.server.provideService<\n { credential: { type: string; payload: T }; order: IOrder },\n { order_id: string }\n >(\n 'SubmitOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n const result = await exchange.submitOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK', data: result } };\n },\n );\n\n // ModifyOrder\n terminal.server.provideService<{ credential: { type: string; payload: T }; order: IOrder }, void>(\n 'ModifyOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n await exchange.modifyOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n\n // CancelOrder\n terminal.server.provideService<{ credential: { type: string; payload: T }; order: IOrder }, void>(\n 'CancelOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n await exchange.cancelOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n};\n\n/**\n * Get credential ID\n *\n * @public\n */\nexport const getCredentialId = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n): Promise<IResponse<string>> => {\n return terminal.client.requestForResponse('GetCredentialId', { credential });\n};\n\n/**\n * List products\n *\n * @public\n */\nexport const listProducts = async (terminal: Terminal, type: string): Promise<IResponse<IProduct[]>> => {\n return terminal.client.requestForResponse('ListProducts', { type });\n};\n\n/**\n * Get positions\n *\n * @public\n */\nexport const getPositions = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n product_id?: string,\n): Promise<IResponse<IPosition[]>> => {\n return terminal.client.requestForResponse('GetPositions', { credential, product_id });\n};\n\n/**\n * Get orders\n *\n * @public\n */\nexport const getOrders = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n product_id?: string,\n): Promise<IResponse<IOrder[]>> => {\n return terminal.client.requestForResponse('GetOrders', { credential, product_id });\n};\n\n/**\n * Submit order\n *\n * @public\n */\nexport const submitOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<{ order_id: string }>> => {\n return terminal.client.requestForResponse('SubmitOrder', { credential, order });\n};\n\n/**\n * Modify order\n *\n * @public\n */\nexport const modifyOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<void>> => {\n return terminal.client.requestForResponse('ModifyOrder', { credential, order });\n};\n\n/**\n * Cancel order\n *\n * @public\n */\nexport const cancelOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<void>> => {\n return terminal.client.requestForResponse('CancelOrder', { credential, order });\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAKA,0CAAwB;AACxB,yCAAuB;AACvB,kDAAgC;AAChC,0CAAwB;AAqFxB,MAAM,oBAAoB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C,EACxC,KAAa,EACa,EAAE;IAC5B,OAAO,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB;AAEF;;;;GAIG;AACI,MAAM,WAAW,GAAG,KAAK,EAC9B,QAAkB,EAClB,UAAwC,EACxC,KAAa,EACa,EAAE;IAC5B,OAAO,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAClF,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { IProduct } from '@yuants/data-product';\nimport { IResponse, Terminal } from '@yuants/protocol';\nimport { JSONSchema7 } from 'json-schema';\nexport * from './quote';\nexport * from './ohlc';\nexport * from './interest_rate';\nexport * from './types';\n\n/**\n * Exchange Interface\n *\n * @public\n */\nexport interface IExchange<T = any> {\n /**\n * Exchange name / type (e.g. 'Binance', 'OKX')\n */\n name: string;\n\n /**\n * JSON Schema for the credential payload\n */\n credentialSchema: JSONSchema7;\n\n /**\n * Get credential ID from credential\n *\n * @param credential - The credential object\n */\n getCredentialId(credential: T): Promise<string>;\n\n /**\n * List all products\n */\n listProducts(): Promise<IProduct[]>;\n\n /**\n * Get all positions\n *\n * @param credential - The credential object\n */\n getPositions(credential: T): Promise<IPosition[]>;\n\n /**\n * Get all orders\n *\n * @param credential - The credential object\n */\n getOrders(credential: T): Promise<IOrder[]>;\n\n /**\n * Get positions by product_id\n *\n * @param credential - The credential object\n * @param product_id - The product ID\n */\n getPositionsByProductId(credential: T, product_id: string): Promise<IPosition[]>;\n\n /**\n * Get orders by product_id\n *\n * @param credential - The credential object\n * @param product_id - The product ID\n */\n getOrdersByProductId(credential: T, product_id: string): Promise<IOrder[]>;\n\n /**\n * Submit an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n submitOrder(credential: T, order: IOrder): Promise<{ order_id: string }>;\n\n /**\n * Modify an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n modifyOrder(credential: T, order: IOrder): Promise<void>;\n\n /**\n * Cancel an order\n *\n * @param credential - The credential object\n * @param order - The order object\n */\n cancelOrder(credential: T, order: IOrder): Promise<void>;\n}\n\nconst makeCredentialSchema = (type: string, payloadSchema: JSONSchema7): JSONSchema7 => {\n return {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string', const: type },\n payload: payloadSchema,\n },\n };\n};\n\n/**\n * Provide exchange services\n *\n * @public\n */\nexport const provideExchangeServices = <T>(terminal: Terminal, exchange: IExchange<T>) => {\n const { name: type, credentialSchema } = exchange;\n\n // GetCredentialId\n terminal.server.provideService<{ credential: { type: string; payload: T } }, string>(\n 'GetCredentialId',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n },\n },\n async (msg) => {\n const credentialId = await exchange.getCredentialId(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: credentialId } };\n },\n );\n\n // ListProducts\n terminal.server.provideService<void, IProduct[]>(\n 'ListProducts',\n {\n type: 'object',\n required: ['type'],\n properties: {\n type: { const: exchange.name },\n },\n },\n async () => {\n const products = await exchange.listProducts();\n return { res: { code: 0, message: 'OK', data: products } };\n },\n );\n\n // GetPositions\n terminal.server.provideService<\n { credential: { type: string; payload: T }; product_id?: string },\n IPosition[]\n >(\n 'GetPositions',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n if (msg.req.product_id) {\n const positions = await exchange.getPositionsByProductId(\n msg.req.credential.payload,\n msg.req.product_id,\n );\n return { res: { code: 0, message: 'OK', data: positions } };\n }\n const positions = await exchange.getPositions(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: positions } };\n },\n );\n\n // GetOrders\n terminal.server.provideService<{ credential: { type: string; payload: T }; product_id?: string }, IOrder[]>(\n 'GetOrders',\n {\n type: 'object',\n required: ['credential'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n if (msg.req.product_id) {\n const orders = await exchange.getOrdersByProductId(msg.req.credential.payload, msg.req.product_id);\n return { res: { code: 0, message: 'OK', data: orders } };\n }\n const orders = await exchange.getOrders(msg.req.credential.payload);\n return { res: { code: 0, message: 'OK', data: orders } };\n },\n );\n\n // SubmitOrder\n terminal.server.provideService<\n { credential: { type: string; payload: T }; order: IOrder },\n { order_id: string }\n >(\n 'SubmitOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n const result = await exchange.submitOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK', data: result } };\n },\n );\n\n // ModifyOrder\n terminal.server.provideService<{ credential: { type: string; payload: T }; order: IOrder }, void>(\n 'ModifyOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n await exchange.modifyOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n\n // CancelOrder\n terminal.server.provideService<{ credential: { type: string; payload: T }; order: IOrder }, void>(\n 'CancelOrder',\n {\n type: 'object',\n required: ['credential', 'order'],\n properties: {\n credential: makeCredentialSchema(type, credentialSchema),\n order: { type: 'object' },\n },\n },\n async (msg) => {\n await exchange.cancelOrder(msg.req.credential.payload, msg.req.order);\n return { res: { code: 0, message: 'OK' } };\n },\n );\n};\n\n/**\n * Get credential ID\n *\n * @public\n */\nexport const getCredentialId = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n): Promise<IResponse<string>> => {\n return terminal.client.requestForResponse('GetCredentialId', { credential });\n};\n\n/**\n * List products\n *\n * @public\n */\nexport const listProducts = async (terminal: Terminal, type: string): Promise<IResponse<IProduct[]>> => {\n return terminal.client.requestForResponse('ListProducts', { type });\n};\n\n/**\n * Get positions\n *\n * @public\n */\nexport const getPositions = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n product_id?: string,\n): Promise<IResponse<IPosition[]>> => {\n return terminal.client.requestForResponse('GetPositions', { credential, product_id });\n};\n\n/**\n * Get orders\n *\n * @public\n */\nexport const getOrders = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n product_id?: string,\n): Promise<IResponse<IOrder[]>> => {\n return terminal.client.requestForResponse('GetOrders', { credential, product_id });\n};\n\n/**\n * Submit order\n *\n * @public\n */\nexport const submitOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<{ order_id: string }>> => {\n return terminal.client.requestForResponse('SubmitOrder', { credential, order });\n};\n\n/**\n * Modify order\n *\n * @public\n */\nexport const modifyOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<void>> => {\n return terminal.client.requestForResponse('ModifyOrder', { credential, order });\n};\n\n/**\n * Cancel order\n *\n * @public\n */\nexport const cancelOrder = async <T>(\n terminal: Terminal,\n credential: { type: string; payload: T },\n order: IOrder,\n): Promise<IResponse<void>> => {\n return terminal.client.requestForResponse('CancelOrder', { credential, order });\n};\n"]}
@@ -0,0 +1,34 @@
1
+ import { IInterestRate } from '@yuants/data-interest-rate';
2
+ import { IServiceOptions, Terminal } from '@yuants/protocol';
3
+ import { SeriesFetchDirection } from './types';
4
+ /**
5
+ * Interest Rate Service Metadata
6
+ * @public
7
+ */
8
+ export interface IInterestRateServiceMetadata {
9
+ product_id_prefix: string;
10
+ direction: SeriesFetchDirection;
11
+ }
12
+ /**
13
+ * Interest Rate Service Request from VEX to Vendor
14
+ * @public
15
+ */
16
+ export interface IIngestInterestRateRequest {
17
+ product_id: string;
18
+ limit?: number;
19
+ direction: SeriesFetchDirection;
20
+ time: string;
21
+ }
22
+ /**
23
+ * @public
24
+ */
25
+ export declare const parseInterestRateServiceMetadataFromSchema: (schema: any) => IInterestRateServiceMetadata;
26
+ /**
27
+ * @public
28
+ */
29
+ export declare const provideInterestRateService: (terminal: Terminal, metadata: IInterestRateServiceMetadata, fetchPage: (request: IIngestInterestRateRequest & {
30
+ series_id: string;
31
+ }) => Promise<IInterestRate[]>, serviceOptions?: IServiceOptions) => {
32
+ dispose: () => void;
33
+ };
34
+ //# sourceMappingURL=interest_rate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAK7D,OAAO,EAAuB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,oBAAoB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAwCD;;GAEG;AACH,eAAO,MAAM,0CAA0C,WAAY,GAAG,KAAG,4BAOxE,CAAC;AAqCF;;GAEG;AACH,eAAO,MAAM,0BAA0B,aAC3B,QAAQ,YACR,4BAA4B,uBACjB,0BAA0B,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,KAAK,QAAQ,aAAa,EAAE,CAAC,mBACnF,eAAe;;CAkEjC,CAAC"}
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.provideInterestRateService = exports.parseInterestRateServiceMetadataFromSchema = void 0;
4
+ const schema_1 = require("@yuants/protocol/lib/schema");
5
+ const sql_1 = require("@yuants/sql");
6
+ const utils_1 = require("@yuants/utils");
7
+ const lib_1 = require("../../utils/lib");
8
+ const schemaValidator = (0, schema_1.createValidator)({
9
+ type: 'object',
10
+ required: ['type', 'properties'],
11
+ properties: {
12
+ type: { type: 'string', const: 'object' },
13
+ required: { type: 'array', const: ['product_id', 'direction', 'time'] },
14
+ properties: {
15
+ type: 'object',
16
+ required: ['product_id', 'direction', 'time'],
17
+ properties: {
18
+ product_id: {
19
+ type: 'object',
20
+ required: ['type', 'pattern'],
21
+ properties: {
22
+ type: { type: 'string', const: 'string' },
23
+ pattern: { type: 'string', pattern: '^\\^' },
24
+ },
25
+ },
26
+ direction: {
27
+ type: 'object',
28
+ required: ['const'],
29
+ properties: {
30
+ const: { type: 'string', enum: ['backward', 'forward'] },
31
+ },
32
+ },
33
+ time: {
34
+ type: 'object',
35
+ required: ['type', 'format'],
36
+ properties: {
37
+ type: { type: 'string', const: 'string' },
38
+ format: { type: 'string', const: 'date-time' },
39
+ },
40
+ },
41
+ },
42
+ },
43
+ },
44
+ });
45
+ /**
46
+ * @public
47
+ */
48
+ const parseInterestRateServiceMetadataFromSchema = (schema) => {
49
+ if (!schema)
50
+ throw (0, lib_1.newError)('INTEREST_RATE_SERVICE_SCHEMA_MISSING', { schema });
51
+ if (!schemaValidator(schema))
52
+ throw (0, lib_1.newError)('INTEREST_RATE_SERVICE_SCHEMA_INVALID', { schema });
53
+ return {
54
+ product_id_prefix: schema.properties.product_id.pattern.slice(1),
55
+ direction: schema.properties.direction.const,
56
+ };
57
+ };
58
+ exports.parseInterestRateServiceMetadataFromSchema = parseInterestRateServiceMetadataFromSchema;
59
+ const INTEREST_RATE_INSERT_COLUMNS = [
60
+ 'series_id',
61
+ 'created_at',
62
+ 'datasource_id',
63
+ 'product_id',
64
+ 'long_rate',
65
+ 'short_rate',
66
+ 'settlement_price',
67
+ ];
68
+ const computeInterestRatePageRange = (items) => {
69
+ if (items.length === 0)
70
+ return undefined;
71
+ let start = items[0];
72
+ let startMs = Date.parse(start.created_at);
73
+ let end = items[0];
74
+ let endMs = Date.parse(end.created_at);
75
+ for (const item of items) {
76
+ const createdAtMs = Date.parse(item.created_at);
77
+ if (!isNaN(createdAtMs) && (isNaN(startMs) || createdAtMs < startMs)) {
78
+ start = item;
79
+ startMs = createdAtMs;
80
+ }
81
+ if (!isNaN(createdAtMs) && (isNaN(endMs) || createdAtMs > endMs)) {
82
+ end = item;
83
+ endMs = createdAtMs;
84
+ }
85
+ }
86
+ return { start_time: start.created_at, end_time: end.created_at };
87
+ };
88
+ /**
89
+ * @public
90
+ */
91
+ const provideInterestRateService = (terminal, metadata, fetchPage, serviceOptions) => {
92
+ return terminal.server.provideService('IngestInterestRate', {
93
+ type: 'object',
94
+ required: ['product_id', 'direction', 'time'],
95
+ properties: {
96
+ product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
97
+ direction: { const: metadata.direction },
98
+ time: { type: 'string', format: 'date-time' },
99
+ },
100
+ }, async (msg) => {
101
+ try {
102
+ const series_id = (0, utils_1.encodePath)(msg.req.product_id);
103
+ const items = await fetchPage(Object.assign(Object.assign({}, msg.req), { series_id }));
104
+ const normalized = items.map((x) => (Object.assign(Object.assign({}, x), { series_id, datasource_id: '', product_id: msg.req.product_id })));
105
+ if (normalized.length > 0) {
106
+ await (0, sql_1.requestSQL)(terminal, (0, sql_1.buildInsertManyIntoTableSQL)(normalized, 'interest_rate', {
107
+ columns: INTEREST_RATE_INSERT_COLUMNS,
108
+ conflictKeys: ['series_id', 'created_at'],
109
+ }));
110
+ }
111
+ const range = computeInterestRatePageRange(normalized);
112
+ if (range) {
113
+ await (0, sql_1.requestSQL)(terminal, (0, sql_1.buildInsertManyIntoTableSQL)([
114
+ {
115
+ series_id,
116
+ table_name: 'interest_rate',
117
+ start_time: range.start_time,
118
+ end_time: range.end_time,
119
+ },
120
+ ], 'series_data_range', {
121
+ columns: ['series_id', 'table_name', 'start_time', 'end_time'],
122
+ ignoreConflict: true,
123
+ }));
124
+ }
125
+ return { res: { code: 0, message: 'OK', data: { wrote_count: normalized.length, range } } };
126
+ }
127
+ catch (error) {
128
+ const message = error instanceof Error ? error.message : `${error}`;
129
+ return { res: { code: 1, message } };
130
+ }
131
+ }, serviceOptions);
132
+ };
133
+ exports.provideInterestRateService = provideInterestRateService;
134
+ //# sourceMappingURL=interest_rate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":";;;AAEA,wDAA8D;AAC9D,qCAAsE;AACtE,yCAA2C;AAC3C,yCAA2C;AAuB3C,MAAM,eAAe,GAAG,IAAA,wBAAe,EAAC;IACtC,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC;IAChC,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;QACzC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE;QACvE,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC;YAC7C,UAAU,EAAE;gBACV,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;oBAC7B,UAAU,EAAE;wBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;wBACzC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE;qBAC7C;iBACF;gBACD,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;o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EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;SAC7F;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;YACpE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;SACtC;IACH,CAAC,EACD,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAtEW,QAAA,0BAA0B,8BAsErC","sourcesContent":["import { IInterestRate } from '@yuants/data-interest-rate';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { createValidator } from '@yuants/protocol/lib/schema';\nimport { buildInsertManyIntoTableSQL, requestSQL } from '@yuants/sql';\nimport { encodePath } from '@yuants/utils';\nimport { newError } from '../../utils/lib';\nimport { ISeriesIngestResult, SeriesFetchDirection } from './types';\n\n/**\n * Interest Rate Service Metadata\n * @public\n */\nexport interface IInterestRateServiceMetadata {\n product_id_prefix: string;\n direction: SeriesFetchDirection;\n}\n\n/**\n * Interest Rate Service Request from VEX to Vendor\n * @public\n */\nexport interface IIngestInterestRateRequest {\n product_id: string;\n limit?: number;\n direction: SeriesFetchDirection;\n time: string;\n}\n\nconst schemaValidator = createValidator({\n type: 'object',\n required: ['type', 'properties'],\n properties: {\n type: { type: 'string', const: 'object' },\n required: { type: 'array', const: ['product_id', 'direction', 'time'] },\n properties: {\n type: 'object',\n required: ['product_id', 'direction', 'time'],\n properties: {\n product_id: {\n type: 'object',\n required: ['type', 'pattern'],\n properties: {\n type: { type: 'string', const: 'string' },\n pattern: { type: 'string', pattern: '^\\\\^' },\n },\n },\n direction: {\n type: 'object',\n required: ['const'],\n properties: {\n const: { type: 'string', enum: ['backward', 'forward'] },\n },\n },\n time: {\n type: 'object',\n required: ['type', 'format'],\n properties: {\n type: { type: 'string', const: 'string' },\n format: { type: 'string', const: 'date-time' },\n },\n },\n },\n },\n },\n});\n\n/**\n * @public\n */\nexport const parseInterestRateServiceMetadataFromSchema = (schema: any): IInterestRateServiceMetadata => {\n if (!schema) throw newError('INTEREST_RATE_SERVICE_SCHEMA_MISSING', { schema });\n if (!schemaValidator(schema)) throw newError('INTEREST_RATE_SERVICE_SCHEMA_INVALID', { schema });\n return {\n product_id_prefix: schema.properties.product_id.pattern.slice(1),\n direction: schema.properties.direction.const,\n };\n};\n\nconst INTEREST_RATE_INSERT_COLUMNS: Array<keyof IInterestRate> = [\n 'series_id',\n 'created_at',\n 'datasource_id',\n 'product_id',\n 'long_rate',\n 'short_rate',\n 'settlement_price',\n];\n\nconst computeInterestRatePageRange = (\n items: IInterestRate[],\n): { start_time: string; end_time: string } | undefined => {\n if (items.length === 0) return undefined;\n\n let start = items[0];\n let startMs = Date.parse(start.created_at);\n let end = items[0];\n let endMs = Date.parse(end.created_at);\n\n for (const item of items) {\n const createdAtMs = Date.parse(item.created_at);\n if (!isNaN(createdAtMs) && (isNaN(startMs) || createdAtMs < startMs)) {\n start = item;\n startMs = createdAtMs;\n }\n if (!isNaN(createdAtMs) && (isNaN(endMs) || createdAtMs > endMs)) {\n end = item;\n endMs = createdAtMs;\n }\n }\n\n return { start_time: start.created_at, end_time: end.created_at };\n};\n\n/**\n * @public\n */\nexport const provideInterestRateService = (\n terminal: Terminal,\n metadata: IInterestRateServiceMetadata,\n fetchPage: (request: IIngestInterestRateRequest & { series_id: string }) => Promise<IInterestRate[]>,\n serviceOptions?: IServiceOptions,\n) => {\n return terminal.server.provideService<IIngestInterestRateRequest, ISeriesIngestResult>(\n 'IngestInterestRate',\n {\n type: 'object',\n required: ['product_id', 'direction', 'time'],\n properties: {\n product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },\n direction: { const: metadata.direction },\n time: { type: 'string', format: 'date-time' },\n },\n },\n async (msg) => {\n try {\n const series_id = encodePath(msg.req.product_id);\n\n const items = await fetchPage({ ...msg.req, series_id });\n\n const normalized: IInterestRate[] = items.map((x) => ({\n ...x,\n series_id,\n datasource_id: '',\n product_id: msg.req.product_id,\n }));\n\n if (normalized.length > 0) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(normalized, 'interest_rate', {\n columns: INTEREST_RATE_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n }),\n );\n }\n\n const range = computeInterestRatePageRange(normalized);\n if (range) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(\n [\n {\n series_id,\n table_name: 'interest_rate',\n start_time: range.start_time,\n end_time: range.end_time,\n },\n ],\n 'series_data_range',\n {\n columns: ['series_id', 'table_name', 'start_time', 'end_time'],\n ignoreConflict: true,\n },\n ),\n );\n }\n\n return { res: { code: 0, message: 'OK', data: { wrote_count: normalized.length, range } } };\n } catch (error) {\n const message = error instanceof Error ? error.message : `${error}`;\n return { res: { code: 1, message } };\n }\n },\n serviceOptions,\n );\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=interest_rate.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.test.d.ts","sourceRoot":"","sources":["../src/interest_rate.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const interest_rate_1 = require("./interest_rate");
4
+ describe('parseInterestRateServiceMetadataFromSchema', () => {
5
+ it('parses interest rate service schema', () => {
6
+ const schema = {
7
+ type: 'object',
8
+ required: ['product_id', 'direction', 'time'],
9
+ properties: {
10
+ product_id: { type: 'string', pattern: '^BINANCE/' },
11
+ direction: { const: 'forward' },
12
+ time: { type: 'string', format: 'date-time' },
13
+ },
14
+ };
15
+ const meta = (0, interest_rate_1.parseInterestRateServiceMetadataFromSchema)(schema);
16
+ expect(meta).toEqual({
17
+ product_id_prefix: 'BINANCE/',
18
+ direction: 'forward',
19
+ });
20
+ });
21
+ it('throws when schema missing/invalid', () => {
22
+ expect(() => (0, interest_rate_1.parseInterestRateServiceMetadataFromSchema)(undefined)).toThrow('INTEREST_RATE_SERVICE_SCHEMA_MISSING');
23
+ expect(() => (0, interest_rate_1.parseInterestRateServiceMetadataFromSchema)({})).toThrow('INTEREST_RATE_SERVICE_SCHEMA_INVALID');
24
+ });
25
+ });
26
+ //# sourceMappingURL=interest_rate.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interest_rate.test.js","sourceRoot":"","sources":["../src/interest_rate.test.ts"],"names":[],"mappings":";;AAAA,mDAA6E;AAE7E,QAAQ,CAAC,4CAA4C,EAAE,GAAG,EAAE;IAC1D,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAC7C,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC;YAC7C,UAAU,EAAE;gBACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE;gBACpD,SAAS,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE;gBAC/B,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE;aAC9C;SACF,CAAC;QAEF,MAAM,IAAI,GAAG,IAAA,0DAA0C,EAAC,MAAM,CAAC,CAAC;QAChE,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YACnB,iBAAiB,EAAE,UAAU;YAC7B,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,0DAA0C,EAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CACzE,sCAAsC,CACvC,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,0DAA0C,EAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAClE,sCAAsC,CACvC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { parseInterestRateServiceMetadataFromSchema } from './interest_rate';\n\ndescribe('parseInterestRateServiceMetadataFromSchema', () => {\n it('parses interest rate service schema', () => {\n const schema = {\n type: 'object',\n required: ['product_id', 'direction', 'time'],\n properties: {\n product_id: { type: 'string', pattern: '^BINANCE/' },\n direction: { const: 'forward' },\n time: { type: 'string', format: 'date-time' },\n },\n };\n\n const meta = parseInterestRateServiceMetadataFromSchema(schema);\n expect(meta).toEqual({\n product_id_prefix: 'BINANCE/',\n direction: 'forward',\n });\n });\n\n it('throws when schema missing/invalid', () => {\n expect(() => parseInterestRateServiceMetadataFromSchema(undefined)).toThrow(\n 'INTEREST_RATE_SERVICE_SCHEMA_MISSING',\n );\n expect(() => parseInterestRateServiceMetadataFromSchema({})).toThrow(\n 'INTEREST_RATE_SERVICE_SCHEMA_INVALID',\n );\n });\n});\n"]}
package/lib/ohlc.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { IOHLC } from '@yuants/data-ohlc';
2
+ import { IServiceOptions, Terminal } from '@yuants/protocol';
3
+ import { SeriesFetchDirection } from './types';
4
+ /**
5
+ * OHLC Service Metadata
6
+ * @public
7
+ */
8
+ export interface IOHLCServiceMetadata {
9
+ product_id_prefix: string;
10
+ duration_list: string[];
11
+ direction: SeriesFetchDirection;
12
+ }
13
+ /**
14
+ * OHLC Service Request from VEX to Vendor
15
+ * @public
16
+ */
17
+ export interface IIngestOHLCRequest {
18
+ product_id: string;
19
+ duration: string;
20
+ limit?: number;
21
+ direction: SeriesFetchDirection;
22
+ time: string;
23
+ }
24
+ /**
25
+ * @public
26
+ */
27
+ export declare const parseOHLCServiceMetadataFromSchema: (schema: any) => IOHLCServiceMetadata;
28
+ /**
29
+ * @public
30
+ */
31
+ export declare const provideOHLCService: (terminal: Terminal, metadata: IOHLCServiceMetadata, fetchPage: (request: IIngestOHLCRequest & {
32
+ series_id: string;
33
+ }) => Promise<IOHLC[]>, serviceOptions?: IServiceOptions) => {
34
+ dispose: () => void;
35
+ };
36
+ //# sourceMappingURL=ohlc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc.d.ts","sourceRoot":"","sources":["../src/ohlc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAK7D,OAAO,EAAuB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpE;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,oBAAoB,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,oBAAoB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAgDD;;GAEG;AACH,eAAO,MAAM,kCAAkC,WAAY,GAAG,KAAG,oBAQhE,CAAC;AA6CF;;GAEG;AACH,eAAO,MAAM,kBAAkB,aACnB,QAAQ,YACR,oBAAoB,uBACT,kBAAkB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,KAAK,QAAQ,KAAK,EAAE,CAAC,mBACnE,eAAe;;CAqEjC,CAAC"}
package/lib/ohlc.js ADDED
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.provideOHLCService = exports.parseOHLCServiceMetadataFromSchema = void 0;
4
+ const schema_1 = require("@yuants/protocol/lib/schema");
5
+ const sql_1 = require("@yuants/sql");
6
+ const utils_1 = require("@yuants/utils");
7
+ const lib_1 = require("../../utils/lib");
8
+ const schemaValidator = (0, schema_1.createValidator)({
9
+ type: 'object',
10
+ required: ['type', 'properties'],
11
+ properties: {
12
+ type: { type: 'string', const: 'object' },
13
+ required: { type: 'array', const: ['product_id', 'duration', 'direction', 'time'] },
14
+ properties: {
15
+ type: 'object',
16
+ required: ['product_id', 'duration', 'direction', 'time'],
17
+ properties: {
18
+ product_id: {
19
+ type: 'object',
20
+ required: ['type', 'pattern'],
21
+ properties: {
22
+ type: { type: 'string', const: 'string' },
23
+ pattern: { type: 'string', pattern: '^\\^' },
24
+ },
25
+ },
26
+ duration: {
27
+ type: 'object',
28
+ required: ['type', 'enum'],
29
+ properties: {
30
+ type: { type: 'string', const: 'string' },
31
+ enum: { type: 'array', items: { type: 'string' } },
32
+ },
33
+ },
34
+ direction: {
35
+ type: 'object',
36
+ required: ['const'],
37
+ properties: {
38
+ const: { type: 'string', enum: ['backward', 'forward'] },
39
+ },
40
+ },
41
+ time: {
42
+ type: 'object',
43
+ required: ['type', 'format'],
44
+ properties: {
45
+ type: { type: 'string', const: 'string' },
46
+ format: { type: 'string', const: 'date-time' },
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ });
53
+ /**
54
+ * @public
55
+ */
56
+ const parseOHLCServiceMetadataFromSchema = (schema) => {
57
+ if (!schema)
58
+ throw (0, lib_1.newError)('OHLC_SERVICE_SCHEMA_MISSING', { schema });
59
+ if (!schemaValidator(schema))
60
+ throw (0, lib_1.newError)('OHLC_SERVICE_SCHEMA_INVALID', { schema });
61
+ return {
62
+ product_id_prefix: schema.properties.product_id.pattern.slice(1),
63
+ duration_list: schema.properties.duration.enum,
64
+ direction: schema.properties.direction.const,
65
+ };
66
+ };
67
+ exports.parseOHLCServiceMetadataFromSchema = parseOHLCServiceMetadataFromSchema;
68
+ const OHLC_INSERT_COLUMNS = [
69
+ 'series_id',
70
+ 'created_at',
71
+ 'datasource_id',
72
+ 'product_id',
73
+ 'duration',
74
+ 'closed_at',
75
+ 'open',
76
+ 'high',
77
+ 'low',
78
+ 'close',
79
+ 'volume',
80
+ 'open_interest',
81
+ ];
82
+ const computeOHLCPageRange = (items) => {
83
+ if (items.length === 0)
84
+ return undefined;
85
+ let start = items[0];
86
+ let startMs = Date.parse(start.created_at);
87
+ let end = items[0];
88
+ let endMs = Date.parse(end.closed_at) || Date.parse(end.created_at);
89
+ for (const item of items) {
90
+ const createdAtMs = Date.parse(item.created_at);
91
+ if (!isNaN(createdAtMs) && (isNaN(startMs) || createdAtMs < startMs)) {
92
+ start = item;
93
+ startMs = createdAtMs;
94
+ }
95
+ const closedAtMs = Date.parse(item.closed_at);
96
+ const candidateEndMs = !isNaN(closedAtMs) ? closedAtMs : createdAtMs;
97
+ if (!isNaN(candidateEndMs) && (isNaN(endMs) || candidateEndMs > endMs)) {
98
+ end = item;
99
+ endMs = candidateEndMs;
100
+ }
101
+ }
102
+ return {
103
+ start_time: start.created_at,
104
+ end_time: end.closed_at || end.created_at,
105
+ };
106
+ };
107
+ /**
108
+ * @public
109
+ */
110
+ const provideOHLCService = (terminal, metadata, fetchPage, serviceOptions) => {
111
+ return terminal.server.provideService('IngestOHLC', {
112
+ type: 'object',
113
+ required: ['product_id', 'duration', 'direction', 'time'],
114
+ properties: {
115
+ product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
116
+ duration: { type: 'string', enum: metadata.duration_list },
117
+ direction: { const: metadata.direction },
118
+ time: { type: 'string', format: 'date-time' },
119
+ },
120
+ }, async (msg) => {
121
+ try {
122
+ const series_id = (0, utils_1.encodePath)(msg.req.product_id, msg.req.duration);
123
+ const items = await fetchPage(Object.assign(Object.assign({}, msg.req), { series_id }));
124
+ const normalized = items.map((x) => {
125
+ var _a;
126
+ return (Object.assign(Object.assign({}, x), { series_id, datasource_id: '', product_id: msg.req.product_id, duration: msg.req.duration, open_interest: (_a = x.open_interest) !== null && _a !== void 0 ? _a : '0' }));
127
+ });
128
+ if (normalized.length > 0) {
129
+ await (0, sql_1.requestSQL)(terminal, (0, sql_1.buildInsertManyIntoTableSQL)(normalized, 'ohlc', {
130
+ columns: OHLC_INSERT_COLUMNS,
131
+ conflictKeys: ['series_id', 'created_at'],
132
+ }));
133
+ }
134
+ const range = computeOHLCPageRange(normalized);
135
+ if (range) {
136
+ await (0, sql_1.requestSQL)(terminal, (0, sql_1.buildInsertManyIntoTableSQL)([
137
+ {
138
+ series_id,
139
+ table_name: 'ohlc',
140
+ start_time: range.start_time,
141
+ end_time: range.end_time,
142
+ },
143
+ ], 'series_data_range', {
144
+ columns: ['series_id', 'table_name', 'start_time', 'end_time'],
145
+ ignoreConflict: true,
146
+ }));
147
+ }
148
+ return { res: { code: 0, message: 'OK', data: { wrote_count: normalized.length, range } } };
149
+ }
150
+ catch (error) {
151
+ const message = error instanceof Error ? error.message : `${error}`;
152
+ return { res: { code: 1, message } };
153
+ }
154
+ }, serviceOptions);
155
+ };
156
+ exports.provideOHLCService = provideOHLCService;
157
+ //# sourceMappingURL=ohlc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc.js","sourceRoot":"","sources":["../src/ohlc.ts"],"names":[],"mappings":";;;AAEA,wDAA8D;AAC9D,qCAAsE;AACtE,yCAA2C;AAC3C,yCAA2C;AAyB3C,MAAM,eAAe,GAAG,IAAA,wBAAe,EAAC;IACtC,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,CAAC;IAChC,UAAU,EAAE;QACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE;QACzC,QAAQ,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE;QACnF,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,YAA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AY,EAAE,YAAY,EAAE,UAAU,CAAC;oBAC9D,cAAc,EAAE,IAAI;iBACrB,CACF,CACF,CAAC;aACH;YAED,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;SAC7F;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;YACpE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;SACtC;IACH,CAAC,EACD,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AAzEW,QAAA,kBAAkB,sBAyE7B","sourcesContent":["import { IOHLC } from '@yuants/data-ohlc';\nimport { IServiceOptions, Terminal } from '@yuants/protocol';\nimport { createValidator } from '@yuants/protocol/lib/schema';\nimport { buildInsertManyIntoTableSQL, requestSQL } from '@yuants/sql';\nimport { encodePath } from '@yuants/utils';\nimport { newError } from '../../utils/lib';\nimport { ISeriesIngestResult, SeriesFetchDirection } from './types';\n\n/**\n * OHLC Service Metadata\n * @public\n */\nexport interface IOHLCServiceMetadata {\n product_id_prefix: string;\n duration_list: string[];\n direction: SeriesFetchDirection;\n}\n\n/**\n * OHLC Service Request from VEX to Vendor\n * @public\n */\nexport interface IIngestOHLCRequest {\n product_id: string;\n duration: string;\n limit?: number;\n direction: SeriesFetchDirection;\n time: string;\n}\n\nconst schemaValidator = createValidator({\n type: 'object',\n required: ['type', 'properties'],\n properties: {\n type: { type: 'string', const: 'object' },\n required: { type: 'array', const: ['product_id', 'duration', 'direction', 'time'] },\n properties: {\n type: 'object',\n required: ['product_id', 'duration', 'direction', 'time'],\n properties: {\n product_id: {\n type: 'object',\n required: ['type', 'pattern'],\n properties: {\n type: { type: 'string', const: 'string' },\n pattern: { type: 'string', pattern: '^\\\\^' },\n },\n },\n duration: {\n type: 'object',\n required: ['type', 'enum'],\n properties: {\n type: { type: 'string', const: 'string' },\n enum: { type: 'array', items: { type: 'string' } },\n },\n },\n direction: {\n type: 'object',\n required: ['const'],\n properties: {\n const: { type: 'string', enum: ['backward', 'forward'] },\n },\n },\n time: {\n type: 'object',\n required: ['type', 'format'],\n properties: {\n type: { type: 'string', const: 'string' },\n format: { type: 'string', const: 'date-time' },\n },\n },\n },\n },\n },\n});\n\n/**\n * @public\n */\nexport const parseOHLCServiceMetadataFromSchema = (schema: any): IOHLCServiceMetadata => {\n if (!schema) throw newError('OHLC_SERVICE_SCHEMA_MISSING', { schema });\n if (!schemaValidator(schema)) throw newError('OHLC_SERVICE_SCHEMA_INVALID', { schema });\n return {\n product_id_prefix: schema.properties.product_id.pattern.slice(1),\n duration_list: schema.properties.duration.enum,\n direction: schema.properties.direction.const,\n };\n};\n\nconst OHLC_INSERT_COLUMNS: Array<keyof IOHLC> = [\n 'series_id',\n 'created_at',\n 'datasource_id',\n 'product_id',\n 'duration',\n 'closed_at',\n 'open',\n 'high',\n 'low',\n 'close',\n 'volume',\n 'open_interest',\n];\n\nconst computeOHLCPageRange = (items: IOHLC[]): { start_time: string; end_time: string } | undefined => {\n if (items.length === 0) return undefined;\n\n let start = items[0];\n let startMs = Date.parse(start.created_at);\n let end = items[0];\n let endMs = Date.parse(end.closed_at) || Date.parse(end.created_at);\n\n for (const item of items) {\n const createdAtMs = Date.parse(item.created_at);\n if (!isNaN(createdAtMs) && (isNaN(startMs) || createdAtMs < startMs)) {\n start = item;\n startMs = createdAtMs;\n }\n const closedAtMs = Date.parse(item.closed_at);\n const candidateEndMs = !isNaN(closedAtMs) ? closedAtMs : createdAtMs;\n if (!isNaN(candidateEndMs) && (isNaN(endMs) || candidateEndMs > endMs)) {\n end = item;\n endMs = candidateEndMs;\n }\n }\n\n return {\n start_time: start.created_at,\n end_time: end.closed_at || end.created_at,\n };\n};\n\n/**\n * @public\n */\nexport const provideOHLCService = (\n terminal: Terminal,\n metadata: IOHLCServiceMetadata,\n fetchPage: (request: IIngestOHLCRequest & { series_id: string }) => Promise<IOHLC[]>,\n serviceOptions?: IServiceOptions,\n) => {\n return terminal.server.provideService<IIngestOHLCRequest, ISeriesIngestResult>(\n 'IngestOHLC',\n {\n type: 'object',\n required: ['product_id', 'duration', 'direction', 'time'],\n properties: {\n product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },\n duration: { type: 'string', enum: metadata.duration_list },\n direction: { const: metadata.direction },\n time: { type: 'string', format: 'date-time' },\n },\n },\n async (msg) => {\n try {\n const series_id = encodePath(msg.req.product_id, msg.req.duration);\n\n const items = await fetchPage({ ...msg.req, series_id });\n\n const normalized: IOHLC[] = items.map((x) => ({\n ...x,\n series_id,\n datasource_id: '',\n product_id: msg.req.product_id,\n duration: msg.req.duration,\n open_interest: x.open_interest ?? '0',\n }));\n\n if (normalized.length > 0) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(normalized, 'ohlc', {\n columns: OHLC_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n }),\n );\n }\n\n const range = computeOHLCPageRange(normalized);\n if (range) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(\n [\n {\n series_id,\n table_name: 'ohlc',\n start_time: range.start_time,\n end_time: range.end_time,\n },\n ],\n 'series_data_range',\n {\n columns: ['series_id', 'table_name', 'start_time', 'end_time'],\n ignoreConflict: true,\n },\n ),\n );\n }\n\n return { res: { code: 0, message: 'OK', data: { wrote_count: normalized.length, range } } };\n } catch (error) {\n const message = error instanceof Error ? error.message : `${error}`;\n return { res: { code: 1, message } };\n }\n },\n serviceOptions,\n );\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ohlc.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc.test.d.ts","sourceRoot":"","sources":["../src/ohlc.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ohlc_1 = require("./ohlc");
4
+ describe('parseOHLCServiceMetadataFromSchema', () => {
5
+ it('parses OHLC service schema', () => {
6
+ const schema = {
7
+ type: 'object',
8
+ required: ['product_id', 'duration', 'direction', 'time'],
9
+ properties: {
10
+ product_id: { type: 'string', pattern: '^BINANCE/USDT-FUTURE' },
11
+ duration: { type: 'string', enum: ['PT1M', 'PT5M'] },
12
+ direction: { const: 'backward' },
13
+ time: { type: 'string', format: 'date-time' },
14
+ },
15
+ };
16
+ const meta = (0, ohlc_1.parseOHLCServiceMetadataFromSchema)(schema);
17
+ expect(meta).toEqual({
18
+ product_id_prefix: 'BINANCE/USDT-FUTURE',
19
+ duration_list: ['PT1M', 'PT5M'],
20
+ direction: 'backward',
21
+ });
22
+ });
23
+ it('throws when schema missing/invalid', () => {
24
+ expect(() => (0, ohlc_1.parseOHLCServiceMetadataFromSchema)(undefined)).toThrow('OHLC_SERVICE_SCHEMA_MISSING');
25
+ expect(() => (0, ohlc_1.parseOHLCServiceMetadataFromSchema)({})).toThrow('OHLC_SERVICE_SCHEMA_INVALID');
26
+ });
27
+ });
28
+ //# sourceMappingURL=ohlc.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ohlc.test.js","sourceRoot":"","sources":["../src/ohlc.test.ts"],"names":[],"mappings":";;AAAA,iCAA4D;AAE5D,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAClD,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,QAAQ;YACd,QAAQ,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC;YACzD,UAAU,EAAE;gBACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,sBAAsB,EAAE;gBAC/D,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE;gBACpD,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE;gBAChC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE;aAC9C;SACF,CAAC;QAEF,MAAM,IAAI,GAAG,IAAA,yCAAkC,EAAC,MAAM,CAAC,CAAC;QACxD,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;YACnB,iBAAiB,EAAE,qBAAqB;YACxC,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;YAC/B,SAAS,EAAE,UAAU;SACtB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;QAC5C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,yCAAkC,EAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;QACnG,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,yCAAkC,EAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { parseOHLCServiceMetadataFromSchema } from './ohlc';\n\ndescribe('parseOHLCServiceMetadataFromSchema', () => {\n it('parses OHLC service schema', () => {\n const schema = {\n type: 'object',\n required: ['product_id', 'duration', 'direction', 'time'],\n properties: {\n product_id: { type: 'string', pattern: '^BINANCE/USDT-FUTURE' },\n duration: { type: 'string', enum: ['PT1M', 'PT5M'] },\n direction: { const: 'backward' },\n time: { type: 'string', format: 'date-time' },\n },\n };\n\n const meta = parseOHLCServiceMetadataFromSchema(schema);\n expect(meta).toEqual({\n product_id_prefix: 'BINANCE/USDT-FUTURE',\n duration_list: ['PT1M', 'PT5M'],\n direction: 'backward',\n });\n });\n\n it('throws when schema missing/invalid', () => {\n expect(() => parseOHLCServiceMetadataFromSchema(undefined)).toThrow('OHLC_SERVICE_SCHEMA_MISSING');\n expect(() => parseOHLCServiceMetadataFromSchema({})).toThrow('OHLC_SERVICE_SCHEMA_INVALID');\n });\n});\n"]}