-
-
Notifications
You must be signed in to change notification settings - Fork 92
refactor: centralize CCXT instance caching with ccxtInstanceManager #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Simple test script to validate ccxtInstanceManager refactoring | ||
| * This script verifies that: | ||
| * 1. ccxtInstanceManager is properly exported | ||
| * 2. No direct CCXT instantiations remain except in fallback cases | ||
| * 3. ccxtBrowserProvider delegates to ccxtInstanceManager | ||
| */ | ||
|
|
||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| console.log('π§ͺ Testing CCXT Instance Manager Refactoring'); | ||
| console.log('============================================'); | ||
|
|
||
| // Test 1: Verify ccxtInstanceManager export | ||
| console.log('\n1. Checking ccxtInstanceManager export...'); | ||
| const ccxtInstanceManagerPath = '../src/store/utils/ccxtInstanceManager.ts'; | ||
| const ccxtInstanceManagerContent = fs.readFileSync(path.join(__dirname, ccxtInstanceManagerPath), 'utf8'); | ||
|
|
||
| if (ccxtInstanceManagerContent.includes('export const ccxtInstanceManager = new CCXTInstanceManager()')) { | ||
| console.log('β ccxtInstanceManager properly exported as singleton'); | ||
| } else { | ||
| console.log('β ccxtInstanceManager export not found'); | ||
| } | ||
|
|
||
| // Test 2: Verify TestChartWidget.tsx uses ccxtInstanceManager | ||
| console.log('\n2. Checking TestChartWidget.tsx...'); | ||
| const testChartWidgetPath = '../src/components/TestChartWidget.tsx'; | ||
| const testChartWidgetContent = fs.readFileSync(path.join(__dirname, testChartWidgetPath), 'utf8'); | ||
|
|
||
| if (testChartWidgetContent.includes('import { ccxtInstanceManager }')) { | ||
| console.log('β TestChartWidget imports ccxtInstanceManager'); | ||
| } else { | ||
| console.log('β TestChartWidget does not import ccxtInstanceManager'); | ||
| } | ||
|
|
||
| if (testChartWidgetContent.includes('ccxtInstanceManager.getExchangeInstanceForMarket')) { | ||
| console.log('β TestChartWidget uses ccxtInstanceManager.getExchangeInstanceForMarket'); | ||
| } else { | ||
| console.log('β TestChartWidget does not use ccxtInstanceManager'); | ||
| } | ||
|
|
||
| // Test 3: Verify TestTimeframes.tsx uses ccxtInstanceManager | ||
| console.log('\n3. Checking TestTimeframes.tsx...'); | ||
| const testTimeframesPath = '../src/components/TestTimeframes.tsx'; | ||
| const testTimeframesContent = fs.readFileSync(path.join(__dirname, testTimeframesPath), 'utf8'); | ||
|
|
||
| if (testTimeframesContent.includes('import { ccxtInstanceManager }')) { | ||
| console.log('β TestTimeframes imports ccxtInstanceManager'); | ||
| } else { | ||
| console.log('β TestTimeframes does not import ccxtInstanceManager'); | ||
| } | ||
|
|
||
| if (testTimeframesContent.includes('ccxtInstanceManager.getExchangeInstanceForMarket')) { | ||
| console.log('β TestTimeframes uses ccxtInstanceManager.getExchangeInstanceForMarket'); | ||
| } else { | ||
| console.log('β TestTimeframes does not use ccxtInstanceManager'); | ||
| } | ||
|
|
||
| // Test 4: Verify ccxtBrowserProvider delegates to ccxtInstanceManager | ||
| console.log('\n4. Checking ccxtBrowserProvider.ts...'); | ||
| const ccxtBrowserProviderPath = '../src/store/providers/ccxtBrowserProvider.ts'; | ||
| const ccxtBrowserProviderContent = fs.readFileSync(path.join(__dirname, ccxtBrowserProviderPath), 'utf8'); | ||
|
|
||
| if (ccxtBrowserProviderContent.includes('import { ccxtInstanceManager }')) { | ||
| console.log('β ccxtBrowserProvider imports ccxtInstanceManager'); | ||
| } else { | ||
| console.log('β ccxtBrowserProvider does not import ccxtInstanceManager'); | ||
| } | ||
|
|
||
| if (ccxtBrowserProviderContent.includes('ccxtInstanceManager.getExchangeInstanceForMarket')) { | ||
| console.log('β ccxtBrowserProvider delegates to ccxtInstanceManager.getExchangeInstanceForMarket'); | ||
| } else { | ||
| console.log('β ccxtBrowserProvider does not delegate to ccxtInstanceManager'); | ||
| } | ||
|
|
||
| if (ccxtBrowserProviderContent.includes('ccxtInstanceManager.clearCache')) { | ||
| console.log('β ccxtBrowserProvider delegates cache clearing to ccxtInstanceManager'); | ||
| } else { | ||
| console.log('β ccxtBrowserProvider does not delegate cache clearing'); | ||
| } | ||
|
|
||
| // Test 5: Check for duplicate caching code removal | ||
| console.log('\n5. Checking for duplicate cache removal...'); | ||
|
|
||
| if (!ccxtBrowserProviderContent.includes('private static instancesCache = new Map')) { | ||
| console.log('β Duplicate static instancesCache removed from ccxtBrowserProvider'); | ||
| } else { | ||
| console.log('β Duplicate static instancesCache still exists in ccxtBrowserProvider'); | ||
| } | ||
|
|
||
| if (!ccxtBrowserProviderContent.includes('setInterval(() => {') || | ||
| ccxtBrowserProviderContent.includes('Cleanup ΡΠ΅ΠΏΠ΅ΡΡ ΡΠΏΡΠ°Π²Π»ΡΠ΅ΡΡΡ ΡΠ΅Π½ΡΡΠ°Π»ΠΈΠ·ΠΎΠ²Π°Π½Π½ΠΎ')) { | ||
| console.log('β Duplicate cleanup interval removed or replaced'); | ||
| } else { | ||
| console.log('β Duplicate cleanup interval still exists'); | ||
| } | ||
|
|
||
| // Test 6: Check for remaining direct instantiations | ||
| console.log('\n6. Checking for direct CCXT instantiations...'); | ||
|
|
||
| const filesToCheck = [ | ||
| testChartWidgetPath, | ||
| testTimeframesPath, | ||
| ccxtBrowserProviderPath | ||
| ]; | ||
|
|
||
| let foundDirectInstantiations = 0; | ||
| let expectedFallbackInstantiations = 0; | ||
|
|
||
| filesToCheck.forEach(filePath => { | ||
| const content = fs.readFileSync(path.join(__dirname, filePath), 'utf8'); | ||
| const directInstantiations = (content.match(/new ccxt\./g) || []).length; | ||
| const fallbackInstantiations = (content.match(/Fallback|fallback|CCXT Pro.*fallback/gi) || []).length; | ||
|
|
||
| foundDirectInstantiations += directInstantiations; | ||
| expectedFallbackInstantiations += fallbackInstantiations; | ||
|
|
||
| if (directInstantiations > 0) { | ||
| console.log(` - ${path.basename(filePath)}: ${directInstantiations} direct instantiation(s) found`); | ||
| } | ||
| }); | ||
|
|
||
| if (foundDirectInstantiations <= expectedFallbackInstantiations) { | ||
| console.log('β Direct CCXT instantiations limited to fallback cases only'); | ||
| } else { | ||
| console.log(`β Found ${foundDirectInstantiations} direct instantiations, expected only ${expectedFallbackInstantiations} fallback cases`); | ||
| } | ||
|
|
||
| console.log('\nπ― Refactoring Summary:'); | ||
| console.log('- ccxtInstanceManager is now used as the central caching mechanism'); | ||
| console.log('- Test components use ccxtInstanceManager instead of direct instantiation'); | ||
| console.log('- ccxtBrowserProvider delegates to ccxtInstanceManager'); | ||
| console.log('- Duplicate caching code has been removed'); | ||
| console.log('- CCXT Pro has fallback logic until ccxtInstanceManager supports it'); | ||
|
|
||
| console.log('\nβ Refactoring validation completed!'); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import React, { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useDataProviderStore } from '../store/dataProviderStore'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { getCCXT } from '../store/utils/ccxtUtils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ccxtInstanceManager } from '../store/utils/ccxtInstanceManager'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const TestTimeframes: React.FC = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { getTimeframesForExchange } = useDataProviderStore(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -10,43 +11,66 @@ const TestTimeframes: React.FC = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const testExchanges = ['binance', 'bybit', 'okx', 'kucoin']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const testResults: Record<string, any> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test direct CCXT access | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π§ͺ [TestTimeframes] Testing direct CCXT access'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ccxt = getCCXT(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ccxt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('β [TestTimeframes] CCXT is available'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π [TestTimeframes] Available exchanges:', Object.keys(ccxt).filter(key => typeof ccxt[key] === 'function').slice(0, 10)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test specific exchange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ccxt.binance) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const runTests = async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test direct CCXT access | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π§ͺ [TestTimeframes] Testing direct CCXT access'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ccxt = getCCXT(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ccxt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('β [TestTimeframes] CCXT is available'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π [TestTimeframes] Available exchanges:', Object.keys(ccxt).filter(key => typeof ccxt[key] === 'function').slice(0, 10)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test specific exchange using ccxtInstanceManager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ccxt.binance) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const binanceInstance = await ccxtInstanceManager.getExchangeInstanceForMarket( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'binance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'test-timeframes-account', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| apiKey: 'test', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secret: 'test', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sandbox: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'spot' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π [TestTimeframes] Binance timeframes via ccxtInstanceManager:', binanceInstance.timeframes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = binanceInstance.timeframes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('β [TestTimeframes] Error creating Binance instance via ccxtInstanceManager:', error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = { error: error.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fallback to direct instantiation for comparison | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const binanceInstanceFallback = new ccxt.binance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('β οΈ [TestTimeframes] Fallback - Binance timeframes:', binanceInstanceFallback.timeframes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = binanceInstanceFallback.timeframes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (fallbackError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('β [TestTimeframes] Fallback also failed:', fallbackError); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = { error: fallbackError.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fallback inconsistency and result overwriting issue. Two problems here:
Apply this diff: const binanceInstance = await ccxtInstanceManager.getExchangeInstanceForMarket(
'binance',
'test-timeframes-account',
{
apiKey: 'test',
secret: 'test',
sandbox: true
},
'spot'
);
console.log('π [TestTimeframes] Binance timeframes via ccxtInstanceManager:', binanceInstance.timeframes);
testResults.binance_direct = binanceInstance.timeframes;
} catch (error) {
console.error('β [TestTimeframes] Error creating Binance instance via ccxtInstanceManager:', error);
- testResults.binance_direct = { error: error.message };
// Fallback to direct instantiation for comparison
try {
- const binanceInstanceFallback = new ccxt.binance();
+ const binanceInstanceFallback = new ccxt.binance({
+ apiKey: 'test',
+ secret: 'test',
+ sandbox: true
+ });
console.log('β οΈ [TestTimeframes] Fallback - Binance timeframes:', binanceInstanceFallback.timeframes);
testResults.binance_direct = binanceInstanceFallback.timeframes;
} catch (fallbackError) {
console.error('β [TestTimeframes] Fallback also failed:', fallbackError);
testResults.binance_direct = { error: fallbackError.message };
}
}π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('β [TestTimeframes] CCXT is not available'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.ccxt_available = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test our store method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testExchanges.forEach(exchange => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`π§ͺ [TestTimeframes] Testing ${exchange}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const binanceInstance = new ccxt.binance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log('π [TestTimeframes] Binance timeframes:', binanceInstance.timeframes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = binanceInstance.timeframes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const timeframes = getTimeframesForExchange(exchange); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults[exchange] = timeframes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`β [TestTimeframes] ${exchange} timeframes:`, timeframes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('β [TestTimeframes] Error creating Binance instance:', error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.binance_direct = { error: error.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(`β [TestTimeframes] Error getting timeframes for ${exchange}:`, error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults[exchange] = { error: error.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('β [TestTimeframes] CCXT is not available'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults.ccxt_available = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test our store method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testExchanges.forEach(exchange => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`π§ͺ [TestTimeframes] Testing ${exchange}`); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const timeframes = getTimeframesForExchange(exchange); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults[exchange] = timeframes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(`β [TestTimeframes] ${exchange} timeframes:`, timeframes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(`β [TestTimeframes] Error getting timeframes for ${exchange}:`, error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testResults[exchange] = { error: error.message }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setResults(testResults); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setResults(testResults); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runTests(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [getTimeframesForExchange]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback creates inconsistent instance without credentials.
The fallback at line 61 instantiates
ccxt.binance()without credentials, while the manager call (lines 47-56) passesapiKey,secret, andsandboxconfiguration. This inconsistency means the fallback won't actually test the same scenario and could mask configuration or authentication issues in ccxtInstanceManager.Apply this diff to align the fallback with the manager configuration:
} catch (managerError) { addResult(`β ccxtInstanceManager error: ${managerError}`); // Fallback to direct instantiation for comparison - const binance = new ccxt.binance(); + const binance = new ccxt.binance({ + apiKey: 'test', + secret: 'test', + sandbox: true + }); addResult(`β οΈ Fallback - Binance instance created directly: ${binance.id}`); }π Committable suggestion
π€ Prompt for AI Agents