UNPKG

skayn-trading-sdk

Version:

Professional Bitcoin trading strategy backtesting framework with institutional-grade architecture

251 lines (228 loc) 7.22 kB
/** * Storage Provider Interface * Defines contract for data persistence backends */ class IStorageProvider { /** * Initialize the storage provider * @param {Object} config - Storage configuration */ async initialize(config = {}) { throw new Error('IStorageProvider.initialize() must be implemented'); } /** * Store trading data * @param {string} collection - Data collection name * @param {Object} data - Data to store * @param {Object} options - Storage options * @returns {Promise<Object>} Storage result with ID */ async store(collection, data, options = {}) { throw new Error('IStorageProvider.store() must be implemented'); } /** * Retrieve data by ID * @param {string} collection - Data collection name * @param {string} id - Data identifier * @returns {Promise<Object>} Retrieved data */ async get(collection, id) { throw new Error('IStorageProvider.get() must be implemented'); } /** * Query data with filters * @param {string} collection - Data collection name * @param {Object} query - Query filters * @param {Object} options - Query options (limit, sort, etc.) * @returns {Promise<Array>} Array of matching records */ async query(collection, query = {}, options = {}) { throw new Error('IStorageProvider.query() must be implemented'); } /** * Update existing data * @param {string} collection - Data collection name * @param {string} id - Data identifier * @param {Object} updates - Data updates * @returns {Promise<Object>} Update result */ async update(collection, id, updates) { throw new Error('IStorageProvider.update() must be implemented'); } /** * Delete data * @param {string} collection - Data collection name * @param {string} id - Data identifier * @returns {Promise<Object>} Delete result */ async delete(collection, id) { throw new Error('IStorageProvider.delete() must be implemented'); } /** * Store trade execution data * @param {Object} trade - Trade execution data * @returns {Promise<string>} Trade ID */ async storeTrade(trade) { return await this.store('trades', { ...trade, timestamp: trade.timestamp || new Date().toISOString(), type: 'trade' }); } /** * Store market data * @param {Object} marketData - Market data * @returns {Promise<string>} Data ID */ async storeMarketData(marketData) { return await this.store('market_data', { ...marketData, timestamp: marketData.timestamp || new Date().toISOString(), type: 'market_data' }); } /** * Store position data * @param {Object} position - Position data * @returns {Promise<string>} Position ID */ async storePosition(position) { return await this.store('positions', { ...position, timestamp: position.timestamp || new Date().toISOString(), type: 'position' }); } /** * Store strategy performance data * @param {Object} performance - Performance metrics * @returns {Promise<string>} Performance ID */ async storePerformance(performance) { return await this.store('performance', { ...performance, timestamp: performance.timestamp || new Date().toISOString(), type: 'performance' }); } /** * Get trade history * @param {Object} filters - Query filters * @param {Object} options - Query options * @returns {Promise<Array>} Array of trades */ async getTradeHistory(filters = {}, options = {}) { return await this.query('trades', filters, options); } /** * Get market data history * @param {Object} filters - Query filters * @param {Object} options - Query options * @returns {Promise<Array>} Array of market data */ async getMarketDataHistory(filters = {}, options = {}) { return await this.query('market_data', filters, options); } /** * Get position history * @param {Object} filters - Query filters * @param {Object} options - Query options * @returns {Promise<Array>} Array of positions */ async getPositionHistory(filters = {}, options = {}) { return await this.query('positions', filters, options); } /** * Get performance history * @param {Object} filters - Query filters * @param {Object} options - Query options * @returns {Promise<Array>} Array of performance data */ async getPerformanceHistory(filters = {}, options = {}) { return await this.query('performance', filters, options); } /** * Create data index for faster queries * @param {string} collection - Collection name * @param {Object} indexSpec - Index specification * @param {Object} options - Index options * @returns {Promise<Object>} Index creation result */ async createIndex(collection, indexSpec, options = {}) { throw new Error('IStorageProvider.createIndex() must be implemented'); } /** * Bulk insert data * @param {string} collection - Collection name * @param {Array} documents - Array of documents to insert * @param {Object} options - Insert options * @returns {Promise<Object>} Bulk insert result */ async bulkInsert(collection, documents, options = {}) { throw new Error('IStorageProvider.bulkInsert() must be implemented'); } /** * Get storage statistics * @param {string} collection - Collection name (optional) * @returns {Promise<Object>} Storage statistics */ async getStats(collection = null) { throw new Error('IStorageProvider.getStats() must be implemented'); } /** * Backup data * @param {Object} options - Backup options * @returns {Promise<Object>} Backup result */ async backup(options = {}) { throw new Error('IStorageProvider.backup() must be implemented'); } /** * Restore data from backup * @param {string} backupPath - Path to backup * @param {Object} options - Restore options * @returns {Promise<Object>} Restore result */ async restore(backupPath, options = {}) { throw new Error('IStorageProvider.restore() must be implemented'); } /** * Archive old data * @param {string} collection - Collection name * @param {Object} archiveOptions - Archive criteria * @returns {Promise<Object>} Archive result */ async archiveData(collection, archiveOptions) { throw new Error('IStorageProvider.archiveData() must be implemented'); } /** * Get storage provider metadata * @returns {Object} Provider information */ getStorageProviderMetadata() { return { name: 'Unknown Storage Provider', version: '1.0.0', description: 'Base storage provider interface', supportedOperations: ['store', 'get', 'query', 'update', 'delete'], supportsTransactions: false, supportsIndexing: false, maxDocumentSize: 16777216 // 16MB default }; } /** * Test storage connectivity * @returns {Promise<Object>} Health check result */ async healthCheck() { throw new Error('IStorageProvider.healthCheck() must be implemented'); } /** * Cleanup resources and connections */ async cleanup() { // Optional cleanup - override if needed } } module.exports = IStorageProvider;