{
  "id": "HMh7K0lzn0qHpHdB",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Futures Trade Tracker with Profit/Loss Monitoring + Alerts",
  "tags": [],
  "nodes": [
    {
      "id": "14da5758-d51f-4a0d-9983-ef2b25eb620f",
      "name": "Schedule Trades Check",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        752
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "5acab6a1-f7c0-4bbf-8036-b58e135a5d12",
      "name": "Trade Positions",
      "type": "n8n-nodes-base.code",
      "position": [
        224,
        752
      ],
      "parameters": {
        "jsCode": "return [\n  { json: { symbol: \"BTCUSDT\", entry_price: 50000, quantity: 0.1 } },\n  { json: { symbol: \"ETHUSDT\", entry_price: 3000, quantity: 1 } },\n  { json: { symbol: \"BNBUSDT\", entry_price: 400, quantity: 2 } }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "4e2d4462-b900-47ae-89ab-e50a3fe986ff",
      "name": "Market Price (Binance)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        448,
        824
      ],
      "parameters": {
        "url": "=https://api.binance.com/api/v3/ticker/price?symbol={{$json[\"symbol\"]}}",
        "options": {}
      },
      "typeVersion": 4.4
    },
    {
      "id": "f85779cb-8f33-43c5-8309-69699fc62e4c",
      "name": "Trade + Market Data",
      "type": "n8n-nodes-base.merge",
      "position": [
        672,
        752
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition"
      },
      "typeVersion": 3.2
    },
    {
      "id": "2e3dee82-f377-4bdc-8643-4d15a4437eb5",
      "name": "Valid Trades Only",
      "type": "n8n-nodes-base.if",
      "position": [
        1120,
        752
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4d60f74e-5a09-4709-b561-aaadc0a3c051",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.net_pnl }} ",
              "rightValue": -50
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.3
    },
    {
      "id": "c1abd5a1-68a7-4727-a3ef-35e6c0dde21e",
      "name": "Risk Scoring Engine",
      "type": "n8n-nodes-base.code",
      "position": [
        1344,
        752
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "let score = 0;\n\nif ($json.net_pnl < -100) score += 6;\nif ($json.net_pnl < -50) score += 3;\nif ($json.quantity > 1) score += 2;\n\n$json.risk_score = score;\n\nreturn $json;"
      },
      "typeVersion": 2
    },
    {
      "id": "06ac04f9-df2d-4e2c-bef6-b833dd0e9e40",
      "name": "Alert Severity Split",
      "type": "n8n-nodes-base.switch",
      "position": [
        1568,
        352
      ],
      "parameters": {
        "mode": "expression",
        "output": "={{\n  $json.risk_score > 6 ? 2 :\n  $json.risk_score > 3 ? 1 : 0\n}}",
        "numberOutputs": 3
      },
      "typeVersion": 3.4
    },
    {
      "id": "8b90f522-e24e-494f-a74b-d711a81de8f6",
      "name": "Trade History",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1808,
        1248
      ],
      "parameters": {
        "columns": {
          "value": {
            "ROI": "={{ $json.roi }}",
            "PNL ": "={{ $json.pnl }}",
            "Symbol": "={{ $json.symbol }}",
            "Net_PNL": "={{ $json.net_pnl }}",
            "TimeStamp": "={{ $now }}",
            "Entry_Price ": "={{ $json.entry_price }}",
            "Current_Price": "={{ $json.current_price }}"
          },
          "schema": [
            {
              "id": "Symbol",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Symbol",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Entry_Price ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Entry_Price ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Current_Price",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Current_Price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "PNL ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "PNL ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Net_PNL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Net_PNL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ROI",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "ROI",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "TimeStamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "TimeStamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU/edit#gid=0",
          "cachedResultName": "Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU/edit?usp=drivesdk",
          "cachedResultName": "Trade_Tracker"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "2ee2fb0c-2253-4f7c-9c92-214d545ad8bd",
      "name": "Execution Summary",
      "type": "n8n-nodes-base.set",
      "position": [
        2032,
        1248
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "5665a353-9e4e-4a18-972e-cf22d42086d3",
              "name": "Status",
              "type": "string",
              "value": "Success"
            },
            {
              "id": "298581b5-1074-4921-9a11-c9967d188f59",
              "name": "Symbol",
              "type": "string",
              "value": "={{ $json.Symbol }}"
            },
            {
              "id": "623482aa-167f-4f38-947f-fa0345e70b45",
              "name": "Net_PNL",
              "type": "number",
              "value": "={{ $json.Net_PNL }}"
            },
            {
              "id": "98cf7116-ea9d-4d4d-8d19-c3ae8c936905",
              "name": "TimeStamp",
              "type": "string",
              "value": "={{ $json.TimeStamp }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3fcdeef9-f508-4f4e-8c1c-d264e4fb498c",
      "name": "Daily Analytics",
      "type": "n8n-nodes-base.code",
      "position": [
        2256,
        1248
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "$json.day = new Date().toISOString().split(\"T\")[0];\n$json.trade_count = 1;\n\nreturn $json;"
      },
      "typeVersion": 2
    },
    {
      "id": "03bd0e1b-a73a-4881-9454-611b9f9ff93f",
      "name": "Analytics Summary",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2448,
        1248
      ],
      "parameters": {
        "columns": {
          "value": {
            "Day": "={{ $json.day }}",
            "Net_PNL": "={{ $json.Net_PNL }}",
            "Trade_Count ": "={{ $json.trade_count }}"
          },
          "schema": [
            {
              "id": "Day",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Day",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Trade_Count ",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Trade_Count ",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Net_PNL",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Net_PNL",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 163722985,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU/edit#gid=163722985",
          "cachedResultName": "Analytics"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/11aBlqNl86Ek8U-IgD_zjhO4qC5j91CwgyQm3ECe9waU/edit?usp=drivesdk",
          "cachedResultName": "Trade_Tracker"
        },
        "authentication": "serviceAccount"
      },
      "credentials": {
        "googleApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "afd2ca1e-eebd-4c3d-bf24-bec5bf781a1f",
      "name": "Slack (LOW RISK)",
      "type": "n8n-nodes-base.slack",
      "position": [
        2208,
        -208
      ],
      "parameters": {
        "text": "=Trade Alert\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AQ2CNTV0C",
          "cachedResultName": "trade-alerts"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "ec542c11-7937-4b4d-bbec-1000b312f812",
      "name": "Slack (MEDIUM RISK)",
      "type": "n8n-nodes-base.slack",
      "position": [
        2208,
        0
      ],
      "parameters": {
        "text": "=Trade Alert\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AQ2CNTV0C",
          "cachedResultName": "trade-alerts"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "1187d7a4-5343-431d-bfff-49f8cd1503c3",
      "name": "Telegram (MEDIUM RISK)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2224,
        208
      ],
      "parameters": {
        "text": "=Trade Alert\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "chatId": "123456789",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "30b688d4-d5cb-4a3a-8cea-982dbadcaff5",
      "name": "Slack (HIGH RISK)",
      "type": "n8n-nodes-base.slack",
      "position": [
        2224,
        416
      ],
      "parameters": {
        "text": "=Trade Alert\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AQ2CNTV0C",
          "cachedResultName": "trade-alerts"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "b320365e-c92a-4a29-ac64-d94f7e34f2d2",
      "name": "Jira (HIGH RISK)",
      "type": "n8n-nodes-base.jira",
      "position": [
        2224,
        608
      ],
      "parameters": {
        "project": {
          "__rl": true,
          "mode": "list",
          "value": "10034",
          "cachedResultName": "Trade-Alerts"
        },
        "summary": "HIGH RISK TRADE ALERT",
        "issueType": {
          "__rl": true,
          "mode": "list",
          "value": "10042",
          "cachedResultName": "Task"
        },
        "additionalFields": {}
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fafa70e7-5b7d-4130-bdc7-e625576afcc1",
      "name": "Telegram  (HIGH RISK)",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2224,
        800
      ],
      "parameters": {
        "text": "=Trade Aler\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "chatId": "123456789",
        "additionalFields": {
          "appendAttribution": true
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "cef0210a-e844-4190-9423-255ce43d3535",
      "name": "Gmail  (HIGH RISK)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2224,
        992
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "=HIGH RISK TRADE  \nTrade Alert\nSymbol: {{$json.symbol}}\nPnL: {{$json.net_pnl}}\nSignal: {{$json.signal}}",
        "options": {},
        "subject": "HIGH ALERT",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0f8fcad8-84bd-453e-ae95-c69bb9ca972b",
      "name": "PROCESS - Trade Metrics Engine",
      "type": "n8n-nodes-base.code",
      "position": [
        896,
        752
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Extract values\nconst entry = parseFloat($json.entry_price);\nconst current = parseFloat($json.price);   // IMPORTANT FIX\nconst quantity = parseFloat($json.quantity);\n\n// Validate values\nif (!entry || !current || !quantity) {\n  return $json;\n}\n\n// Calculate PnL\nconst pnl = (current - entry) * quantity;\n\n// Fees (0.1%)\nconst fees = Math.abs(pnl) * 0.001;\n\n// Net PnL\nconst net_pnl = pnl - fees;\n\n// ROI\nconst investment = entry * quantity;\nconst roi = (net_pnl / investment) * 100;\n\n// Attach results\n$json.current_price = current;\n$json.pnl = pnl;\n$json.fees = fees;\n$json.net_pnl = net_pnl;\n$json.roi = roi.toFixed(2);\n\nreturn $json;"
      },
      "typeVersion": 2
    },
    {
      "id": "dcc0c14d-7327-439c-9a0d-89789fab3a41",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -768,
        80
      ],
      "parameters": {
        "width": 608,
        "height": 480,
        "content": "## Futures Trade Monitoring & Risk Alert System\nThis workflow automates futures trade monitoring and risk-based alerting. It fetches live market prices, calculates trade performance (PnL, ROI, fees), evaluates risk levels and sends alerts via Slack, Telegram, Jira and Email based on severity.\n\n### How it works:\nThe workflow starts with scheduled execution, reads trade data, fetches real-time prices from Binance and processes trade metrics using a centralized calculation engine. Based on risk scoring, trades are categorized into severity levels and routed to appropriate alert channels. All trade data and analytics are stored in Google Sheets.\n\n### Setup steps:\n\nConfigure trade input (Function or Google Sheets).\nSet up API connection for price data.\nConnect Slack, Telegram, Jira and Email credentials.\nConfigure Google Sheets for trade history and analytics.\n\nThis workflow helps traders monitor positions automatically, reduce manual effort and react quickly to market changes."
      },
      "typeVersion": 1
    },
    {
      "id": "83583fed-6bb4-4a20-82e5-9e888d2fe770",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        624
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 368,
        "content": "## INPUT & MARKET DATA\nThis section initializes the workflow by defining trade positions and fetching live market prices from the Binance API."
      },
      "typeVersion": 1
    },
    {
      "id": "57d92e6b-6116-49dc-83c8-10f01c8d56ca",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        240
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 704,
        "content": "## TRADE PROCESSING ENGINE\nCalculates trade metrics such as PnL, ROI and fees. Filters valid trades and assigns risk scores for decision-making."
      },
      "typeVersion": 1
    },
    {
      "id": "100e1995-1751-4aab-b45a-2b2eb7cfc533",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1760,
        -368
      ],
      "parameters": {
        "color": 7,
        "width": 992,
        "height": 1792,
        "content": "## ALERTING & DATA STORAGE\nRoutes alerts based on risk level and stores trade data and analytics in Google Sheets for tracking and reporting."
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "09db76a5-4768-4949-8be0-ca407cd7e5de",
  "connections": {
    "Trade History": {
      "main": [
        [
          {
            "node": "Execution Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Daily Analytics": {
      "main": [
        [
          {
            "node": "Analytics Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trade Positions": {
      "main": [
        [
          {
            "node": "Trade + Market Data",
            "type": "main",
            "index": 0
          },
          {
            "node": "Market Price (Binance)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Jira (HIGH RISK)": {
      "main": [
        []
      ]
    },
    "Slack (LOW RISK)": {
      "main": [
        []
      ]
    },
    "Analytics Summary": {
      "main": [
        []
      ]
    },
    "Execution Summary": {
      "main": [
        [
          {
            "node": "Daily Analytics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack (HIGH RISK)": {
      "main": [
        []
      ]
    },
    "Valid Trades Only": {
      "main": [
        [
          {
            "node": "Risk Scoring Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail  (HIGH RISK)": {
      "main": [
        []
      ]
    },
    "Risk Scoring Engine": {
      "main": [
        [
          {
            "node": "Alert Severity Split",
            "type": "main",
            "index": 0
          },
          {
            "node": "Trade History",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack (MEDIUM RISK)": {
      "main": [
        []
      ]
    },
    "Trade + Market Data": {
      "main": [
        [
          {
            "node": "PROCESS - Trade Metrics Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Severity Split": {
      "main": [
        [
          {
            "node": "Slack (LOW RISK)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack (MEDIUM RISK)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Telegram (MEDIUM RISK)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack (HIGH RISK)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Telegram  (HIGH RISK)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Jira (HIGH RISK)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Gmail  (HIGH RISK)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trades Check": {
      "main": [
        [
          {
            "node": "Trade Positions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram  (HIGH RISK)": {
      "main": [
        []
      ]
    },
    "Market Price (Binance)": {
      "main": [
        [
          {
            "node": "Trade + Market Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Telegram (MEDIUM RISK)": {
      "main": [
        []
      ]
    },
    "PROCESS - Trade Metrics Engine": {
      "main": [
        [
          {
            "node": "Valid Trades Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}