@yuants/exchange 0.8.8 → 0.8.10

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.
@@ -1,3 +1,4 @@
1
+ import { IInterestLedger } from '@yuants/data-interest-rate';
1
2
  import { IInterestRate } from '@yuants/data-interest-rate';
2
3
  import { IOHLC } from '@yuants/data-ohlc';
3
4
  import { IOrder } from '@yuants/data-order';
@@ -124,6 +125,18 @@ export declare interface IExchange<T = any> {
124
125
  cancelOrder(credential: T, order: IOrder): Promise<void>;
125
126
  }
126
127
 
128
+ declare interface IExchangeCredential {
129
+ type: string;
130
+ payload: any;
131
+ }
132
+
133
+ declare interface IIngestInterestLedgerRequest {
134
+ credential: IExchangeCredential;
135
+ account_id: string;
136
+ time: number;
137
+ ledger_type: string;
138
+ }
139
+
127
140
  /**
128
141
  * Interest Rate Service Request from VEX to Vendor
129
142
  * @public
@@ -263,6 +276,16 @@ export declare const parseQuoteServiceMetadataFromSchema: (schema: any) => IQuot
263
276
  */
264
277
  export declare const provideExchangeServices: <T>(terminal: Terminal, exchange: IExchange<T>) => void;
265
278
 
279
+ /**
280
+ * @public
281
+ */
282
+ export declare const provideInterestLedgerService: (terminal: Terminal, metadata: {
283
+ direction: string;
284
+ type: string;
285
+ }, fetchPage: (request: IIngestInterestLedgerRequest) => Promise<IInterestLedger[]>, serviceOptions?: IServiceOptions) => {
286
+ dispose: () => void;
287
+ };
288
+
266
289
  /**
267
290
  * @public
268
291
  */
@@ -140,4 +140,79 @@ export const provideInterestRateService = (terminal, metadata, fetchPage, servic
140
140
  }
141
141
  }, serviceOptions);
142
142
  };
