UNPKG

@barfinex/types

Version:

Shared TypeScript interfaces for Barfinex — an open-source standard for digital asset trading by Barfin Network.

216 lines (215 loc) 6.86 kB
import { Candle } from './candle.interface'; import { TimeFrame, WorkingEnv } from './common.interface'; import { GeneticSchema, ConfigValidator, StatsValidator } from './genetic.interface'; import { Order } from './order.interface'; import { PluginInterface } from './plugin.interface'; import { Connector } from './connector.interface'; import { InspectorTradeSettingsConfig } from './inspector.interface'; import { Subscription, Symbol, Provider, Advisor } from '.'; /** * Interface representing the configuration options for a detector. */ export interface Detector { /** * A unique key for the detector. */ key: string; sysname: string; logLevel: string; currency: string; useNotifications: { telegram: { token: string; chatId: string; messageFormat: string; isActive: boolean; }; }; advisor: Advisor; /** * The base API URL used by the detector. */ restApiUrl: string; /** * List of connector configurations. */ providers: Provider[]; /** * Port number used for the inspector API. */ /** * Optional system name for the detector. */ detectorSysname?: string; /** * Array of symbols the detector will operate on. */ symbols: Symbol[]; /** * Array of active orders associated with the detector. */ orders: Order[]; /** * Array of time frames the detector will use. */ intervals: TimeFrame[]; /** * Configuration for indicators used by the detector. */ indicators: Indicator[]; /** * Optional plugins configuration for the detector. */ plugins?: DetectorPlugin[]; /** * Indicates if the detector operates in sandbox mode. */ useSandbox: boolean; /** * Indicates if the detector should start from scratch. */ useScratch: boolean; /** * Indicates if the detector is blocked. */ isBlocked?: boolean; /** * Indicates if the detector is currently active. */ isActive?: boolean; subscriptions: Subscription[]; tradeSettings?: InspectorTradeSettingsConfig; } export interface DetectorPlugin { name: string; path: string; enabled: boolean; options?: Record<string, unknown>; } export interface Indicator { name: string; parameters: IndicatorParameters; visual: IndicatorVisual; } export interface IndicatorParameters { period: number; source: string | { peak: string; trough: string; }; overboughtLevel?: number; oversoldLevel?: number; } export interface IndicatorVisual { group?: string; paneSysName: string; } /** * Interface for metadata used in genetic algorithms and strategy creation. */ export interface Meta { /** * Parameters for the genetic algorithm. */ parameters: GeneticSchema; /** * Function to calculate a score for the detector. * @param detector - The detector to score. * @returns The calculated score. */ score: (detector: Detector) => number; /** * Function to retrieve statistics for the detector. * @param detector - The detector to analyze. * @returns The statistics for the detector. */ stats: (detector: Detector) => unknown; /** * Function to create a new detector instance. * @param provider - The connector provider for the detector. * @param cfg - The configuration options for the detector. * @param env - The working environment for the detector. * @returns A Promise resolving to the created detector. */ create: (provider: Connector, cfg: Detector, env: WorkingEnv) => Promise<Detector>; /** * Optional function to validate the detector configuration. */ validate?: ConfigValidator; /** * Optional function to validate the detector's statistics. */ validateStats?: StatsValidator; /** * Optional filter function for ticks. * @param solution - The detector options to filter. * @returns A function that filters ticks. */ ticksFilter?: (solution: Detector) => (tick: Candle) => boolean; /** * Function to retrieve plugins for testing purposes. * @param cfg - The detector configuration. * @returns An array of test plugins. */ testPlugins?: (cfg: Detector) => PluginInterface[]; /** * Function to retrieve plugins for genetic algorithms. * @param cfg - The detector configuration. * @returns An array of genetic plugins. */ geneticPlugins?: (cfg: Detector) => PluginInterface[]; } /** * Interface representing a snapshot of the detector's state. */ export interface SnapshotData { /** * Array of orders in the detector's state. */ orders: Array<Order>; /** * The detector's options at the time of the snapshot. */ options: Detector; /** * Plugin-specific data for the snapshot. */ pluginsData: Record<string, Record<string, unknown>>; } export declare enum DetectorEventType { SERVICE_STARTED = "SERVICE_STARTED", SERVICE_STOPPED = "SERVICE_STOPPED", DETECTOR_INITIALIZED = "DETECTOR_INITIALIZED", DETECTOR_STARTED = "DETECTOR_STARTED", DETECTOR_STOPPED = "DETECTOR_STOPPED", ERROR_OCCURRED = "ERROR_OCCURRED", RESTART_ATTEMPT = "RESTART_ATTEMPT", TICK_RECEIVED = "TICK_RECEIVED", CANDLE_UPDATED = "CANDLE_UPDATED", ORDERBOOK_UPDATED = "ORDERBOOK_UPDATED", MARKET_SNAPSHOT = "MARKET_SNAPSHOT", CONNECTION_LOST = "CONNECTION_LOST", CONNECTION_RESTORED = "CONNECTION_RESTORED", ENTRY_SIGNAL = "ENTRY_SIGNAL", EXIT_SIGNAL = "EXIT_SIGNAL", NO_ACTION = "NO_ACTION", CONDITION_EVALUATED = "CONDITION_EVALUATED", ORDER_PLACED = "ORDER_PLACED", ORDER_FILLED = "ORDER_FILLED", ORDER_PARTIALLY_FILLED = "ORDER_PARTIALLY_FILLED", ORDER_CANCELED = "ORDER_CANCELED", ORDER_REJECTED = "ORDER_REJECTED", POSITION_OPENED = "POSITION_OPENED", POSITION_CLOSED = "POSITION_CLOSED", RISK_TRIGGERED = "RISK_TRIGGERED", PNL_UPDATED = "PNL_UPDATED", BALANCE_UPDATED = "BALANCE_UPDATED", LEVERAGE_SET = "LEVERAGE_SET", RISK_ADJUSTED = "RISK_ADJUSTED", HEALTH_CHECK_FAILED = "HEALTH_CHECK_FAILED", WEBHOOK_RECEIVED = "WEBHOOK_RECEIVED", CONFIG_UPDATED = "CONFIG_UPDATED", MOCK_EVENT = "MOCK_EVENT" } export type DetectorEventCategory = 'system' | 'market_data' | 'signals' | 'orders' | 'metrics' | 'infrastructure'; export declare const DetectorEventGroups: Record<DetectorEventCategory, DetectorEventType[]>;