{
  "nodes": [
    {
      "parameters": {
        "cronExpression": "*/1 * * * *"
      },
      "id": "Schedule Trigger",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "symbol",
              "value": "AAPL"
            },
            {
              "name": "userId",
              "value": "test-user"
            }
          ],
          "number": [
            {
              "name": "thresholdAmount",
              "value": 150
            },
            {
              "name": "quantity",
              "value": 1
            },
            {
              "name": "price",
              "value": 140
            }
          ]
        },
        "options": {}
      },
      "id": "Set",
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Buy logic\nconst price = $json[\"price\"];\nconst threshold = $json[\"thresholdAmount\"];\nconst shouldBuy = price < threshold;\nreturn [{\n  json: {\n    shouldBuy,\n    symbol: $json[\"symbol\"],\n    thresholdAmount: $json[\"thresholdAmount\"],\n    quantity: $json[\"quantity\"],\n    userId: $json[\"userId\"]\n  }\n}];"
      },
      "id": "Function",
      "name": "Buy Logic",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$json[\"shouldBuy\"]}}",
              "value2": true
            }
          ]
        }
      },
      "id": "IF",
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://localhost:5000/api/trades/buy",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"userId\": \"{{$json[\"userId\"]}}\",\n  \"symbol\": \"{{$json[\"symbol\"]}}\",\n  \"thresholdAmount\": {{$json[\"thresholdAmount\"]}},\n  \"quantity\": {{$json[\"quantity\"]}}\n}"
      },
      "id": "HTTP Request",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ]
    }
  ],
  "connections": {
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Buy Logic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Buy Logic": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  }
}