143
+ const INTEREST_RATE_LEDGER_INSERT_COLUMNS = [
144
+ 'created_at',
145
+ 'product_id',
146
+ 'account_id',
147
+ 'amount',
148
+ 'currency',
149
+ 'id',
150
+ ];
151
+ /**
152
+ * @public
153
+ */
154
+ export const provideInterestLedgerService = (terminal, metadata, fetchPage, serviceOptions) => {
155
+ return terminal.server.provideService('IngestInterestLedger', {
156
+ type: 'object',
157
+ required: ['account_id', 'direction', 'time', 'credential', 'ledger_type'],
158
+ properties: {
159
+ account_id: { type: 'string', pattern: `^${metadata.type}` },
160
+ direction: { const: metadata.direction },
161
+ time: { type: 'number' },
162
+ ledger_type: { type: 'string' },
163
+ credential: {
164
+ type: 'object',
165
+ required: ['type', 'payload'],
166
+ properties: {
167
+ type: { type: 'string', const: metadata.type },
168
+ payload: { type: 'object' },
169
+ },
170
+ },
171
+ },
172
+ }, async (msg) => {
173
+ try {
174
+ const interestRateLedgers = await fetchPage(Object.assign({}, msg.req));
175
+ const range = computeInterestRatePageRange(interestRateLedgers);
176
+ // Atomic write: data rows + series_data_range in the same statement.
177
+ if (interestRateLedgers.length > 0 && range) {
178
+ const writeInterestRate = `${buildInsertManyIntoTableSQL(interestRateLedgers, 'interest_rate_ledger', {
179
+ columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,
180
+ conflictKeys: ['id'],
181
+ })} RETURNING 1`;
182
+ const writeRange = `${buildInsertManyIntoTableSQL([
183
+ {
184
+ series_id: msg.req.account_id,
185
+ table_name: 'interest_rate_ledger',
186
+ start_time: range.start_time,
187
+ end_time: range.end_time,
188
+ },
189
+ ], 'series_data_range', {
190
+ columns: ['series_id', 'table_name', 'start_time', 'end_time'],
191
+ ignoreConflict: true,
192
+ })} RETURNING 1`;
193
+ await requestSQL(terminal, `
194
+ WITH
195
+ write_interest_rate_ledger AS (
196
+ ${writeInterestRate}
197
+ ),
198
+ write_range AS (
199
+ ${writeRange}
200
+ )
201
+ SELECT 1 as ok;
202
+ `);
203
+ }
204
+ else if (interestRateLedgers.length > 0) {
205
+ await requestSQL(terminal, buildInsertManyIntoTableSQL(interestRateLedgers, 'interest_rate_ledger', {
206
+ columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,
207
+ conflictKeys: ['id'],
208
+ }));
209
+ }
210
+ return { res: { code: 0, message: 'OK', data: { wrote_count: interestRateLedgers.length, range } } };
211
+ }
212
+ catch (error) {
213
+ const message = error instanceof Error ? error.message : `${error}`;
214
+ return { res: { code: 1, message } };
215
+ }
216
+ }, serviceOptions);
217
+ };
143
218
  //# sourceMappingURL=interest_rate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAiB,MAAM,4BAA4B,CAAC;AAEvF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtE,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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BACvD,OAAO,EAAE,4BAA4B;oBACrC,YAAY,EAAE,CAAC,WAAW,EAAE,YAAY,CAAC;iBAC1C,CAAC,CACH,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 { encodeInterestRateSeriesId, 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 { 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 = encodeInterestRateSeriesId(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 const range = computeInterestRatePageRange(normalized);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (normalized.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(normalized, 'interest_rate', {\n columns: INTEREST_RATE_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n })} RETURNING 1`;\n\n const writeRange = `${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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else 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 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":"AAAA,OAAO,EAAE,0BAA0B,EAAkC,MAAM,4BAA4B,CAAC;AAExG,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,2BAA2B,EAAE,UAAU,EAAE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;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 { encodeInterestRateSeriesId, IInterestRate, IInterestLedger } 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 { newError } from '../../utils/lib';\nimport { ISeriesIngestResult, SeriesFetchDirection } from './types';\nimport { IExchange } from '.';\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 | IInterestLedger)[],\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 = encodeInterestRateSeriesId(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 const range = computeInterestRatePageRange(normalized);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (normalized.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(normalized, 'interest_rate', {\n columns: INTEREST_RATE_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n })} RETURNING 1`;\n\n const writeRange = `${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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else 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 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};\ninterface IExchangeCredential {\n type: string;\n payload: any;\n}\n\ninterface IIngestInterestLedgerRequest {\n credential: IExchangeCredential;\n account_id: string;\n time: number;\n ledger_type: string;\n}\n\nconst INTEREST_RATE_LEDGER_INSERT_COLUMNS: Array<keyof IInterestLedger> = [\n 'created_at',\n 'product_id',\n 'account_id',\n 'amount',\n 'currency',\n 'id',\n];\n\n/**\n * @public\n */\nexport const provideInterestLedgerService = (\n terminal: Terminal,\n metadata: { direction: string; type: string },\n fetchPage: (request: IIngestInterestLedgerRequest) => Promise<IInterestLedger[]>,\n serviceOptions?: IServiceOptions,\n) => {\n return terminal.server.provideService<IIngestInterestLedgerRequest, ISeriesIngestResult>(\n 'IngestInterestLedger',\n {\n type: 'object',\n required: ['account_id', 'direction', 'time', 'credential', 'ledger_type'],\n properties: {\n account_id: { type: 'string', pattern: `^${metadata.type}` },\n direction: { const: metadata.direction },\n time: { type: 'number' },\n ledger_type: { type: 'string' },\n credential: {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string', const: metadata.type },\n payload: { type: 'object' },\n },\n },\n },\n },\n async (msg) => {\n try {\n const interestRateLedgers = await fetchPage({ ...msg.req });\n const range = computeInterestRatePageRange(interestRateLedgers);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (interestRateLedgers.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(\n interestRateLedgers,\n 'interest_rate_ledger',\n {\n columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,\n conflictKeys: ['id'],\n },\n )} RETURNING 1`;\n\n const writeRange = `${buildInsertManyIntoTableSQL(\n [\n {\n series_id: msg.req.account_id,\n table_name: 'interest_rate_ledger',\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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate_ledger AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else if (interestRateLedgers.length > 0) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(interestRateLedgers, 'interest_rate_ledger', {\n columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,\n conflictKeys: ['id'],\n }),\n );\n }\n\n return { res: { code: 0, message: 'OK', data: { wrote_count: interestRateLedgers.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,4 +1,4 @@
