{
  "name": "Automated stock trading with AI: integrating Alpaca and Google Sheets",
  "nodes": [
    {
      "id": "1311dd64-4b51-4e2e-ab20-9621e3b41e03",
      "name": "Alpaca-get-account-info",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -140,
        680
      ]
    },
    {
      "id": "1aa8a8aa-b765-4674-9177-15167da914be",
      "name": "Alpaca-post-order-sell",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1620,
        580
      ]
    },
    {
      "id": "0d966c99-bf41-4cc6-82de-217e25a7fcf2",
      "name": "Alpaca-post-order-buy",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1620,
        780
      ]
    },
    {
      "id": "60ba11a2-065f-453a-b310-4cc65f3b726d",
      "name": "filter_top_sentiment_score",
      "type": "n8n-nodes-base.code",
      "position": [
        520,
        680
      ]
    },
    {
      "id": "6f876b15-aeb6-4def-96f1-3ec20b8e4919",
      "name": "read_sentiments_score_today",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        300,
        680
      ]
    },
    {
      "id": "c4ce7556-5966-493e-8017-0377c2bcd2be",
      "name": "write_account_balace_today",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        80,
        680
      ]
    },
    {
      "id": "657726f0-38f0-4863-b911-1050cf345d84",
      "name": "Alpaca_get_open_positions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        740,
        680
      ]
    },
    {
      "id": "7d04afeb-3b24-4c96-9cf9-16999a14fec4",
      "name": "create_positions_to_close_and_positions_two_open",
      "type": "n8n-nodes-base.code",
      "position": [
        960,
        680
      ]
    },
    {
      "id": "1e846978-377d-477f-9e62-5ae465066315",
      "name": "positions_to_open",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1180,
        780
      ]
    },
    {
      "id": "a8bbdca1-d531-4384-bde9-8c1bf0979677",
      "name": "positions_to_close",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1400,
        580
      ]
    },
    {
      "id": "a6175bb8-d92e-4c36-9f70-9411567f80c8",
      "name": "merge_orders_to_write_to_sheets",
      "type": "n8n-nodes-base.merge",
      "position": [
        1840,
        680
      ]
    },
    {
      "id": "d74f036b-e085-43d4-a47d-82820e68bbed",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -920,
        380
      ],
      "parameters": {
        "width": 400,
        "height": 380,
        "content": "## Alpaca Trading 📈\nthis workflow takes the sentiment analysis made by our sentiment analysis bot workflow ([template link](https://n8n.io/workflows/5369-automated-stock-sentiment-analysis-with-google"
      }
    },
    {
      "id": "61a3c87f-00f1-4dad-94c1-bd9ef1a9c906",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2060,
        680
      ]
    },
    {
      "id": "22e12a7a-0a3d-46d7-a103-648e9628f3c4",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        1400,
        780
      ]
    },
    {
      "id": "ea31c298-b298-4e59-8057-a582a9fed462",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -360,
        680
      ]
    },
    {
      "id": "2b54791d-fec9-47f4-bf86-4e967884c5c0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        380
      ],
      "parameters": {
        "width": 620,
        "height": 560,
        "content": "## 1. Daily Trigger and Account Snapshot 📈\n**Schedule Trigger:** The workflow is automatically triggered every day at 4:45 PM (Asia/Jerusalem time). The time is set so it will run after the stock mark"
      }
    },
    {
      "id": "a2bc2441-e498-4de4-9d5e-b4af8fa1d5d4",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        260,
        380
      ],
      "parameters": {
        "width": 620,
        "height": 560,
        "content": "## 2. Sentiment-Based Stock Selection 👍👎\n**read_sentiments_score_today:** The workflow reads the sentiment scores from a google sheet the scores were generated by a \"Sentiment Analysis Bot\"([template "
      }
    },
    {
      "id": "e80a7608-0850-4da6-af19-a2d271a6960c",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        100
      ],
      "parameters": {
        "width": 840,
        "height": 840,
        "content": "## 3. Trading Logic and Execution ⚙️\n**create_positions_to_close_and_positions_two_open:** This is the core logic of your trading strategy. The code compares the stocks you currently hold with the top"
      }
    },
    {
      "id": "d824c44b-d4c3-4334-b563-f0390541c2e8",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1800,
        420
      ],
      "parameters": {
        "width": 520,
        "height": 520,
        "content": "## 4. Logging and Record-Keeping 📝\n**merge_orders_to_write_to_sheets:** This node gathers the results from both the buy and sell orders.\n\n**Google Sheets (Append):** Finally, the details of every trad"
      }
    }
  ],
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Alpaca-post-order-buy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Alpaca-get-account-info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "positions_to_open": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "positions_to_close": {
      "main": [
        [
          {
            "node": "Alpaca-post-order-sell",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alpaca-post-order-buy": {
      "main": [
        [
          {
            "node": "merge_orders_to_write_to_sheets",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Alpaca-post-order-sell": {
      "main": [
        [
          {
            "node": "merge_orders_to_write_to_sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alpaca-get-account-info": {
      "main": [
        [
          {
            "node": "write_account_balace_today",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alpaca_get_open_positions": {
      "main": [
        [
          {
            "node": "create_positions_to_close_and_positions_two_open",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "filter_top_sentiment_score": {
      "main": [
        [
          {
            "node": "Alpaca_get_open_positions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "write_account_balace_today": {
      "main": [
        [
          {
            "node": "read_sentiments_score_today",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "read_sentiments_score_today": {
      "main": [
        [
          {
            "node": "filter_top_sentiment_score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "merge_orders_to_write_to_sheets": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "create_positions_to_close_and_positions_two_open": {
      "main": [
        [
          {
            "node": "positions_to_close",
            "type": "main",
            "index": 0
          },
          {
            "node": "positions_to_open",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}