{ "name": "Kraken_REST_API_Example", "nodes": [ { "parameters": {}, "name": "Start", "type": "n8n-nodes-base.start", "typeVersion": 1, "position": [ 250, 300 ] }, { "parameters": { "triggerTimes": { "item": [ { "hour": 12 } ] } }, "name": "Cron", "type": "n8n-nodes-base.cron", "typeVersion": 1, "position": [ 50, 1100 ] }, { "parameters": { "unit": "minutes" }, "name": "Interval", "type": "n8n-nodes-base.interval", "typeVersion": 1, "position": [ 50, 1400 ], "disabled": true }, { "parameters": { "chatId": "-557603531", "text": "={{$json[\"Message\"]}}", "additionalFields": {} }, "name": "Telegram", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "position": [ 1400, 1450 ], "credentials": { "telegramApi": "N8N Workflows" } }, { "parameters": { "values": { "string": [ { "name": "API Public Key", "value": "zu2Z/3ivwwtLO3f2xOdJAEmIDbTdYnTM2B7edxXCI57a8r0j6GQITDtz" }, { "name": "API Private Key", "value": "OUfFLoPP5cB3NIEWJTIy1nsfn3axqQhk39Dle0qsxMznnLj3CBIIayXkXPtTXJRcGA3RtuKuw5119R33PTT5ig==" }, { "name": "Currency Pair", "value": "DOGE/USD" }, { "name": "Amount", "value": "50" } ], "number": [] }, "options": {} }, "name": "API Settings", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [ 200, 1250 ], "notesInFlow": false }, { "parameters": { "type": "SHA256", "value": "={{$json[\"api_nonce\"] + $json[\"api_json\"]}}", "encoding": "base64" }, "name": "API auth 1", "type": "n8n-nodes-base.crypto", "typeVersion": 1, "position": [ 500, 1250 ] }, { "parameters": { "action": "hmac", "type": "SHA512", "value": "={{Buffer.concat([Buffer.from($json.api_path, 'utf8'), Buffer.from($json[\"data\"], \"base64\")])}}", "secret": "={{Buffer.from($node['API Settings'].json['API Private Key'], 'base64')}}", "encoding": "base64" }, "name": "API auth 2", "type": "n8n-nodes-base.crypto", "typeVersion": 1, "position": [ 650, 1250 ] }, { "parameters": { "requestMethod": "POST", "url": "={{'https://api.kraken.com' + $node['API auth 2'].json[\"api_path\"]}}", "allowUnauthorizedCerts": true, "jsonParameters": true, "options": { "bodyContentType": "raw" }, "bodyParametersJson": "={{$json[\"api_json\"]}}", "headerParametersJson": "={{{\"API-Key\":$node[\"API Settings\"].json[\"API Public Key\"], \"API-Sign\":$json[\"data\"], \"Content-type\":\"application/json\"}}}" }, "name": "API request", "type": "n8n-nodes-base.httpRequest", "typeVersion": 1, "position": [ 800, 1250 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{$json[\"error\"][0]}}", "operation": "isEmpty" } ], "boolean": [] } }, "name": "API error check", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 950, 1250 ] }, { "parameters": { "conditions": { "string": [ { "value1": "={{$node[\"API request\"].parameter[\"url\"]}}", "operation": "endsWith", "value2": "AddOrder" } ], "boolean": [] } }, "name": "Logic 1", "type": "n8n-nodes-base.if", "typeVersion": 1, "position": [ 1100, 1230 ] }, { "parameters": { "functionCode": "const api_path = '/0/private/Balance';\nconst api_nonce = Date.now().toString();\nconst api_json = '{\"assetVersion\":\"1\", \"nonce\":\"' + api_nonce + '\"}';\nconst api_variables = [];\napi_variables.push({\"json\":{\"api_path\":api_path, \"api_nonce\":api_nonce, \"api_json\":api_json}});\nreturn api_variables;" }, "name": "JavaScript 2", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [ 650, 1050 ] }, { "parameters": { "functionCode": "const api_base = $node['API Settings'].json['Currency Pair'].split('/')[0];\nconst api_quote = $node['API Settings'].json['Currency Pair'].split('/')[1];\nconst api_path = '/0/private/AddOrder';\nconst api_nonce = Date.now().toString();\nconst api_json = '{\"pair\":\"' + $node['API Settings'].json['Currency Pair'] + '\", \"type\":\"buy\", \"ordertype\":\"market\", \"volume\":\"' + $node['API Settings'].json['Amount'] + '\", \"assetVersion\":\"1\", \"nonce\":\"' + api_nonce + '\"}';\nconst api_variables = [];\napi_variables.push({\"json\":{\"api_base\":api_base, \"api_quote\":api_quote, \"api_path\":api_path, \"api_nonce\":api_nonce, \"api_json\":api_json}});\nreturn api_variables;" }, "name": "JavaScript 1", "type": "n8n-nodes-base.function", "typeVersion": 1, "position": [ 350, 1250 ] }, { "parameters": { "keepOnlySet": true, "values": { "string": [ { "name": "Message", "value": "={{\"Your new \" + $node[\"JavaScript 1\"].json[\"api_base\"] + \" balance is \" + $json['result'][$node[\"JavaScript 1\"].json[\"api_base\"]]}}" } ], "number": [] }, "options": {} }, "name": "TG message 1", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [ 1250, 1250 ] }, { "parameters": { "keepOnlySet": true, "values": { "string": [ { "name": "Message", "value": "={{\"Your \" + $node[\"API Settings\"].json[\"Currency Pair\"] + \" purchase failed because you do not have enough \" + $node[\"JavaScript 1\"].json[\"api_quote\"]}}" } ], "number": [] }, "options": {} }, "name": "TG message 2", "type": "n8n-nodes-base.set", "typeVersion": 1, "position": [ 1100, 1450 ] } ], "connections": { "Cron": { "main": [ [ { "node": "API Settings", "type": "main", "index": 0 } ] ] }, "Interval": { "main": [ [ { "node": "API Settings", "type": "main", "index": 0 } ] ] }, "API Settings": { "main": [ [ { "node": "JavaScript 1", "type": "main", "index": 0 } ] ] }, "API auth 1": { "main": [ [ { "node": "API auth 2", "type": "main", "index": 0 } ] ] }, "API auth 2": { "main": [ [ { "node": "API request", "type": "main", "index": 0 } ] ] }, "API request": { "main": [ [ { "node": "API error check", "type": "main", "index": 0 } ] ] }, "API error check": { "main": [ [ { "node": "Logic 1", "type": "main", "index": 0 } ], [ { "node": "TG message 2", "type": "main", "index": 0 } ] ] }, "Logic 1": { "main": [ [ { "node": "JavaScript 2", "type": "main", "index": 0 } ], [ { "node": "TG message 1", "type": "main", "index": 0 } ] ] }, "JavaScript 2": { "main": [ [ { "node": "API auth 1", "type": "main", "index": 0 } ] ] }, "JavaScript 1": { "main": [ [ { "node": "API auth 1", "type": "main", "index": 0 } ] ] }, "TG message 1": { "main": [ [ { "node": "Telegram", "type": "main", "index": 0 } ] ] }, "TG message 2": { "main": [ [ { "node": "Telegram", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": {}, "id": "1005" }