1
- import { IInterestRate } from '@yuants/data-interest-rate';
1
+ import { IInterestRate, IInterestLedger } from '@yuants/data-interest-rate';
2
2
  import { IServiceOptions, Terminal } from '@yuants/protocol';
3
3
  import { SeriesFetchDirection } from './types';
4
4
  /**
@@ -30,4 +30,24 @@ export declare const provideInterestRateService: (terminal: Terminal, metadata:
30
30
  }) => Promise<IInterestRate[]>, serviceOptions?: IServiceOptions) => {
31
31
  dispose: () => void;
32
32
  };
33
+ interface IExchangeCredential {
34
+ type: string;
35
+ payload: any;
36
+ }
37
+ interface IIngestInterestLedgerRequest {
38
+ credential: IExchangeCredential;
39
+ account_id: string;
40
+ time: number;
41
+ ledger_type: string;
42
+ }
43
+ /**
44
+ * @public
45
+ */
46
+ export declare const provideInterestLedgerService: (terminal: Terminal, metadata: {
47
+ direction: string;
48
+ type: string;
49
+ }, fetchPage: (request: IIngestInterestLedgerRequest) => Promise<IInterestLedger[]>, serviceOptions?: IServiceOptions) => {
50
+ dispose: () => void;
51
+ };
52
+ export {};
33
53
  //# sourceMappingURL=interest_rate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.d.ts","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI7D,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,MAA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AE,CAAC,mBAC/D,eAAe;;CAqFjC,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.provideInterestRateService = exports.parseInterestRateServiceMetadataFromSchema = void 0;
3
+ exports.provideInterestLedgerService = exports.provideInterestRateService = exports.parseInterestRateServiceMetadataFromSchema = void 0;
4
4
  const data_interest_rate_1 = require("@yuants/data-interest-rate");
5
5
  const schema_1 = require("@yuants/protocol/lib/schema");
6
6
  const sql_1 = require("@yuants/sql");
@@ -145,4 +145,80 @@ const provideInterestRateService = (terminal, metadata, fetchPage, serviceOption
145
145
  }, serviceOptions);
146
146
  };
147
147
  exports.provideInterestRateService = provideInterestRateService;
