diff --git a/DesignSpace/Workspace/FunctionLibraries/CCXTFunctions.js b/DesignSpace/Workspace/FunctionLibraries/CCXTFunctions.js index 167fcd855..caaf38590 100644 --- a/DesignSpace/Workspace/FunctionLibraries/CCXTFunctions.js +++ b/DesignSpace/Workspace/FunctionLibraries/CCXTFunctions.js @@ -9,11 +9,18 @@ function newCCXTFunctions () { function addMissingExchanges (node, functionLibraryUiObjectsFromNodes) { currentExchanges = new Map() - for (let j = 0; j < node.exchanges.length; j++) { - let exchange = node.exchanges[j] - let codeName = loadPropertyFromNodeConfig(exchange.payload, 'codeName') - currentExchanges.set(codeName, exchange) + let parent = node.payload.parentNode + if (parent !== undefined) { + for (let i = 0; i < parent.cryptoExchanges.length; i++) { + let cryptoExchanges = parent.cryptoExchanges[i] + for (let j = 0; j < cryptoExchanges.exchanges.length; j++) { + let exchange = cryptoExchanges.exchanges[j] + let codeName = loadPropertyFromNodeConfig(exchange.payload, 'codeName') + currentExchanges.set(codeName, exchange) + } + } } + for (let i = 0; i < ccxt.exchanges.length; i++) { let exchangeId = ccxt.exchanges[i] let existingExchange = currentExchanges.get(exchangeId) @@ -28,25 +35,66 @@ function newCCXTFunctions () { let ccxtExchange = new exchangeClass(exchangeConstructorParams) if (ccxtExchange.has.fetchOHLCV === true) { - if (ccxtExchange.timeframes['1m'] !== undefined) { - let newExchange = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Crypto Exchange') - newExchange.name = ccxtExchange.name - newExchange.code = '{ \n\"codeName\": \"' + ccxtExchange.id + '\"\n}' - newExchange.payload.floatingObject.collapseToggle() - newExchange.exchangeAssets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeMarkets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeAccounts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 - newExchange.exchangeAssets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_050X - newExchange.exchangeMarkets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X - newExchange.exchangeAccounts.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_025X + if (ccxtExchange.has.fetchCurrencies === true) { + if (ccxtExchange.has.fetchMarkets === true) { + if (ccxtExchange.timeframes['1m'] !== undefined) { + let newExchange = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Crypto Exchange') + newExchange.name = ccxtExchange.name + newExchange.code = '{ \n\"codeName\": \"' + ccxtExchange.id + '\"\n}' + newExchange.payload.floatingObject.collapseToggle() + newExchange.exchangeAssets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + newExchange.exchangeMarkets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + newExchange.exchangeAccounts.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_180 + newExchange.exchangeAssets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_050X + newExchange.exchangeMarkets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X + newExchange.exchangeAccounts.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_025X + } + } } } } } } - function addMissingAssets (node, functionLibraryUiObjectsFromNodes) { + async function addMissingAssets (node, functionLibraryUiObjectsFromNodes) { + currentAssets = new Map() + for (let j = 0; j < node.assets.length; j++) { + let asset = node.assets[j] + let codeName = loadPropertyFromNodeConfig(asset.payload, 'codeName') + currentAssets.set(codeName, asset) + } + let exchangeId = loadPropertyFromNodeConfig(node.payload.parentNode.payload, 'codeName') + + const exchangeClass = ccxt[exchangeId] + const exchangeConstructorParams = { + 'timeout': 30000, + 'enableRateLimit': true, + verbose: false + } + + let ccxtExchange = new exchangeClass(exchangeConstructorParams) + + if (ccxtExchange.has.fetchCurrencies === true) { + let ccxtAssets = [] + try { + ccxtAssets = await ccxtExchange.fetchCurrencies() + } catch (err) { + node.payload.uiObject.setErrorMessage('Failed to Fetch Assets from the Exchange') + console.log(err.stack) + } + + for (let i = 0; i < ccxtAssets.length; i++) { + let ccxtAsset = ccxtAssets[i] + let newAsseet = functionLibraryUiObjectsFromNodes.addUIObject(node, 'Asset') + newAsseet.name = ccxtAsset.name + newAsseet.code = '{ \n\"codeName\": \"' + newAsseet.id + '\"\n}' + newAsseet.exchangeAssets.payload.floatingObject.angleToParent = ANGLE_TO_PARENT.RANGE_360 + newAsseet.exchangeMarkets.payload.floatingObject.distanceToParent = DISTANCE_TO_PARENT.PARENT_100X + } + } else { + node.payload.uiObject.setErrorMessage('This exchange does not provide a list of supported Assets.') + } } function addMissingMarkets (node, functionLibraryUiObjectsFromNodes) {