@yuants/exchange 0.8.0 → 0.8.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.
@@ -130,9 +130,8 @@ export declare interface IExchange<T = any> {
130
130
  */
131
131
  export declare interface IIngestInterestRateRequest {
132
132
  product_id: string;
133
- limit?: number;
134
133
  direction: SeriesFetchDirection;
135
- time: string;
134
+ time: number;
136
135
  }
137
136
 
138
137
  /**
@@ -142,9 +141,8 @@ export declare interface IIngestInterestRateRequest {
142
141
  export declare interface IIngestOHLCRequest {
143
142
  product_id: string;
144
143
  duration: string;
145
- limit?: number;
146
144
  direction: SeriesFetchDirection;
147
- time: string;
145
+ time: number;
148
146
  }
149
147
 
150
148
  /**
@@ -29,10 +29,9 @@ const schemaValidator = createValidator({
29
29
  },
30
30
  time: {
31
31
  type: 'object',
32
- required: ['type', 'format'],
32
+ required: ['type'],
33
33
  properties: {
34
- type: { type: 'string', const: 'string' },
35
- format: { type: 'string', const: 'date-time' },
34
+ type: { type: 'string', const: 'number' },
36
35
  },
37
36
  },
38
37
  },
@@ -91,7 +90,7 @@ export const provideInterestRateService = (terminal, metadata, fetchPage, servic
91
90
  properties: {
92
91
  product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
93
92
  direction: { const: metadata.direction },
94
- time: { type: 'string', format: 'date-time' },
93
+ time: { type: 'number' },
95
94
  },
96
95
  }, async (msg) => {
97
96
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAuB3C,MAAM,eAAe,GAAG,eAAe,CAAC;I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B,CAAC,CAAC;YAEJ,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;gBACzB,MAAM,UAAU,CACd,QAAQ,EACR,2BAA2B,CAAC,UAAU,EAAE,eAAe,EAAE;oBACvD,OAAO,EAAE,4BAA4B;oBACrC,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;iBAC1C,CAAC,CACH,CAAC;aACH;YAED,MAAM,KAAK,GAAG,4BAA4B,CAAC,UAAU,CAAC,CAAC;YACvD,IAAI,KAAK,EAAE;gBACT,MAAM,UAAU,CACd,QAAQ,EACR,2BAA2B,CACzB;oBACE;wBACE,SAAS;wBACT,UAAU,EAAE,eAAe;wBAC3B,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;qBACzB;iBACF,EACD,mBAAmB,EACnB;oBACE,OAAO,EAAE,CAAC,WAAW,EAAE,YAAY,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","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"]}
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAsB3C,MAAM,eAAe,GAAG,eAAe,CAAC;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;oBACd,QAAQ,EAAE,CAAC,OAAO,CAAC;oBACnB,UAAU,EAAE;wBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAA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AAO,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","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 direction: SeriesFetchDirection;\n time: number;\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'],\n properties: {\n type: { type: 'string', const: 'number' },\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: 'number' },\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"]}
@@ -7,7 +7,7 @@ describe('parseInterestRateServiceMetadataFromSchema', () => {
7
7
  properties: {
8
8
  product_id: { type: 'string', pattern: '^BINANCE/' },
9
9
  direction: { const: 'forward' },
10
- time: { type: 'string', format: 'date-time' },
10
+ time: { type: 'number' },
11
11
  },
12
12
  };
13
13
  const meta = parseInterestRateServiceMetadataFromSchema(schema);
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.test.js","sourceRoot":"","sources":["../src/interest_rate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0CAA0C,EAAE,MAAM,iBAAiB,CAAC;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,0CAA0C,CAAC,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,0CAA0C,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CACzE,sCAAsC,CACvC,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CAAC,0CAA0C,CAAC,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"]}
1
+ {"version":3,"file":"interest_rate.test.js","sourceRoot":"","sources":["../src/interest_rate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0CAA0C,EAAE,MAAM,iBAAiB,CAAC;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;aACzB;SACF,CAAC;QAEF,MAAM,IAAI,GAAG,0CAA0C,CAAC,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,0CAA0C,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CACzE,sCAAsC,CACvC,CAAC;QACF,MAAM,CAAC,GAAG,EAAE,CAAC,0CAA0C,CAAC,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: 'number' },\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/dist/ohlc.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createValidator } from '@yuants/protocol/lib/schema';
2
2
  import { buildInsertManyIntoTableSQL, requestSQL } from '@yuants/sql';
3
- import { encodePath } from '@yuants/utils';
3
+ import { encodePath, formatTime } from '@yuants/utils';
4
4
  import { newError } from '../../utils/lib';
5
5
  const schemaValidator = createValidator({
6
6
  type: 'object',
@@ -37,10 +37,9 @@ const schemaValidator = createValidator({
37
37
  },
38
38
  time: {
39
39
  type: 'object',
40
- required: ['type', 'format'],
40
+ required: ['type'],
41
41
  properties: {
42
- type: { type: 'string', const: 'string' },
43
- format: { type: 'string', const: 'date-time' },
42
+ type: { type: 'string', const: 'number' },
44
43
  },
45
44
  },
46
45
  },
@@ -111,12 +110,13 @@ export const provideOHLCService = (terminal, metadata, fetchPage, serviceOptions
111
110
  product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
112
111
  duration: { type: 'string', enum: metadata.duration_list },
113
112
  direction: { const: metadata.direction },
114
- time: { type: 'string', format: 'date-time' },
113
+ time: { type: 'number' },
115
114
  },
116
115
  }, async (msg) => {
117
116
  try {
118
117
  const series_id = encodePath(msg.req.product_id, msg.req.duration);
119
118
  const items = await fetchPage(Object.assign(Object.assign({}, msg.req), { series_id }));
119
+ console.info(formatTime(Date.now()), 'IngestOHLC', msg.req.product_id, msg.req.duration, 'fetched', items.length, 'bars');
120
120
  const normalized = items.map((x) => {
121
121
  var _a;
122
122
  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' }));
@@ -145,6 +145,7 @@ export const provideOHLCService = (terminal, metadata, fetchPage, serviceOptions
145
145
  }
146
146
  catch (error) {
147
147
  const message = error instanceof Error ? error.message : `${error}`;
148
+ console.error(formatTime(Date.now()), 'IngestOHLC error:', error);
148
149
  return { res: { code: 1, message } };
149
150
  }
150
151
  }, serviceOptions);
package/dist/ohlc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ohlc.js","sourceRoot":"","sources":["../src/ohlc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAyB3C,MAAM,eAAe,GAAG,eAAe,CAAC;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,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC;YACzD,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,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;oBAC1B,UAAU,EA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CAAC,EACD,cAAc,CACf,CAAC;AACJ,CAAC,CAAC","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"]}
1
+ {"version":3,"file":"ohlc.js","sourceRoot":"","sources":["../src/ohlc.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAwB3C,MAAM,eAAe,GAAG,eAAe,CAAC;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,IAA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E,KAAK,CAAC,QAAQ;qBACzB;iBACF,EACD,mBAAmB,EACnB;oBACE,OAAO,EAAE,CAAC,WAAW,EAAE,YAAY,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,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC;YAClE,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;SACtC;IACH,CAAC,EACD,cAAc,CACf,CAAC;AACJ,CAAC,CAAC","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, formatTime } 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 direction: SeriesFetchDirection;\n time: number;\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'],\n properties: {\n type: { type: 'string', const: 'number' },\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: 'number' },\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 console.info(\n formatTime(Date.now()),\n 'IngestOHLC',\n msg.req.product_id,\n msg.req.duration,\n 'fetched',\n items.length,\n 'bars',\n );\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 console.error(formatTime(Date.now()), 'IngestOHLC error:', error);\n return { res: { code: 1, message } };\n }\n },\n serviceOptions,\n );\n};\n"]}
package/dist/ohlc.test.js CHANGED
@@ -8,7 +8,7 @@ describe('parseOHLCServiceMetadataFromSchema', () => {
8
8
  product_id: { type: 'string', pattern: '^BINANCE/USDT-FUTURE' },
9
9
  duration: { type: 'string', enum: ['PT1M', 'PT5M'] },
10
10
  direction: { const: 'backward' },
11
- time: { type: 'string', format: 'date-time' },
11
+ time: { type: 'number' },
12
12
  },
13
13
  };
14
14
  const meta = parseOHLCServiceMetadataFromSchema(schema);
@@ -1 +1 @@
1
- {"version":3,"file":"ohlc.test.js","sourceRoot":"","sources":["../src/ohlc.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,QAAQ,CAAC;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,kCAAkC,CAAC,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,kCAAkC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;QACnG,MAAM,CAAC,GAAG,EAAE,CAAC,kCAAkC,CAAC,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"]}
1
+ {"version":3,"file":"ohlc.test.js","sourceRoot":"","sources":["../src/ohlc.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kCAAkC,EAAE,MAAM,QAAQ,CAAC;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;aACzB;SACF,CAAC;QAEF,MAAM,IAAI,GAAG,kCAAkC,CAAC,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,kCAAkC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC;QACnG,MAAM,CAAC,GAAG,EAAE,CAAC,kCAAkC,CAAC,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: 'number' },\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"]}
@@ -15,9 +15,8 @@ export interface IInterestRateServiceMetadata {
15
15
  */
16
16
  export interface IIngestInterestRateRequest {
17
17
  product_id: string;
18
- limit?: number;
19
18
  direction: SeriesFetchDirection;
20
- time: string;
19
+ time: number;
21
20
  }
22
21
  /**
23
22
  * @public
@@ -1 +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"}
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,SAAS,EAAE,oBAAoB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAuCD;;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"}
@@ -32,10 +32,9 @@ const schemaValidator = (0, schema_1.createValidator)({
32
32
  },
33
33
  time: {
34
34
  type: 'object',
35
- required: ['type', 'format'],
35
+ required: ['type'],
36
36
  properties: {
37
- type: { type: 'string', const: 'string' },
38
- format: { type: 'string', const: 'date-time' },
37
+ type: { type: 'string', const: 'number' },
39
38
  },
40
39
  },
41
40
  },
@@ -95,7 +94,7 @@ const provideInterestRateService = (terminal, metadata, fetchPage, serviceOption
95
94
  properties: {
96
95
  product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
97
96
  direction: { const: metadata.direction },
98
- time: { type: 'string', format: 'date-time' },
97
+ time: { type: 'number' },
99
98
  },
100
99
  }, async (msg) => {
101
100
  try {
@@ -1 +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;oBACd,QAAQ,EAAE,CAAC,OAAO,CAAC;oBACnB,UAAU,EAAE;wBACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,EAAE;qBACzD;iBACF;gBACD,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,CAAC,MAAM,EAAE,QA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K,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"]}
1
+ {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":";;;AAEA,wDAA8D;AAC9D,qCAAsE;AACtE,yCAA2C;AAC3C,yCAA2C;AAsB3C,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,IA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AG,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 direction: SeriesFetchDirection;\n time: number;\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'],\n properties: {\n type: { type: 'string', const: 'number' },\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: 'number' },\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"]}
@@ -9,7 +9,7 @@ describe('parseInterestRateServiceMetadataFromSchema', () => {
9
9
  properties: {
10
10
  product_id: { type: 'string', pattern: '^BINANCE/' },
11
11
  direction: { const: 'forward' },
12
- time: { type: 'string', format: 'date-time' },
12
+ time: { type: 'number' },
13
13
  },
14
14
  };
15
15
  const meta = (0, interest_rate_1.parseInterestRateServiceMetadataFromSchema)(schema);
@@ -1 +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"]}
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;aACzB;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: 'number' },\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 CHANGED
@@ -17,9 +17,8 @@ export interface IOHLCServiceMetadata {
17
17
  export interface IIngestOHLCRequest {
18
18
  product_id: string;
19
19
  duration: string;
20
- limit?: number;
21
20
  direction: SeriesFetchDirection;
22
- time: string;
21
+ time: number;
23
22
  }
24
23
  /**
25
24
  * @public
package/lib/ohlc.d.ts.map CHANGED
@@ -1 +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"}
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,SAAS,EAAE,oBAAoB,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AA+CD;;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;;CAgFjC,CAAC"}
package/lib/ohlc.js CHANGED
@@ -40,10 +40,9 @@ const schemaValidator = (0, schema_1.createValidator)({
40
40
  },
41
41
  time: {
42
42
  type: 'object',
43
- required: ['type', 'format'],
43
+ required: ['type'],
44
44
  properties: {
45
- type: { type: 'string', const: 'string' },
46
- format: { type: 'string', const: 'date-time' },
45
+ type: { type: 'string', const: 'number' },
47
46
  },
48
47
  },
49
48
  },
@@ -115,12 +114,13 @@ const provideOHLCService = (terminal, metadata, fetchPage, serviceOptions) => {
115
114
  product_id: { type: 'string', pattern: `^${metadata.product_id_prefix}` },
116
115
  duration: { type: 'string', enum: metadata.duration_list },
117
116
  direction: { const: metadata.direction },
118
- time: { type: 'string', format: 'date-time' },
117
+ time: { type: 'number' },
119
118
  },
120
119
  }, async (msg) => {
121
120
  try {
122
121
  const series_id = (0, utils_1.encodePath)(msg.req.product_id, msg.req.duration);
123
122
  const items = await fetchPage(Object.assign(Object.assign({}, msg.req), { series_id }));
123
+ console.info((0, utils_1.formatTime)(Date.now()), 'IngestOHLC', msg.req.product_id, msg.req.duration, 'fetched', items.length, 'bars');
124
124
  const normalized = items.map((x) => {
125
125
  var _a;
126
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' }));
@@ -149,6 +149,7 @@ const provideOHLCService = (terminal, metadata, fetchPage, serviceOptions) => {
149
149
  }
150
150
  catch (error) {
151
151
  const message = error instanceof Error ? error.message : `${error}`;
152
+ console.error((0, utils_1.formatTime)(Date.now()), 'IngestOHLC error:', error);
152
153
  return { res: { code: 1, message } };
153
154
  }
154
155
  }, serviceOptions);
package/lib/ohlc.js.map CHANGED
@@ -1 +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,EA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E,MAAM;wBAClB,UAAU,EAAE,KAAK,CAAC,UAAU;wBAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;qBACzB;iBACF,EACD,mBAAmB,EACnB;oBACE,OAAO,EAAE,CAAC,WAAW,EAAE,YAAY,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: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AE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;SACtC;IACH,CAAC,EACD,cAAc,CACf,CAAC;AACJ,CAAC,CAAC;AApFW,QAAA,kBAAkB,sBAoF7B","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, formatTime } 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 direction: SeriesFetchDirection;\n time: number;\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'],\n properties: {\n type: { type: 'string', const: 'number' },\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: 'number' },\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 console.info(\n formatTime(Date.now()),\n 'IngestOHLC',\n msg.req.product_id,\n msg.req.duration,\n 'fetched',\n items.length,\n 'bars',\n );\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 console.error(formatTime(Date.now()), 'IngestOHLC error:', error);\n return { res: { code: 1, message } };\n }\n },\n serviceOptions,\n );\n};\n"]}
package/lib/ohlc.test.js CHANGED
@@ -10,7 +10,7 @@ describe('parseOHLCServiceMetadataFromSchema', () => {
10
10
  product_id: { type: 'string', pattern: '^BINANCE/USDT-FUTURE' },
11
11
  duration: { type: 'string', enum: ['PT1M', 'PT5M'] },
12
12
  direction: { const: 'backward' },
13
- time: { type: 'string', format: 'date-time' },
13
+ time: { type: 'number' },
14
14
  },
15
15
  };
16
16
  const meta = (0, ohlc_1.parseOHLCServiceMetadataFromSchema)(schema);
@@ -1 +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"]}
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;aACzB;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: 'number' },\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/exchange",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "main": "lib/index.js",
5
5
  "module": "dist/index.js",
6
6
  "files": [
@@ -1091,33 +1091,6 @@
1091
1091
  "endIndex": 2
1092
1092
  }
1093
1093
  },
1094
- {
1095
- "kind": "PropertySignature",
1096
- "canonicalReference": "@yuants/exchange!IIngestInterestRateRequest#limit:member",
1097
- "docComment": "",
1098
- "excerptTokens": [
1099
- {
1100
- "kind": "Content",
1101
- "text": "limit?: "
1102
- },
1103
- {
1104
- "kind": "Content",
1105
- "text": "number"
1106
- },
1107
- {
1108
- "kind": "Content",
1109
- "text": ";"
1110
- }
1111
- ],
1112
- "isReadonly": false,
1113
- "isOptional": true,
1114
- "releaseTag": "Public",
1115
- "name": "limit",
1116
- "propertyTypeTokenRange": {
1117
- "startIndex": 1,
1118
- "endIndex": 2
1119
- }
1120
- },
1121
1094
  {
1122
1095
  "kind": "PropertySignature",
1123
1096
  "canonicalReference": "@yuants/exchange!IIngestInterestRateRequest#product_id:member",
@@ -1156,7 +1129,7 @@
1156
1129
  },
1157
1130
  {
1158
1131
  "kind": "Content",
1159
- "text": "string"
1132
+ "text": "number"
1160
1133
  },
1161
1134
  {
1162
1135
  "kind": "Content",
@@ -1244,33 +1217,6 @@
1244
1217
  "endIndex": 2
1245
1218
  }
1246
1219
  },
1247
- {
1248
- "kind": "PropertySignature",
1249
- "canonicalReference": "@yuants/exchange!IIngestOHLCRequest#limit:member",
1250
- "docComment": "",
1251
- "excerptTokens": [
1252
- {
1253
- "kind": "Content",
1254
- "text": "limit?: "
1255
- },
1256
- {
1257
- "kind": "Content",
1258
- "text": "number"
1259
- },
1260
- {
1261
- "kind": "Content",
1262
- "text": ";"
1263
- }
1264
- ],
1265
- "isReadonly": false,
1266
- "isOptional": true,
1267
- "releaseTag": "Public",
1268
- "name": "limit",
1269
- "propertyTypeTokenRange": {
1270
- "startIndex": 1,
1271
- "endIndex": 2
1272
- }
1273
- },
1274
1220
  {
1275
1221
  "kind": "PropertySignature",
1276
1222
  "canonicalReference": "@yuants/exchange!IIngestOHLCRequest#product_id:member",
@@ -1309,7 +1255,7 @@
1309
1255
  },
1310
1256
  {
1311
1257
  "kind": "Content",
1312
- "text": "string"
1258
+ "text": "number"
1313
1259
  },
1314
1260
  {
1315
1261
  "kind": "Content",
@@ -61,11 +61,9 @@ export interface IIngestInterestRateRequest {
61
61
  // (undocumented)
62
62
  direction: SeriesFetchDirection;
63
63
  // (undocumented)
64
- limit?: number;
65
- // (undocumented)
66
64
  product_id: string;
67
65
  // (undocumented)
68
- time: string;
66
+ time: number;
69
67
  }
70
68
 
71
69
  // @public
@@ -75,11 +73,9 @@ export interface IIngestOHLCRequest {
75
73
  // (undocumented)
76
74
  duration: string;
77
75
  // (undocumented)
78
- limit?: number;
79
- // (undocumented)
80
76
  product_id: string;
81
77
  // (undocumented)
82
- time: string;
78
+ time: number;
83
79
  }
84
80
 
85
81
  // @public
@@ -1,17 +1,17 @@
1
1
  {
2
- "libraries/exchange/CHANGELOG.json": "90f3fa915c71c18d5b684f0d62aeaf83b5e2d932",
3
- "libraries/exchange/CHANGELOG.md": "bad0c3f012539c7861affce27b525be7aab5b10b",
2
+ "libraries/exchange/CHANGELOG.json": "39f1e7f93fcc64bffdf5d847eded0aac63cb7d1d",
3
+ "libraries/exchange/CHANGELOG.md": "98e7e849c1adfd6e19c53a5bbde6ee04fa39ee22",
4
4
  "libraries/exchange/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
5
5
  "libraries/exchange/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
6
6
  "libraries/exchange/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
7
7
  "libraries/exchange/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
8
- "libraries/exchange/etc/exchange.api.md": "89e77701ff5e9f8a2d2887fb2ab3e254e60bcd8f",
9
- "libraries/exchange/package.json": "e4eb91d1edc7a0fc36079607b318a10350181108",
8
+ "libraries/exchange/etc/exchange.api.md": "5cbfbfb185ea230234d254b34a778ee25073ac3c",
9
+ "libraries/exchange/package.json": "1e5a3beb25f3829b2de5cf7f7d6a85f7c5bea857",
10
10
  "libraries/exchange/src/index.ts": "3eb2b464a88063b8730b8d7f671553bfdfc88ce6",
11
- "libraries/exchange/src/interest_rate.test.ts": "027f0951ad0b6f105d35febc82c1576a90e36e5c",
12
- "libraries/exchange/src/interest_rate.ts": "0483754b034d5e57e70a144dc3b18eae2bebeaea",
13
- "libraries/exchange/src/ohlc.test.ts": "5a18e54c22a76d58a79570a3e24487901853ec51",
14
- "libraries/exchange/src/ohlc.ts": "0fb0bb321a180f10889e7e6e5a1bf4ccb1eaae5d",
11
+ "libraries/exchange/src/interest_rate.test.ts": "9197fe2ace778d3dd6ef6043926d776abf21ab89",
12
+ "libraries/exchange/src/interest_rate.ts": "58ca713ccbaccaef478f35149695220f1c97bef5",
13
+ "libraries/exchange/src/ohlc.test.ts": "975b880372c2c608d09944a37e294244bd6e488b",
14
+ "libraries/exchange/src/ohlc.ts": "7f9a7a80d75b0e1421866e47b47f0cc739bc83f1",
15
15
  "libraries/exchange/src/quote.test.ts": "2d50be70e6a924498719ad4fe940e0b95d0dfa09",
16
16
  "libraries/exchange/src/quote.ts": "663393e8f22b1e11f675e05f6d3c19d06862366e",
17
17
  "libraries/exchange/src/types.ts": "302d5383c38c053ac2ea8fac028b9d4921f1abe0",