148
+ const INTEREST_RATE_LEDGER_INSERT_COLUMNS = [
149
+ 'created_at',
150
+ 'product_id',
151
+ 'account_id',
152
+ 'amount',
153
+ 'currency',
154
+ 'id',
155
+ ];
156
+ /**
157
+ * @public
158
+ */
159
+ const provideInterestLedgerService = (terminal, metadata, fetchPage, serviceOptions) => {
160
+ return terminal.server.provideService('IngestInterestLedger', {
161
+ type: 'object',
162
+ required: ['account_id', 'direction', 'time', 'credential', 'ledger_type'],
163
+ properties: {
164
+ account_id: { type: 'string', pattern: `^${metadata.type}` },
165
+ direction: { const: metadata.direction },
166
+ time: { type: 'number' },
167
+ ledger_type: { type: 'string' },
168
+ credential: {
169
+ type: 'object',
170
+ required: ['type', 'payload'],
171
+ properties: {
172
+ type: { type: 'string', const: metadata.type },
173
+ payload: { type: 'object' },
174
+ },
175
+ },
176
+ },
177
+ }, async (msg) => {
178
+ try {
179
+ const interestRateLedgers = await fetchPage(Object.assign({}, msg.req));
180
+ const range = computeInterestRatePageRange(interestRateLedgers);
181
+ // Atomic write: data rows + series_data_range in the same statement.
182
+ if (interestRateLedgers.length > 0 && range) {
183
+ const writeInterestRate = `${(0, sql_1.buildInsertManyIntoTableSQL)(interestRateLedgers, 'interest_rate_ledger', {
184
+ columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,
185
+ conflictKeys: ['id'],
186
+ })} RETURNING 1`;
187
+ const writeRange = `${(0, sql_1.buildInsertManyIntoTableSQL)([
188
+ {
189
+ series_id: msg.req.account_id,
190
+ table_name: 'interest_rate_ledger',
191
+ start_time: range.start_time,
192
+ end_time: range.end_time,
193
+ },
194
+ ], 'series_data_range', {
195
+ columns: ['series_id', 'table_name', 'start_time', 'end_time'],
196
+ ignoreConflict: true,
197
+ })} RETURNING 1`;
198
+ await (0, sql_1.requestSQL)(terminal, `
199
+ WITH
200
+ write_interest_rate_ledger AS (
201
+ ${writeInterestRate}
202
+ ),
203
+ write_range AS (
204
+ ${writeRange}
205
+ )
206
+ SELECT 1 as ok;
207
+ `);
208
+ }
209
+ else if (interestRateLedgers.length > 0) {
210
+ await (0, sql_1.requestSQL)(terminal, (0, sql_1.buildInsertManyIntoTableSQL)(interestRateLedgers, 'interest_rate_ledger', {
211
+ columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,
212
+ conflictKeys: ['id'],
213
+ }));
214
+ }
215
+ return { res: { code: 0, message: 'OK', data: { wrote_count: interestRateLedgers.length, range } } };
216
+ }
217
+ catch (error) {
218
+ const message = error instanceof Error ? error.message : `${error}`;
219
+ return { res: { code: 1, message } };
220
+ }
221
+ }, serviceOptions);
222
+ };
223
+ exports.provideInterestLedgerService = provideInterestLedgerService;
148
224
  //# sourceMappingURL=interest_rate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"interest_rate.js","sourceRoot":"","sources":["../src/interest_rate.ts"],"names":[],"mappings":";;;AAAA,mEAAuF;AAEvF,wDAA8D;AAC9D,qCAAsE;AACtE,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,QA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QAAA,0BAA0B,8BAsFrC","sourcesContent":["import { encodeInterestRateSeriesId, 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 { 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 = encodeInterestRateSeriesId(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 const range = computeInterestRatePageRange(normalized);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (normalized.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(normalized, 'interest_rate', {\n columns: INTEREST_RATE_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n })} RETURNING 1`;\n\n const writeRange = `${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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else 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 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":";;;AAAA,mEAAwG;AAExG,wDAA8D;AAC9D,qCAAsE;AACtE,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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,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,CAAC;oBAC9D,cAAc,EAAE,IAAI;iBACrB,CACF,cAAc,CAAC;gBAEhB,MAAM,IAAA,gBAAU,EACd,QAAQ,EACR;;;kBAGM,iBAAiB;;;kBAGjB,UAAU;;;aAGf,CACF,CAAC;aACH;iBAAM,IAAI,mBAAmB,CAAC,MAAM,GAAG,CAAC,EAAE;gBACzC,MAAM,IAAA,gBAAU,EACd,QAAQ,EACR,IAAA,iCAA2B,EAAC,mBAAmB,EAAE,sBAAsB,EAAE;oBACvE,OAAO,EAAE,mCAAmC;oBAC5C,YAAY,EAAE,CAAC,IAAI,CAAC;iBACrB,CAAC,CACH,CAAC;aACH;YAED,OAAO,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;SACtG;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;AAzFW,QAAA,4BAA4B,gCAyFvC","sourcesContent":["import { encodeInterestRateSeriesId, IInterestRate, IInterestLedger } 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 { newError } from '../../utils/lib';\nimport { ISeriesIngestResult, SeriesFetchDirection } from './types';\nimport { IExchange } from '.';\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 | IInterestLedger)[],\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 = encodeInterestRateSeriesId(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 const range = computeInterestRatePageRange(normalized);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (normalized.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(normalized, 'interest_rate', {\n columns: INTEREST_RATE_INSERT_COLUMNS,\n conflictKeys: ['series_id', 'created_at'],\n })} RETURNING 1`;\n\n const writeRange = `${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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else 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 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};\ninterface IExchangeCredential {\n type: string;\n payload: any;\n}\n\ninterface IIngestInterestLedgerRequest {\n credential: IExchangeCredential;\n account_id: string;\n time: number;\n ledger_type: string;\n}\n\nconst INTEREST_RATE_LEDGER_INSERT_COLUMNS: Array<keyof IInterestLedger> = [\n 'created_at',\n 'product_id',\n 'account_id',\n 'amount',\n 'currency',\n 'id',\n];\n\n/**\n * @public\n */\nexport const provideInterestLedgerService = (\n terminal: Terminal,\n metadata: { direction: string; type: string },\n fetchPage: (request: IIngestInterestLedgerRequest) => Promise<IInterestLedger[]>,\n serviceOptions?: IServiceOptions,\n) => {\n return terminal.server.provideService<IIngestInterestLedgerRequest, ISeriesIngestResult>(\n 'IngestInterestLedger',\n {\n type: 'object',\n required: ['account_id', 'direction', 'time', 'credential', 'ledger_type'],\n properties: {\n account_id: { type: 'string', pattern: `^${metadata.type}` },\n direction: { const: metadata.direction },\n time: { type: 'number' },\n ledger_type: { type: 'string' },\n credential: {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string', const: metadata.type },\n payload: { type: 'object' },\n },\n },\n },\n },\n async (msg) => {\n try {\n const interestRateLedgers = await fetchPage({ ...msg.req });\n const range = computeInterestRatePageRange(interestRateLedgers);\n\n // Atomic write: data rows + series_data_range in the same statement.\n if (interestRateLedgers.length > 0 && range) {\n const writeInterestRate = `${buildInsertManyIntoTableSQL(\n interestRateLedgers,\n 'interest_rate_ledger',\n {\n columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,\n conflictKeys: ['id'],\n },\n )} RETURNING 1`;\n\n const writeRange = `${buildInsertManyIntoTableSQL(\n [\n {\n series_id: msg.req.account_id,\n table_name: 'interest_rate_ledger',\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 )} RETURNING 1`;\n\n await requestSQL(\n terminal,\n `\n WITH\n write_interest_rate_ledger AS (\n ${writeInterestRate}\n ),\n write_range AS (\n ${writeRange}\n )\n SELECT 1 as ok;\n `,\n );\n } else if (interestRateLedgers.length > 0) {\n await requestSQL(\n terminal,\n buildInsertManyIntoTableSQL(interestRateLedgers, 'interest_rate_ledger', {\n columns: INTEREST_RATE_LEDGER_INSERT_COLUMNS,\n conflictKeys: ['id'],\n }),\n );\n }\n\n return { res: { code: 0, message: 'OK', data: { wrote_count: interestRateLedgers.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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuants/exchange",
