skayn-trading-sdk
Version:
Professional Bitcoin trading strategy backtesting framework with institutional-grade architecture
152 lines (136 loc) • 4.22 kB
JavaScript
/**
* Execution Engine Interface
* Defines contract for executing trades on any broker/exchange
*/
class IExecutionEngine {
/**
* Initialize the execution engine
* @param {Object} config - Engine configuration
*/
async initialize(config = {}) {
throw new Error('IExecutionEngine.initialize() must be implemented');
}
/**
* Execute a trading signal
* @param {Object} signal - Trading signal from strategy
* @param {Object} portfolioState - Current portfolio state
* @returns {Promise<Object>} Execution result
*/
async execute(signal, portfolioState) {
throw new Error('IExecutionEngine.execute() must be implemented');
}
/**
* Get current account balance
* @returns {Promise<Object>} Account balance information
*/
async getAccountBalance() {
throw new Error('IExecutionEngine.getAccountBalance() must be implemented');
}
/**
* Get open positions
* @returns {Promise<Array>} Array of open positions
*/
async getOpenPositions() {
throw new Error('IExecutionEngine.getOpenPositions() must be implemented');
}
/**
* Close a specific position
* @param {string} positionId - Position identifier
* @param {Object} options - Close options (partial, market order, etc.)
* @returns {Promise<Object>} Close result
*/
async closePosition(positionId, options = {}) {
throw new Error('IExecutionEngine.closePosition() must be implemented');
}
/**
* Close all positions
* @param {Object} options - Close options
* @returns {Promise<Array>} Array of close results
*/
async closeAllPositions(options = {}) {
throw new Error('IExecutionEngine.closeAllPositions() must be implemented');
}
/**
* Get order history
* @param {Object} filters - Filter options (symbol, date range, etc.)
* @returns {Promise<Array>} Array of historical orders
*/
async getOrderHistory(filters = {}) {
throw new Error('IExecutionEngine.getOrderHistory() must be implemented');
}
/**
* Cancel an open order
* @param {string} orderId - Order identifier
* @returns {Promise<Object>} Cancellation result
*/
async cancelOrder(orderId) {
throw new Error('IExecutionEngine.cancelOrder() must be implemented');
}
/**
* Get supported assets/symbols
* @returns {Promise<Array>} Array of supported trading symbols
*/
async getSupportedSymbols() {
throw new Error('IExecutionEngine.getSupportedSymbols() must be implemented');
}
/**
* Validate if order is executable
* @param {Object} order - Order details
* @returns {Promise<Object>} Validation result
*/
async validateOrder(order) {
throw new Error('IExecutionEngine.validateOrder() must be implemented');
}
/**
* Get trading fees
* @param {string} symbol - Trading symbol
* @param {string} orderType - Order type (market, limit, etc.)
* @returns {Promise<Object>} Fee information
*/
async getTradingFees(symbol, orderType = 'market') {
throw new Error('IExecutionEngine.getTradingFees() must be implemented');
}
/**
* Set position sizing rules
* @param {Object} rules - Position sizing configuration
*/
setPositionSizing(rules) {
throw new Error('IExecutionEngine.setPositionSizing() must be implemented');
}
/**
* Set risk management rules
* @param {Object} rules - Risk management configuration
*/
setRiskManagement(rules) {
throw new Error('IExecutionEngine.setRiskManagement() must be implemented');
}
/**
* Get execution engine metadata
* @returns {Object} Engine information
*/
getEngineMetadata() {
return {
name: 'Unknown Execution Engine',
version: '1.0.0',
description: 'Base execution engine interface',
supportedAssets: [],
supportedOrderTypes: ['market', 'limit'],
maxLeverage: 1,
minOrderSize: 0
};
}
/**
* Check engine health/connectivity
* @returns {Promise<Object>} Health status
*/
async healthCheck() {
throw new Error('IExecutionEngine.healthCheck() must be implemented');
}
/**
* Cleanup resources
*/
async cleanup() {
// Optional cleanup - override if needed
}
}
module.exports = IExecutionEngine;