Skip to content

Instantly share code, notes, and snippets.

@obokaman-com
Last active March 28, 2024 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save obokaman-com/2e8395bf9898cdb760d00cded2a9cc51 to your computer and use it in GitHub Desktop.
Save obokaman-com/2e8395bf9898cdb760d00cded2a9cc51 to your computer and use it in GitHub Desktop.
n8n workflow to conduct a token analysis using OpenAI, based on Coingecko API information
{
"meta": {
"instanceId": "14a4579496eca8e63f6eac9a77d91fb8519619f23d5dabe63f5fc41397c8344e"
},
"nodes": [
{
"parameters": {},
"id": "d36d80c2-95e1-4ede-9189-d5a3d5fb9087",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
300,
380
]
},
{
"parameters": {
"prompt": "=Talk as an expert in web3 and crypto assets investmen, and financial analyts. \n\nFollowing you have some details about a crypto token.\n\nThe token name is {{ $node[\"Retrieve data from Coingecko\"].json[\"name\"] }}.\n\nThe description of this token from CoinGecko is\n\n\"\"\"\n{{ $node[\"Retrieve data from Coingecko\"].json[\"description\"][\"en\"] }}\n\"\"\"\n\n{{ $node[\"Retrieve data from Coingecko\"].json[\"sentiment_votes_up_percentage\"] }}% of people is voting up this token in Coingecko and {{ $node[\"Retrieve data from Coingecko\"].json[\"sentiment_votes_down_percentage\"] }}% is voting it down.\n\nIt's ranked as TOP {{ $node[\"Retrieve data from Coingecko\"].json[\"market_cap_rank\"] }} coin per market capitalization.\n\nIts market capitalization is {{ $node[\"Retrieve data from Coingecko\"].json[\"market_data\"][\"market_cap\"][\"usd\"] }}USD\n\nIts current price is {{ $json[\"market_data\"][\"current_price\"][\"usd\"] }}USD\n\nIt's CoinGecko score is {{ $node[\"Retrieve data from Coingecko\"].json[\"coingecko_score\"] }}/100.\nIt's developers score is {{ $node[\"Retrieve data from Coingecko\"].json[\"developer_score\"] }}/100.\nIt's community score is {{ $node[\"Retrieve data from Coingecko\"].json[\"community_score\"] }}/100.\nIt's liquidity score is {{ $node[\"Retrieve data from Coingecko\"].json[\"liquidity_score\"] }}/100.\n\nBased on this information I want to to give me:\n\n1. A quick SWOT analysis\n2. Your opinion about this asset\n3. Advice to evaluate the risk associated to this asset (avoid generic risk prevention advice)\n4. Your suggestion about the amount to invest in this asset in a diversified exclusively crypto portfolio, taking into account a $100K portfolio\n\nI want your output in native Spanish and marked up with HTML and separate each point in different paragraphs.\n\n--- ",
"options": {
"maxTokens": 3072,
"temperature": 0
}
},
"id": "a123f46d-13ae-4bae-8b33-b5fb54a5b884",
"name": "OpenAI",
"type": "n8n-nodes-base.openAi",
"typeVersion": 1,
"position": [
1700,
380
],
"credentials": {
"openAiApi": {
"id": "1",
"name": "OpenAi account"
}
}
},
{
"parameters": {
"url": "=https://api.coingecko.com/api/v3/coins/{{ $node[\"Search token\"].json[\"coins\"][0][\"api_symbol\"] }}",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
}
]
},
"options": {}
},
"id": "935983a5-b028-4e72-a1cc-a321f0d5ca02",
"name": "Retrieve data from Coingecko",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
1380,
380
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "description",
"value": "={{$node[\"Retrieve data from Coingecko\"].json[\"description\"][\"en\"]}}"
}
]
},
"options": {}
},
"id": "f253cc45-32cc-4ed1-91aa-826533ff22a6",
"name": "Get token description",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
1560,
380
]
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "opinion",
"value": "={{ $json[\"text\"] }}"
}
]
},
"options": {}
},
"id": "15330541-0bfc-4c3e-b399-adeca034db24",
"name": "Get OpenAI opinion",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
1840,
380
]
},
{
"parameters": {
"url": "=https://api.coingecko.com/api/v3/search?query={{ $node[\"Set chosen token\"].json[\"token\"] }}",
"options": {}
},
"id": "02c8351c-36db-4460-a21f-4c6e26348b97",
"name": "Search token",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
1060,
480
]
},
{
"parameters": {
"path": "82bf7756-c4a0-4081-b0dd-5558bf11eb78",
"responseMode": "responseNode",
"options": {}
},
"id": "6cc81c75-c0f9-4a3d-b684-e70a0495088c",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [
300,
560
],
"webhookId": "82bf7756-c4a0-4081-b0dd-5558bf11eb78"
},
{
"parameters": {
"respondWith": "text",
"responseBody": "=<html>\n<body style=\"line-height:2.2rem; font-size:1.2rem; font-family:sans-serif;\">\n<div style=\"max-width: 80rem; margin:4rem auto; padding:0 1rem;\">\n<h1>Opinión GPT3 sobre {{ $node[\"Set chosen token\"].json[\"token\"] }}</h1>\n<p><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}\">&laquo; Volver a la home</a></p>\n{{ $node[\"Check cache\"].json[\"response\"].opinion }}\n</div>\n<div style=\"background:white; padding:1rem; position:fixed; width:100%; bottom:0; text-align:center;\">Built with ❤️ by <a href=\"https://twitter.com/obokaman\">obokaman</a></div>\n</body>\n</html",
"options": {}
},
"id": "823d19b4-3403-40e5-a3c3-59f849d896d9",
"name": "Cached Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
1060,
300
]
},
{
"parameters": {
"respondWith": "text",
"responseBody": "=<html>\n<body style=\"line-height:2.2rem; font-size:1.2rem; font-family:sans-serif;\">\n<div style=\"max-width: 80rem; margin:4rem auto; padding:0 1rem;\">\n<h1>Opinión GPT3 sobre {{ $node[\"Set chosen token\"].json[\"token\"] }}</h1>\n<p><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}\">&laquo; Volver a la home</a></p>\n{{ $node[\"Get OpenAI opinion\"].json[\"opinion\"] }}\n</div>\n<div style=\"background:white; padding:1rem; position:fixed; width:100%; bottom:0; text-align:center;\">Built with ❤️ by <a href=\"https://twitter.com/obokaman\">obokaman</a></div>\n</body>\n</html",
"options": {}
},
"id": "b030e01e-f259-4388-bfb5-e5372daa0f0c",
"name": "Built Response",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
2120,
380
]
},
{
"parameters": {
"jsCode": "const static_data = $getWorkflowStaticData(\"global\");\n\nif (undefined == static_data.token_opinion)\n{\n static_data.token_opinion = {};\n}\n\nvar opinion = {\n \"token\": $items('Set chosen token')[0].json.token,\n \"opinion\": $items(\"Get OpenAI opinion\")[0].json.opinion\n};\n\nstatic_data.token_opinion.push(opinion);\n\nreturn [{json: { static_data } }];"
},
"id": "cd77b468-d6ac-4ea5-9caa-2ad1442d631c",
"name": "Save to cache",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
1980,
380
]
},
{
"parameters": {
"jsCode": "const static_data = $getWorkflowStaticData('global');\n\nif ($items('Webhook')[0].json.query.clear_cache == \"true\")\n{\n static_data.token_opinion = static_data.token_opinion.filter(function(obj){\n return obj.token !== $items('Set chosen token')[0].json.token;\n });\n}\n\nif (undefined === static_data.token_opinion)\n{\n static_data.token_opinion = [];\n}\n\nif (static_data.token_opinion.findIndex( x => x.token === $items('Set chosen token')[0].json.token) != -1)\n{\n return [{json: {\"response\": static_data.token_opinion.find( x => x.token === $items('Set chosen token')[0].json.token)}}];\n}\n\nreturn [{json: { \"response\": \"\" }}];"
},
"id": "a6a4b971-357f-494b-9bc1-5357051481d6",
"name": "Check cache",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
740,
380
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": true,
"value2": "={{ Boolean($json[\"response\"]) }}"
}
]
}
},
"id": "bc4d8d3d-ac58-4cfe-bbda-7264335f1602",
"name": "If it's cached",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
880,
380
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "token",
"value": "={{ $node[\"Webhook\"].json[\"query\"][\"token\"] ?? 'Bitcoin' }}"
}
]
},
"options": {}
},
"id": "7d261a78-433e-4e6f-a280-97f25ceb46ea",
"name": "Set chosen token",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
600,
380
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": true,
"value2": "={{ ( typeof $node[\"Search token\"].json[\"coins\"] != 'undefined' && Array.isArray($node[\"Search token\"].json[\"coins\"]) && $node[\"Search token\"].json[\"coins\"].length > 0 ) }}"
}
]
}
},
"id": "4f7d184e-7d85-4ca9-9a25-f186559408d4",
"name": "If exists",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1220,
480
]
},
{
"parameters": {
"respondWith": "text",
"responseBody": "=<html>\n<body style=\"line-height:2.2rem; font-size:1.2rem; font-family:sans-serif;\">\n<div style=\"max-width: 80rem; margin:4rem auto; padding:0 1rem;\">\n<h1>📊 Análisis de criptoactivos</h1>\n<h2 style=\"font-weight:normal; font-size:1.8rem; margin:-1rem 4rem 4rem;\">Elaborado usando GPT-3 y datos extraídos de la API de Coingecko</h1>\n<p>ℹ️ Debes añadir un parámetro \"<code>?token=[criptoactivo]</code>\" a la URL para poder responderte.</p>\n<p>Por ejemplo:\n<ul>\n<li><strong>Bitcoin</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bitcoin\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bitcoin</a></code></li>\n<li><strong>Ethereum</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=ethereum\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=ethereum</a></code></li>\n<li><strong>BNB</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bnb\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bnb</a></code></li>\n<li><strong>Polkadot</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=polkadot\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=polkadot</a></code></li>\n<li><strong>Polygon</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=matic\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=matic</a></code></li>\n<li><strong>TUT</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=tutellus\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=tutellus</a></code></li>\n</ul>\n</p>\n<p style=\"font-size:1rem; text-align: center;\">⏳ Ten paciencia: la primera vez que elabore el informe de un token nuevo puede tardar unos 30 segundos.</p>\n</div>\n<div style=\"background:white; padding:1rem; position:fixed; width:100%; bottom:0; text-align:center;\">Built with ❤️ by <a href=\"https://twitter.com/obokaman\">obokaman</a></div>\n</body>\n</html",
"options": {}
},
"id": "9c923d77-9855-449c-ba31-44f252faf1e0",
"name": "Homepage",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
580,
580
]
},
{
"parameters": {
"respondWith": "text",
"responseBody": "=<html>\n<body style=\"line-height:2.2rem; font-size:1.2rem; font-family:sans-serif;\">\n<div style=\"max-width: 80rem; margin:4rem auto; padding:0 1rem;\">\n<h1>⚠️ Ops, no he podido encontrar \"{{ $node[\"Set chosen token\"].json[\"token\"] }}\"</h1>\n<h2 style=\"font-weight:normal; font-size:1.8rem; margin:-1rem 4rem 4rem;\">\"{{ $node[\"Set chosen token\"].json[\"token\"] }}\" no parece estar listado en Coingecko</h2>\n<p>Puedes probar con otras monedas como:\n<ul>\n<li><strong>Bitcoin</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bitcoin\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bitcoin</a></code></li>\n<li><strong>Ethereum</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=ethereum\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=ethereum</a></code></li>\n<li><strong>BNB</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bnb\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=bnb</a></code></li>\n<li><strong>Polkadot</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=polkadot\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=polkadot</a></code></li>\n<li><strong>Polygon</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=matic\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=matic</a></code></li>\n<li><strong>TUT</strong>: <code style=\"font-size:0.9rem\"><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=tutellus\">{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}?token=tutellus</a></code></li></ul>\n</p>\n<p><a href=\"{{ $env.WEBHOOK_URL }}webhook/{{ $node[\"Webhook\"].parameter[\"path\"] }}\">&laquo; Volver a la home</a></p>\n</div>\n<div style=\"background:white; padding:1rem; position:fixed; width:100%; bottom:0; text-align:center;\">Built with ❤️ by <a href=\"https://twitter.com/obokaman\">obokaman</a></div>\n</body>\n</html\n\n",
"options": {}
},
"id": "43e29474-d43f-4ce0-ae43-8472a1532462",
"name": "Not found",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1,
"position": [
1380,
580
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value2": "={{ $node[\"Webhook\"].json.query[\"token\"] == undefined || $node[\"Webhook\"].json.query[\"token\"] == \"\" }}"
}
]
}
},
"id": "4b4810f6-1db6-4d1b-aa3c-8f975b9ffa4d",
"name": "IF token in URL",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
440,
560
]
}
],
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Set chosen token",
"type": "main",
"index": 0
}
]
]
},
"OpenAI": {
"main": [
[
{
"node": "Get OpenAI opinion",
"type": "main",
"index": 0
}
]
]
},
"Retrieve data from Coingecko": {
"main": [
[
{
"node": "Get token description",
"type": "main",
"index": 0
}
]
]
},
"Get token description": {
"main": [
[
{
"node": "OpenAI",
"type": "main",
"index": 0
}
]
]
},
"Get OpenAI opinion": {
"main": [
[
{
"node": "Save to cache",
"type": "main",
"index": 0
}
]
]
},
"Search token": {
"main": [
[
{
"node": "If exists",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "IF token in URL",
"type": "main",
"index": 0
}
]
]
},
"Save to cache": {
"main": [
[
{
"node": "Built Response",
"type": "main",
"index": 0
}
]
]
},
"Check cache": {
"main": [
[
{
"node": "If it's cached",
"type": "main",
"index": 0
}
]
]
},
"If it's cached": {
"main": [
[
{
"node": "Cached Response",
"type": "main",
"index": 0
}
],
[
{
"node": "Search token",
"type": "main",
"index": 0
}
]
]
},
"Set chosen token": {
"main": [
[
{
"node": "Check cache",
"type": "main",
"index": 0
}
]
]
},
"If exists": {
"main": [
[
{
"node": "Retrieve data from Coingecko",
"type": "main",
"index": 0
}
],
[
{
"node": "Not found",
"type": "main",
"index": 0
}
]
]
},
"IF token in URL": {
"main": [
[
{
"node": "Set chosen token",
"type": "main",
"index": 0
}
],
[
{
"node": "Homepage",
"type": "main",
"index": 0
}
]
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment