fixparser
Version:
FIX.Latest / 5.0 SP2 Parser / AI Agent Trading
183 lines (182 loc) • 6.71 kB
TypeScript
import type { KeyObject } from 'node:tls';
import type { IMessageStore } from 'fixparser-common';
import type { ProxyAgent } from 'proxy-agent';
import type { FIXParser } from './FIXParser.ts';
import type { ConnectionType, FIXParserBase, Options as FIXParserOptions, Protocol } from './FIXParserBase.ts';
import type { Options as FIXParserBrowserOptions } from './FIXParserBrowser.ts';
import type { Field } from './fields/Field.ts';
import type { Logger } from './logger/Logger.ts';
import type { Message } from './message/Message.ts';
import type { Parser } from './util/util.ts';
/**
* Interface defining the core functionality for FIX protocol communication.
* This interface is implemented by various FIX parser classes to provide consistent
* FIX protocol handling across different environments (browser, server, etc.).
*/
export interface IFIXParser {
host: string | undefined;
port: number | undefined;
protocol: Protocol | undefined;
sender: string | undefined;
target: string | undefined;
heartBeatInterval: number;
fixVersion: string;
connectionType: ConnectionType;
parserName: Parser;
fixParserBase?: FIXParserBase;
messageCounter?: number;
heartBeatIntervalId: ReturnType<typeof setInterval> | undefined;
connected: boolean;
messageStoreIn: IMessageStore<Message>;
messageStoreOut: IMessageStore<Message>;
fixParser?: FIXParser;
isLoggedIn?: boolean;
requestedLogout?: boolean;
logger: Logger;
logging: boolean;
proxy?: ProxyAgent;
tlsKey?: string | Buffer | Array<string | Buffer | KeyObject>;
tlsCert?: string | Buffer | Array<string | Buffer>;
tlsUseSNI?: boolean;
tlsSkipStdInPipe?: boolean;
skipValidation?: boolean;
/**
* Registers a callback function to be invoked when a FIX message is received.
* Multiple callbacks can be registered and all will be triggered.
*
* @param {FIXParserOptions['onMessage']} callback - The callback function to handle incoming FIX messages.
*/
addOnMessageCallback(callback: FIXParserOptions['onMessage']): void;
/**
* Registers a callback function to be invoked when the FIX connection is successfully established.
* Multiple callbacks can be registered and all will be triggered.
*
* @param {FIXParserOptions['onOpen']} callback - The callback function to handle connection opening.
*/
addOnOpenCallback(callback: FIXParserOptions['onOpen']): void;
/**
* Registers a callback function to be invoked when a FIX connection error occurs.
* Multiple callbacks can be registered and all will be triggered.
*
* @param {FIXParserOptions['onError']} callback - The callback function to handle connection errors.
*/
addOnErrorCallback(callback: FIXParserOptions['onError']): void;
/**
* Registers a callback function to be invoked when the FIX connection is closed.
* Multiple callbacks can be registered and all will be triggered.
*
* @param {FIXParserOptions['onClose']} callback - The callback function to handle connection closure.
*/
addOnCloseCallback(callback: FIXParserOptions['onClose']): void;
/**
* Registers a callback function to be invoked when the FIX connection is ready for use.
* Multiple callbacks can be registered and all will be triggered.
*
* @param {FIXParserOptions['onReady']} callback - The callback function to handle connection readiness.
*/
addOnReadyCallback(callback: FIXParserOptions['onReady']): void;
/**
* Callback function that is invoked when a FIX message is received.
*
* @param {Message} message - The received FIX message.
*/
onMessageCallback?: FIXParserOptions['onMessage'];
/**
* Callback function that is invoked when the FIX connection is established.
*/
onOpenCallback?: FIXParserOptions['onOpen'];
/**
* Callback function that is invoked when a FIX connection error occurs.
*
* @param {Error} error - The error that occurred.
*/
onErrorCallback?: FIXParserOptions['onError'];
/**
* Callback function that is invoked when the FIX connection is closed.
*/
onCloseCallback?: FIXParserOptions['onClose'];
/**
* Callback function that is invoked when the FIX connection is ready for use.
*/
onReadyCallback?: FIXParserOptions['onReady'];
/**
* Connect to a remote FIX server/gateway.
*
* @param {FIXParserOptions | FIXParserBrowserOptions} options - Connection options.
* @returns {void}
*/
connect?(options: FIXParserOptions | FIXParserBrowserOptions): void;
/**
* Get the next outgoing message sequence number.
*
* @returns {number} The next outgoing message sequence number.
*/
getNextTargetMsgSeqNum(): number;
/**
* Set the next outgoing message sequence number.
*
* @param {number} nextMsgSeqNum - The next message sequence number.
* @returns {number} The next outgoing message sequence number.
*/
setNextTargetMsgSeqNum(nextMsgSeqNum: number): number;
/**
* Get current timestamp.
*
* @param {Date} dateObject - An instance of a Date class.
* @returns {string} The current timestamp.
*/
getTimestamp(dateObject?: Date): string;
/**
* Create an instance of a FIX Message.
*
* @param {...Field} fields - An array of Fields.
* @returns {Message} A FIX Message class instance.
*/
createMessage(...fields: Field[]): Message;
/**
* Parse a FIX message string into Message instance(s).
*
* @param {string} data - FIX message string.
* @returns {Message[]} FIX Message class instance(s).
*/
parse(data: string): Message[];
/**
* Send a FIX message.
*
* @param {Message} message - FIX Message class instance.
* @returns {void}
*/
send(message: Message): void;
/**
* Get connection status.
*
* @returns {boolean} Current connection status.
*/
isConnected(): boolean;
/**
* Close current connection.
*
* @returns {void}
*/
close(): void;
/**
* Stop heartbeat interval.
*
* @returns {void}
*/
stopHeartbeat(): void;
/**
* Restart heartbeat interval.
*
* @returns {void}
*/
restartHeartbeat(): void;
/**
* Start heartbeat interval.
*
* @param {number} heartBeatInterval - Heartbeat interval in seconds.
* @param {boolean} [disableLog] - Whether to disable heartbeat logs.
* @returns {void}
*/
startHeartbeat(heartBeatInterval: number, disableLog?: boolean): void;
}