3
- "version": "0.8.8",
3
+ "version": "0.8.10",
4
4
  "main": "lib/index.js",
5
5
  "module": "dist/index.js",
6
6
  "files": [
@@ -24,16 +24,16 @@
24
24
  "typescript": "~4.7.4"
25
25
  },
26
26
  "dependencies": {
27
- "@yuants/protocol": "0.53.9",
28
- "@yuants/data-account": "0.11.6",
29
- "@yuants/data-order": "0.7.7",
30
- "@yuants/data-product": "0.5.7",
31
- "@yuants/data-quote": "0.4.6",
32
- "@yuants/data-ohlc": "0.6.2",
33
- "@yuants/data-interest-rate": "0.2.5",
34
- "@yuants/cache": "0.3.10",
35
- "@yuants/sql": "0.9.37",
36
- "@yuants/utils": "0.19.2",
27
+ "@yuants/protocol": "0.54.0",
28
+ "@yuants/data-account": "0.11.7",
29
+ "@yuants/data-order": "0.7.8",
30
+ "@yuants/data-product": "0.5.8",
31
+ "@yuants/data-quote": "0.4.7",
32
+ "@yuants/data-ohlc": "0.6.3",
33
+ "@yuants/data-interest-rate": "0.2.7",
34
+ "@yuants/cache": "0.3.11",
35
+ "@yuants/sql": "0.9.38",
36
+ "@yuants/utils": "0.19.3",
37
37
  "rxjs": "~7.5.6"
38
38
  },
39
39
  "scripts": {
@@ -2076,6 +2076,73 @@
2076
2076
  "endIndex": 6
2077
2077
  }
2078
2078
  },
