chart data loading
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Kafka producer for writing market data
|
||||
import { Kafka } from 'kafkajs';
|
||||
import { encodeMessage, MessageTypeId, Tick, OHLC, OHLCBatch } from './proto/messages.js';
|
||||
import { encodeMessage, MessageTypeId, Tick, OHLC, OHLCBatch, Market } from './proto/messages.js';
|
||||
|
||||
export class KafkaProducer {
|
||||
constructor(config, logger) {
|
||||
@@ -257,6 +257,41 @@ export class KafkaProducer {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write market metadata messages to Kafka
|
||||
* @param {string} topic - Kafka topic name
|
||||
* @param {Array<object>} messages - Array of {key, value} objects where value is Market metadata
|
||||
*/
|
||||
async writeMarketMetadata(topic, messages) {
|
||||
if (!this.isConnected) {
|
||||
throw new Error('Kafka producer not connected');
|
||||
}
|
||||
|
||||
if (messages.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const kafkaMessages = messages.map(({ key, value }) => {
|
||||
const [frame1, frame2] = encodeMessage(MessageTypeId.MARKET, value, Market);
|
||||
const encodedValue = Buffer.concat([frame1, frame2]);
|
||||
|
||||
return {
|
||||
key,
|
||||
value: encodedValue
|
||||
};
|
||||
});
|
||||
|
||||
await this.producer.send({
|
||||
topic,
|
||||
messages: kafkaMessages
|
||||
});
|
||||
|
||||
this.logger.debug(
|
||||
{ count: messages.length, topic },
|
||||
'Wrote market metadata to Kafka'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from Kafka
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user