skayn-trading-sdk
Version:
Professional Bitcoin trading strategy backtesting framework with institutional-grade architecture
99 lines (89 loc) • 2.65 kB
JavaScript
/**
* Abstract Strategy Interface
* Defines contract for all trading strategies in backtesting
*/
class IStrategy {
/**
* Analyze market data and generate trading signal
* @param {Array} historicalBars - Array of OHLCV data up to current point
* @param {Object} portfolioState - Current portfolio state
* @returns {Promise<Object>} Trading signal with action, confidence, reasons
*/
async analyze(historicalBars, portfolioState) {
throw new Error('IStrategy.analyze() must be implemented');
}
/**
* Get number of bars needed for strategy warmup
* @returns {number} Minimum bars needed before strategy can generate signals
*/
getRequiredWarmupPeriods() {
throw new Error('IStrategy.getRequiredWarmupPeriods() must be implemented');
}
/**
* Get strategy metadata
* @returns {Object} Strategy information
*/
getStrategyMetadata() {
return {
name: 'Unknown Strategy',
version: '1.0.0',
description: 'Base strategy interface',
parameters: {},
riskLevel: 'medium'
};
}
/**
* Get strategy configuration parameters
* @returns {Object} Configuration object
*/
getParameters() {
return {};
}
/**
* Set strategy parameters
* @param {Object} params - Strategy parameters
*/
setParameters(params) {
this.parameters = { ...this.parameters, ...params };
}
/**
* Validate strategy configuration
* @returns {Object} Validation result
*/
validateConfiguration() {
return { valid: true, issues: [] };
}
/**
* Reset strategy internal state (for multiple backtests)
*/
reset() {
// Override in implementations if strategy maintains state
}
/**
* Get strategy-specific stop loss percentage
* @param {Object} signal - Current signal
* @param {Object} marketConditions - Current market conditions
* @returns {number} Stop loss percentage
*/
getStopLossPercentage(signal, marketConditions) {
return 2.0; // Default 2%
}
/**
* Get strategy-specific take profit percentage
* @param {Object} signal - Current signal
* @param {Object} marketConditions - Current market conditions
* @returns {number} Take profit percentage
*/
getTakeProfitPercentage(signal, marketConditions) {
return 3.0; // Default 3%
}
/**
* Check if strategy supports the given market conditions
* @param {Object} marketConditions - Market conditions object
* @returns {boolean} Whether strategy supports these conditions
*/
supportsMarketConditions(marketConditions) {
return true; // Default: support all conditions
}
}
module.exports = IStrategy;