2079
+ {
2080
+ "kind": "Variable",
2081
+ "canonicalReference": "@yuants/exchange!provideInterestLedgerService:var",
2082
+ "docComment": "/**\n * @public\n */\n",
2083
+ "excerptTokens": [
2084
+ {
2085
+ "kind": "Content",
2086
+ "text": "provideInterestLedgerService: "
2087
+ },
2088
+ {
2089
+ "kind": "Content",
2090
+ "text": "(terminal: "
2091
+ },
2092
+ {
2093
+ "kind": "Reference",
2094
+ "text": "Terminal",
2095
+ "canonicalReference": "@yuants/protocol!Terminal:class"
2096
+ },
2097
+ {
2098
+ "kind": "Content",
2099
+ "text": ", metadata: {\n direction: string;\n type: string;\n}, fetchPage: (request: "
2100
+ },
2101
+ {
2102
+ "kind": "Reference",
2103
+ "text": "IIngestInterestLedgerRequest",
2104
+ "canonicalReference": "@yuants/exchange!~IIngestInterestLedgerRequest:interface"
2105
+ },
2106
+ {
2107
+ "kind": "Content",
2108
+ "text": ") => "
2109
+ },
2110
+ {
2111
+ "kind": "Reference",
2112
+ "text": "Promise",
2113
+ "canonicalReference": "!Promise:interface"
2114
+ },
2115
+ {
2116
+ "kind": "Content",
2117
+ "text": "<"
2118
+ },
2119
+ {
2120
+ "kind": "Reference",
2121
+ "text": "IInterestLedger",
2122
+ "canonicalReference": "@yuants/data-interest-rate!IInterestLedger:interface"
2123
+ },
2124
+ {
2125
+ "kind": "Content",
2126
+ "text": "[]>, serviceOptions?: "
2127
+ },
2128
+ {
2129
+ "kind": "Reference",
2130
+ "text": "IServiceOptions",
2131
+ "canonicalReference": "@yuants/protocol!IServiceOptions:interface"
2132
+ },
2133
+ {
2134
+ "kind": "Content",
2135
+ "text": ") => {\n dispose: () => void;\n}"
2136
+ }
2137
+ ],
2138
+ "isReadonly": true,
2139
+ "releaseTag": "Public",
2140
+ "name": "provideInterestLedgerService",
2141
+ "variableTypeTokenRange": {
2142
+ "startIndex": 1,
2143
+ "endIndex": 12
2144
+ }
2145
+ },
2079
2146
  {
2080
2147
  "kind": "Variable",
2081
2148
  "canonicalReference": "@yuants/exchange!provideInterestRateService:var",
@@ -4,6 +4,7 @@
4
4
 
5
5
  ```ts
6
6
 
7
+ import { IInterestLedger } from '@yuants/data-interest-rate';
7
8
  import { IInterestRate } from '@yuants/data-interest-rate';
8
9
  import { IOHLC } from '@yuants/data-ohlc';
9
10
  import { IOrder } from '@yuants/data-order';
@@ -152,6 +153,16 @@ export const parseQuoteServiceMetadataFromSchema: (schema: any) => IQuoteService
152
153
  // @public
153
154
  export const provideExchangeServices: <T>(terminal: Terminal, exchange: IExchange<T>) => void;
154
155
 
156
+ // Warning: (ae-forgotten-export) The symbol "IIngestInterestLedgerRequest" needs to be exported by the entry point index.d.ts
157
+ //
158
+ // @public (undocumented)
159
+ export const provideInterestLedgerService: (terminal: Terminal, metadata: {
160
+ direction: string;
161
+ type: string;
162
+ }, fetchPage: (request: IIngestInterestLedgerRequest) => Promise<IInterestLedger[]>, serviceOptions?: IServiceOptions) => {
163
+ dispose: () => void;
164
+ };
165
+
155
166
  // @public (undocumented)
156
167
  export const provideInterestRateService: (terminal: Terminal, metadata: IInterestRateServiceMetadata, fetchPage: (request: IIngestInterestRateRequest & {
157
168
  series_id: string;
@@ -1,15 +1,15 @@
1
1
  {
2
- "libraries/exchange/CHANGELOG.json": "aa5a9e895727a43d13fed07ce0bf1b153bc519fb",
3
- "libraries/exchange/CHANGELOG.md": "d4fe2867ca6e7e04c12423d95217a507ea2a79ca",
2
+ "libraries/exchange/CHANGELOG.json": "9b1e6596ce544cd825e9363c37aba7be8eb4b82c",
3
+ "libraries/exchange/CHANGELOG.md": "92142343e214f80d9e29b5f4e3736a03992ff2a3",
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": "5cbfbfb185ea230234d254b34a778ee25073ac3c",
9
- "libraries/exchange/package.json": "b7f661efdca393d7d871e4cbe476729ebcf165d6",
8
+ "libraries/exchange/etc/exchange.api.md": "1a1f98e9a5a5da1d843f93ebb306002db17cd727",
9
+ "libraries/exchange/package.json": "68942f925b46187dcb84e783b8a054cac48a0b70",
10
10
  "libraries/exchange/src/index.ts": "3eb2b464a88063b8730b8d7f671553bfdfc88ce6",
11
11
  "libraries/exchange/src/interest_rate.test.ts": "9197fe2ace778d3dd6ef6043926d776abf21ab89",
12
- "libraries/exchange/src/interest_rate.ts": "f8eb61acc74cb16f30c98ecd382b877eb74f49f3",
12
+ "libraries/exchange/src/interest_rate.ts": "4da86155815f61446d8f1556b5c9273b6ba5d505",
13
13
  "libraries/exchange/src/ohlc.test.ts": "975b880372c2c608d09944a37e294244bd6e488b",
14
14
  "libraries/exchange/src/ohlc.ts": "32d5dbcdcac255a043a93bb62cdec955ac5b01bd",
15
15
  "libraries/exchange/src/quote.test.ts": "2d50be70e6a924498719ad4fe940e0b95d0dfa09",
@@ -17,15 +17,15 @@
17
17
  "libraries/exchange/src/types.ts": "302d5383c38c053ac2ea8fac028b9d4921f1abe0",
18
18
  "libraries/exchange/tsconfig.json": "22f94ca28b507f8ddcc21b9053158eefd3f726a9",
19
19
  "libraries/exchange/.rush/temp/shrinkwrap-deps.json": "75a385701243e189b795559fc82d660f1a355805",
20
- "libraries/protocol/temp/package-deps.json": "fd1828e035a9220017e8951f15d3e4c270e3bc27",
21
- "libraries/data-account/temp/package-deps.json": "cf6d3133b4b3a93ccfed2cfa4b14d4da7ac04111",
22
- "libraries/data-order/temp/package-deps.json": "f31827d78049ac4040cf415f01faac3889189cca",
23
- "libraries/data-product/temp/package-deps.json": "d3c612cf501f32013535b950722ee5ca862c5c06",
24
- "libraries/data-quote/temp/package-deps.json": "0982e538459436994f54ff82826cd8115996c25e",
25
- "libraries/data-ohlc/temp/package-deps.json": "39961506c9620c65688fd33c1800fb05717fa219",
26
- "libraries/data-interest-rate/temp/package-deps.json": "8f63147e58f0d59bfd144a7af59e818d91f1ccac",
27
- "libraries/cache/temp/package-deps.json": "5e819d4f6b881137398de0d7e660d4abb4724264",
28
- "libraries/sql/temp/package-deps.json": "a60ef2dc3b11a2ce34e10d4f75d8f0a954e9dde5",
29
- "libraries/utils/temp/package-deps.json": "b75dc3605259796139482beb655374c86fcb639d",
20
+ "libraries/protocol/temp/package-deps.json": "f9ac8a0412f63d53f93ce189a390eab4a74b772b",
21
+ "libraries/data-account/temp/package-deps.json": "0b428e3b8643b117276ebe0f29428d5686526d4a",
22
+ "libraries/data-order/temp/package-deps.json": "751f5b506c10f57ca17960dd9af22c465c77c6de",
23
+ "libraries/data-product/temp/package-deps.json": "0eee98e9df8a5aa401aa1e87cefa141630973535",
24
+ "libraries/data-quote/temp/package-deps.json": "ad175d5009b9c8a1a0d590bd8b9f5210e48ef61a",
25
+ "libraries/data-ohlc/temp/package-deps.json": "d746fd7cc4964310a4f239d6c59538e7562d537a",
26
+ "libraries/data-interest-rate/temp/package-deps.json": "4c9d3f2fe8c1f209de2039367832df81a410408b",
27
+ "libraries/cache/temp/package-deps.json": "39ebfb1d8a15e6341c4902a0954985d469597125",
28
+ "libraries/sql/temp/package-deps.json": "d1a7297dec9849184bda8843800beae36c6b1f09",
29
+ "libraries/utils/temp/package-deps.json": "16ee87f512cd903d59f2ce9935be22e5ed6d03a1",
30
30
  "tools/toolkit/temp/package-deps.json": "23e053490eb8feade23e4d45de4e54883e322711"
31
31
  }