{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "44e1285f-6c41-4d32-97d7-18b1f59938df",
      "name": "Sticky Note - Summary",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        128
      ],
      "parameters": {
        "width": 600,
        "height": 348,
        "content": "## \ud83d\ude80 Crypto Arbitrage Analyzer\n\n### How it works\nThis workflow monitors the \"Kimchi Premium\" (price gap) between Bitcoin prices on Binance (Global) and Upbit (Korea). It fetches real-time data, converts currencies using live Forex rates, and uses an AI Agent to generate and email a strategic arbitrage report.\n\n### Setup steps\n1. **OpenAI**: Add your API Key to the **OpenAI Chat Model** nodes.\n2. **Gmail**: Connect your Google account in the **Send a Message** node and update the `To` email address.\n3. **Schedule**: Adjust the **Schedule Trigger** node to change how often the analysis runs (currently every 30 mins)."
      },
      "typeVersion": 1
    },
    {
      "id": "c00ea924-89bd-4fc5-914d-e2ba049659c9",
      "name": "Sticky Note - Fetching",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        512
      ],
      "parameters": {
        "color": 7,
        "width": 440,
        "height": 680,
        "content": "## 1. Data Collection\nTriggers on a schedule to fetch live BTC prices from Binance and Upbit, along with the real-time USD/KRW exchange rate."
      },
      "typeVersion": 1
    },
    {
      "id": "31a5f3e3-e311-4307-b434-e3afe25bce6d",
      "name": "Sticky Note - Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        512
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 680,
        "content": "## 2. Normalization\nStandardizes data formats from the different exchanges and merges them into a single dataset for the AI to process."
      },
      "typeVersion": 1
    },
    {
      "id": "17992c0c-6e98-4ca2-a02c-ef39f3cc4f4f",
      "name": "Sticky Note - AI",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        512
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 680,
        "content": "## 3. Analysis & Report\nAn AI Agent calculates the price spread, determines profitability, formats a report, and sends it via Gmail."
      },
      "typeVersion": 1
    },
    {
      "id": "c9461ba4-09ed-4b13-ab92-2bb170ef6207",
      "name": "OpenAI Chat Model for Analyzer",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -16,
        832
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {
          "codeInterpreter": true
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "6c3e2914-352c-4515-a649-da30da3b19b4",
      "name": "OpenAI Chat Model for Format",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        144,
        1008
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "fc23dffc-e7d2-42ca-82e1-b2a9ee9eb14c",
      "name": "Send a Message for Traders",
      "type": "n8n-nodes-base.gmail",
      "position": [
        544,
        800
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $input.last().json.output.message}}",
        "options": {},
        "subject": "={{ $input.last().json.output.subject }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "e25223cc-ea3f-4904-8527-8d354ffa914c",
      "name": "Merge Data",
      "type": "n8n-nodes-base.merge",
      "position": [
        -272,
        800
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "f86e26fa-3ca6-42f7-a018-7f0520ac7adf",
      "name": "Edit Fields For Binance Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -496,
        624
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "1c1423d9-600e-4f0f-b146-2e45caafb354",
              "name": "Exchange",
              "type": "string",
              "value": "Binance"
            },
            {
              "id": "206aa053-9e85-42e9-9a4f-6973f905c12d",
              "name": "Markets",
              "type": "string",
              "value": "USDT-BTC"
            },
            {
              "id": "179f9175-f4a2-4229-b5bf-df1028c2aa79",
              "name": "Price",
              "type": "number",
              "value": "={{ $json.price }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "bbd4f606-80a8-4b2a-8eb9-4014264b81b4",
      "name": "Edit Fields For Upbit Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -496,
        816
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b926c46d-e023-4d60-b17a-e8d2978a1521",
              "name": "Exchange",
              "type": "string",
              "value": "Upbit"
            },
            {
              "id": "705b8da6-afd8-4ad2-b081-435aea88cbe3",
              "name": "Markets",
              "type": "string",
              "value": "={{ $json.market }}"
            },
            {
              "id": "d1ec3aeb-511b-4311-ad6e-bc478025d5f9",
              "name": "Price",
              "type": "number",
              "value": "={{ $json.trade_price }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "a48c581d-0bc6-41ae-9d15-6f42fd635d0f",
      "name": "Edit Fields For Forex Data",
      "type": "n8n-nodes-base.set",
      "position": [
        -496,
        1008
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b926c46d-e023-4d60-b17a-e8d2978a1521",
              "name": "Exchange",
              "type": "string",
              "value": "Forex"
            },
            {
              "id": "705b8da6-afd8-4ad2-b081-435aea88cbe3",
              "name": "Markets",
              "type": "string",
              "value": "=USDKRW=X"
            },
            {
              "id": "d1ec3aeb-511b-4311-ad6e-bc478025d5f9",
              "name": "Price",
              "type": "number",
              "value": "={{ $json.rate }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d2598c2e-60b1-4e3b-982e-6de417787507",
      "name": "Get price from Forex",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -704,
        1008
      ],
      "parameters": {
        "url": "https://api.manana.kr/exchange/rate/KRW/USD.json",
        "options": {}
      },
      "typeVersion": 4.3
    },
    {
      "id": "7971f4e4-e833-41c3-b726-f768d7b9e468",
      "name": "Get price from Binance",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -704,
        624
      ],
      "parameters": {
        "url": "https://api.binance.com/api/v3/trades",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "symbol",
              "value": "BTCUSDT"
            },
            {
              "name": "limit",
              "value": "1"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "275c85ef-b6ca-4cdd-823f-cbf8d289961a",
      "name": "Analyzer",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        80,
        608
      ],
      "parameters": {
        "text": "=Write a report with this price data and send a message to a trader.\n\nTimestamp:{{ $('Schedule Trigger').item.json.timestamp }}\n\n{{ $input.all().map((item, index) => `\n  Exchange: ${item.json.Exchange}\n  Markets: ${item.json.Markets}\n  Price: ${item.json.Price}\n`).join('')}}",
        "options": {
          "systemMessage": "You are a helpful analyst that provides information about the price gap of Bitcoin, KRW, USD between two markets(World based market Binance and Korea based market Upbit) and Forex.\nUse <br> and symbols to optimize readability for mail format and do not use \\n when split line.\nDon't write any unnecessary messages other than body of mail. Just write a subject and body of the mail in 3~4 paragraphs."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "executeOnce": true,
      "typeVersion": 3
    },
    {
      "id": "06563f09-988a-474d-974f-e9abf4f27405",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        144,
        832
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{\n\t\"subject\": \"Arbitrage Snapshot \u2014 BTC price gap Binance vs Upbit (2025-12-01T03:04:47-05:00)\",\n\t\"message\": \"2025-12-01 03:04:47-05:00<br><br><b>Current Prices:</b><br>- Binance (USDT-BTC): 86,410.80 USDT<br>- Upbit (USDT-BTC): 86,474.76 USDT<br>- Upbit (KRW-BTC): 129,717,000 KRW<br>- Upbit (KRW-USDT): 1,501 KRW/USDT<br><br><b>Spreads vs Binance:</b><br>- Upbit USDT vs Binance: +63.96 USDT (+0.074%)<br>- KRW-implied vs Binance: +9.59 USDT (+0.011%)<br>- KRW-implied vs Upbit USDT: -54.37 USDT (-0.0629%)<br><br><b>Arbitrage Assessment:</b><br>Binance \u2192 Upbit USDT offers ~64 USDT/BTC gross profit, but requires total costs under 0.074% to be profitable\u2014extremely tight margin. KRW-implied route yields near-zero after fees. Consider trading fees, network costs, Korean capital controls, and liquidity risks.<br><br><b>Trader Recommendation:</b><br>Avoid large transfers; margins too thin. Use pre-funded accounts for tiny test trades only. Set alerts for \u22650.3% spreads. Monitor continuously for wider gaps >0.2\u20130.3% before acting.[web:21]\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "b76f8c7a-68fb-41fa-9da9-af3c7fdbb700",
      "name": "Get price from Upbit",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -704,
        816
      ],
      "parameters": {
        "url": "https://api.upbit.com/v1/ticker",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "markets",
              "value": "USDT-BTC,KRW-BTC,KRW-USDT"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "3b782dfc-e251-48c0-9d7b-87acb00e4561",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -960,
        816
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "executeOnce": false,
      "notesInFlow": true,
      "typeVersion": 1.3
    }
  ],
  "connections": {
    "Analyzer": {
      "main": [
        [
          {
            "node": "Send a Message for Traders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Data": {
      "main": [
        [
          {
            "node": "Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get price from Binance",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get price from Upbit",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get price from Forex",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get price from Forex": {
      "main": [
        [
          {
            "node": "Edit Fields For Forex Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get price from Upbit": {
      "main": [
        [
          {
            "node": "Edit Fields For Upbit Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get price from Binance": {
      "main": [
        [
          {
            "node": "Edit Fields For Binance Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Analyzer",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields For Forex Data": {
      "main": [
        [
          {
            "node": "Merge Data",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Edit Fields For Upbit Data": {
      "main": [
        [
          {
            "node": "Merge Data",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Edit Fields For Binance Data": {
      "main": [
        [
          {
            "node": "Merge Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model for Format": {
      "ai_languageModel": [
        [
          {
            "node": "Structured Output Parser",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model for Analyzer": {
      "ai_languageModel": [
        [
          {
            "node": "Analyzer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}