8
n8n 中文网amn8n.com

使用Google Sheets和Telegram提醒追踪多经纪商投资组合

中级

这是一个Crypto Trading领域的自动化工作流,包含 14 个节点。主要使用 If, Set, Code, Switch, Telegram 等节点。 使用Google Sheets和Telegram提醒追踪多经纪商投资组合

前置要求
  • Telegram Bot Token
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "40e2ddc17723de14c7d0537f9006dd246a3f4df33df6ca7f746ccb612d5f27b9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "6cc81650-0473-4b2a-bd23-abae6e3c81a7",
      "name": "条件判断",
      "type": "n8n-nodes-base.if",
      "position": [
        -840,
        60
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "376b39de-acc5-49d3-b618-4419a2aa8a25",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Telegram Trigger').item.json.body.message.chat.id }}",
              "rightValue": "={{ $json.myId }}"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "a038f750-3464-4143-b8a7-e4d244c556c5",
      "name": "获取表格中的行",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -260,
        260
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 580349873,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI/edit#gid=580349873",
          "cachedResultName": "Dashboard"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI/edit?usp=drivesdk",
          "cachedResultName": "Track Finances"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9NL9w5d9bKz7xt16",
          "name": "Akash Google Sheet Account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "7f066010-4fd1-4ccf-a407-05694051e4f7",
      "name": "获取表格中的行2",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -260,
        -40
      ],
      "parameters": {
        "options": {},
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $('Telegram Trigger').item.json.body.message.text.replaceAll(\"/\", \"\") }}",
              "lookupColumn": "Platform"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 580349873,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI/edit#gid=580349873",
          "cachedResultName": "Dashboard"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dakq9EhU8GrDgBsk82KvAen0N1P3FySAwNHFtG2lsLI/edit?usp=drivesdk",
          "cachedResultName": "Track Finances"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "9NL9w5d9bKz7xt16",
          "name": "Akash Google Sheet Account"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "1874c3d2-02e7-4faf-b592-af7c1b392d78",
      "name": "条件分支",
      "type": "n8n-nodes-base.switch",
      "position": [
        -580,
        40
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Specific Platform",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "6447e8ed-a64e-4d77-8b81-9716d971439d",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    },
                    "leftValue": "={{ $('Telegram Trigger').item.json.body.message.text }}",
                    "rightValue": "/total"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Total",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "3aef81cf-04a3-4eb3-9c12-accc41dd19f3",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $('Telegram Trigger').item.json.body.message.text }}",
                    "rightValue": "/total"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "e019c20d-4f7f-447a-9b24-0b3c7d1840d5",
      "name": "聚合",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -40,
        260
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "f8e95cdd-7020-4d9e-970f-ec9013be3268",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        220,
        260
      ],
      "parameters": {
        "jsCode": "const data = items[0].json.data;\n\nlet message = '📊 *Daily P&L Report*\\n\\n';\n\nconst formatCurrency = (value) =>\n  `₹${value.toLocaleString('en-IN', { minimumFractionDigits: 2 })}`;\n\nconst formatPercent = (value) => `${(value * 100).toFixed(2)}%`;\n\nfor (const row of data) {\n  if (row.Platform === 'Total') continue; // Skip Total for now\n\n  message += `*🔹 ${row.Platform}*\\n`;\n  message += `- Invested: ${formatCurrency(row[\"Invested Amount\"])}\\n`;\n  message += `- P&L: ${formatCurrency(row[\"PNL\"])} (${formatPercent(row[\"PNL %\"])})\\n`;\n  message += `- Change: ${formatCurrency(row[\"PNL Change\"])} (*${formatPercent(row[\"PNL Change %\"]) }*)\\n`;\n  message += `- Current Value: ${formatCurrency(row[\"Invested Amount\"] + row[\"PNL\"])}\\n\\n`;\n}\n\n// Add Total Portfolio section\nconst total = data.find((d) => d.Platform === 'Total');\nif (total) {\n  message += `*📈 Total Portfolio*\\n`;\n  message += `- Total Invested: ${formatCurrency(total[\"Invested Amount\"])}\\n`;\n  message += `- Total P&L: ${formatCurrency(total[\"PNL\"])} (${formatPercent(total[\"PNL %\"])})\\n`;\n  message += `- Today's Change: ${formatCurrency(total[\"PNL Change\"])} (*${formatPercent(total[\"PNL Change %\"]) }*)\\n\\n`;\n  message += `💰 *Overall Value*: ${formatCurrency(total[\"Invested Amount\"] + total[\"PNL\"])}\\n`;\n  message += `📈 *Overall Return*: *${formatPercent(total[\"PNL %\"])}*\\n`;\n  message += `💸 *Overall P&L*: ${formatCurrency(total[\"PNL\"])}\\n`;\n}\n\nreturn [{\n  json: {\n    chat_id:$('Edit Fields').first().json.myId ,\n    text: message,\n    parse_mode: \"Markdown\"\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "c37ddc50-eec3-4a8e-a0b1-b5216f0dfe99",
      "name": "代码1",
      "type": "n8n-nodes-base.code",
      "position": [
        -40,
        -40
      ],
      "parameters": {
        "jsCode": "const row = items[0].json;\n\nconst formatCurrency = (value) =>\n  `₹${value.toLocaleString('en-IN', { minimumFractionDigits: 2 }) }`;\n\nconst formatPercent = (value) =>\n  `${(value * 100).toFixed(2)}%`;\n\nconst invested = row[\"Invested Amount\"];\nconst pnl = row[\"PNL\"];\nconst change = row[\"PNL Change\"];\nconst pnlPercent = row[\"PNL %\"];\nconst changePercent = row[\"PNL Change %\"];\nconst currentValue = invested + pnl;\nconst platform = row[\"Platform\"].charAt(0).toUpperCase() + row[\"Platform\"].slice(1).toLowerCase();\n\nconst message = \n`📊 *Daily P&L Report*\\n\\n` +\n`*🔹 ${platform}*\\n` +\n`- Invested: ${formatCurrency(invested)}\\n` +\n`- P&L: ${formatCurrency(pnl)} (${formatPercent(pnlPercent)})\\n` +\n`- Change: ${formatCurrency(change)} (*${formatPercent(changePercent)}*)\\n` +\n`- Current Value: ${formatCurrency(currentValue)}`;\n\nreturn [{\n  json: {\n    chat_id: $('Edit Fields').first().json.myId,\n    text: message,\n    parse_mode: \"Markdown\"\n  }\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "61c27425-c7f1-44e2-b36a-386076e9abfd",
      "name": "Telegram触发器",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -1300,
        60
      ],
      "webhookId": "8fe1d478-06d9-4fd2-9e7f-b66d7fe13b38",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "[telegram-id]"
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "GoSthSk9tEcGAZrk",
          "name": "Telegram account 3"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "bc3603aa-cb9d-49f3-a9cb-83dd90b4d0b5",
      "name": "经纪商 PNL 更新",
      "type": "n8n-nodes-base.telegram",
      "position": [
        180,
        -40
      ],
      "webhookId": "5933d82d-50b2-4a7d-ad0b-15b9d5a70b34",
      "parameters": {
        "text": "={{ $json.text }}",
        "chatId": "={{ $json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "GoSthSk9tEcGAZrk",
          "name": "Telegram account 3"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "61c9441a-f243-49ab-824f-2148d3d9c48f",
      "name": "在上午 10 点和下午 4 点自动更新",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -560,
        260
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 16
            },
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "9d2f23f4-5371-45fb-8a03-f7d261f2a0dd",
      "name": "编辑字段",
      "type": "n8n-nodes-base.set",
      "position": [
        -1060,
        60
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "619c3c76-c797-454c-8995-3cb0c39b20d7",
              "name": "myId",
              "type": "string",
              "value": "=[telegram-id]"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "32f61af1-faea-4148-adb9-fd00ec437810",
      "name": "总 PNL 更新",
      "type": "n8n-nodes-base.telegram",
      "position": [
        440,
        260
      ],
      "webhookId": "5933d82d-50b2-4a7d-ad0b-15b9d5a70b34",
      "parameters": {
        "text": "={{ $json.text }}",
        "chatId": "={{ $json.chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "GoSthSk9tEcGAZrk",
          "name": "Telegram account 3"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "948fc47b-8d28-4358-9c69-bda130e026af",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2180,
        -340
      ],
      "parameters": {
        "color": 4,
        "width": 840,
        "height": 1520,
        "content": "## **适用于 n8n 的一体化投资组合追踪器和 Telegram 财务更新工作流:多经纪商、实时、全球覆盖 🚀**"
      },
      "typeVersion": 1
    },
    {
      "id": "90280429-7ef1-4fa2-b7dc-5a777faa0b91",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1320,
        -340
      ],
      "parameters": {
        "color": 3,
        "width": 780,
        "height": 300,
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "pinData": {
    "Telegram Trigger": [
      {
        "body": {
          "message": {
            "chat": {
              "id": 864930702,
              "type": "private",
              "username": "Akashkankariya25",
              "last_name": "Kankariya",
              "first_name": "Akash"
            },
            "date": 1752144799,
            "from": {
              "id": 864930702,
              "is_bot": false,
              "username": "Akashkankariya25",
              "last_name": "Kankariya",
              "first_name": "Akash",
              "language_code": "en"
            },
            "text": "/total",
            "entities": [
              {
                "type": "bot_command",
                "length": 9,
                "offset": 0
              }
            ],
            "message_id": 144
          },
          "update_id": 692524987
        },
        "query": {},
        "params": {},
        "headers": {
          "host": "127.0.0.1:8443",
          "connection": "upgrade",
          "content-type": "application/json",
          "content-length": "399",
          "accept-encoding": "gzip, deflate"
        },
        "webhookUrl": "https://n8n.algowiz.in:8443/webhook/7cfe9667-1d95-4bce-9977-1959d8765037",
        "executionMode": "production"
      }
    ]
  },
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Total PNL Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code1": {
      "main": [
        [
          {
            "node": "Broker PNL Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Broker PNL Update": {
      "main": [
        []
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet2": {
      "main": [
        [
          {
            "node": "Code1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Auto Update at 10AM and 4PM": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 加密货币交易

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量14
分类1
节点类型10
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Akash Kankariya

Akash Kankariya

@akash25

I'm a developer with 5 years of experience in Python and Node.js. Over the past year, I've been building workflows to streamline operations for my team. I have also developed RAG chatbots, AI agents, and WhatsApp automation. If you need any help with N8N workflows, let's connect over a call and solve it together!

外部链接
在 n8n.io 查看

分享此工作流