Documentation
HomeGithubDiscordBlog
  • What is OpenAlgo?
  • OpenAlgo Architecture
  • Mini FOSS Universe
  • Community Support
  • OpenAlgo GPT
  • New Features
    • Fast Scalper
    • API Analyzer
    • Traffic/Latency Monitor
    • Chartink Integration
  • Monetization
  • Connect Brokers
    • Brokers
      • 5Paisa
      • 5paisa (XTS)
      • AliceBlue
      • AngelOne
      • Compositedge
      • Dhan
      • Dhan(Sandbox)
      • Firstock
      • FlatTrade
      • Fyers
      • Groww
      • IIFL (XTS)
      • Jainam Retail (XTS)
      • Jainam Dealer (XTS)
      • Kotak Securities
      • Paytm
      • Pocketful
      • Shoonya
      • Tradejini
      • Upstox
      • Wisdom Capital
      • Zebu
      • Zerodha
  • Installation Guidelines
  • Getting Started
    • Windows Installation
      • Pre-Requesites
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • SSL Verification Failed
      • Accessing OpenAlgo
    • Windows Server Installation
    • Mac OS Installation
      • Pre-Requesties
      • Setup
      • Install Dependencies
      • Ngrok Config
      • Environmental Variables
      • Start OpenAlgo
      • Install certifi
      • Accessing OpenAlgo
    • Amazon Elastic Beanstalk
    • Ubuntu Server Installation
    • Docker Development
    • Testing OpenAlgo in Cloud
    • Upgrade
  • Latency
  • API Documentation
    • V1
      • Accounts API
        • Funds
        • Orderbook
        • Tradebook
        • PositionBook
        • Holdings
      • Orders API
        • Placeorder
        • PlaceSmartOrder
        • BasketOrder
        • SplitOrder
        • ModifyOrder
        • CancelOrder
        • CancelAllOrder
        • ClosePosition
        • OrderStatus
        • OpenPosition
      • Data API
        • Quotes
        • Depth
        • History
        • Intervals
        • Symbol
        • Ticker
      • Order Constants
      • HTTP Status Codes
      • Rate Limiting
      • API Collections
  • Symbol Format
  • MCP
  • Trading Platform
    • Amibroker
      • AmiQuotes
      • Button Trading Module
      • Button Trading with Split Orders
      • Button Trading with Stoploss
      • SmartOrder Chart Module
      • Trailing Stoploss Execution Module
      • Line Trading Module
      • Equity Exploration Module
      • CSV Exploration Module
      • Options Button Trading Module
      • Spot/Futures to Options Module (Single Leg)
      • Spot/Futures to Options Module (Two Leg)
      • Time Based Execution
    • Tradingview
    • ChartInk
    • Python
      • Strategy Management
      • EMA Crossover Strategy
      • Supertrend Strategy
      • Supertrend Strategy with yfinance data
      • Voice Based Orders
    • NodeJS
    • Metatrader 5
      • Download & Install Library
      • OpenAlgo MQL5 Functions
      • Include the Header File
      • Sample Expert Advisor
    • Excel
    • Google Spreadsheets
    • N8N
    • Chrome Extension
  • Strategy Management
  • Developers
    • Design Documentation
      • Architecture
      • API Layer
      • Broker Integerations
      • Database Layer
      • Authentication Platforms
      • Configuration
      • Utilities
      • Broker Integration Checklist
  • Change Log
    • Version 1.0.0.24 Launched
    • Version 1.0.0.23 Launched
    • Version 1.0.0.22 Launched
    • Version 1.0.0.21 Launched
    • Version 1.0.0.20 Launched
    • Version 1.0.0.19 Launched
    • Version 1.0.0.18 Launched
    • Version 1.0.0.17 Launched
    • Version 1.0.0.16 Launched
    • Version 1.0.0.15 Launched
    • Version 1.0.0.14 Launched
    • Version 1.0.0.13 Launched
    • Version 1.0.0.12 Launched
    • Version 1.0.0.11 Launched
    • Version 1.0.0.10 Launched
    • Version 1.0.0.9 Launched
    • Version 1.0.0.8 Launched
    • Version 1.0.0.7 Launched
    • Version 1.0.0.6 Launched
    • Version 1.0.0.5 Launched
    • Version 1.0.0.4 Launched
    • Version 1.0.0.3 Launched
    • Version 1.0.0.2 Launched
    • Version 1.0.0.1 Launched
    • Version 1.0.0.0 Launched
Powered by GitBook
On this page
  • Integrating with n8n for Scheduled Order Placement
  • 1. Install Node.js
  • 2. Install n8n
  • 3. Start n8n
  1. Trading Platform

N8N

PreviousGoogle SpreadsheetsNextChrome Extension

Last updated 2 months ago

n8n is a workflow automation tool that allows users to create automated workflows connecting different apps, APIs, and services without needing extensive coding knowledge. It is an open-source, self-hostable alternative to Zapier, Make, and other automation tools.

With n8n, traders can create workflows that:

  • Fetch data from APIs

  • Process and transform data

  • Automate trading tasks

  • Integrate with trading platforms, brokers, databases, and messaging services

Integrating with n8n for Scheduled Order Placement

This section guides you through creating a workflow in n8n, a powerful open-source workflow automation tool, to automatically place orders in OpenAlgo at a scheduled time. We'll use the example of placing a short straddle on NIFTY options at 9:20 AM IST every day.

Prerequisites:

  • OpenAlgo: You must have OpenAlgo installed and running in http://127.0.0.1:5000/. Ensure your broker is properly configured within OpenAlgo.

  • Install NodeJS as n8n backend relies on Node.js runtime to execute workflows, handle API calls, and manage automation.

  • n8n: n8n should be installed and running.

  • Broker API Key: You'll need your broker's API key and API Secret that you have configured in OpenAlgo.

How to Start n8n on Windows

To start n8n on Windows, follow these steps:


1. Install Node.js

Since n8n runs on Node.js, you need to install it first.

  1. Install the LTS (Long-Term Support) version (recommended for stability).

  2. Verify installation by opening Command Prompt (CMD) and running:

    node -v
    npm -v

    If installed correctly, you will see the version numbers.


2. Install n8n

After Node.js is installed, you can install n8n using npm:

  1. Open Command Prompt (CMD) as Administrator.

  2. Run the following command:

    npm install -g n8n

    This will install n8n globally on your system.

  3. Check if n8n is installed:

    n8n -v

    If installed correctly, you will see the version number.


3. Start n8n

Once installed, start n8n with:

n8n

This will start the n8n server. You should see logs like:

Access n8n in Browser

Open your browser and go to: 👉 http://localhost:5678/

Now you can start creating workflows.

Workflow Setup:

1. Create a New Workflow in n8n

  • Open your n8n instance in your browser (typically http://localhost:5678).

  • Click the "+" button or "Create Workflow" option to start a new, blank workflow.

2. Add and Configure the Schedule Trigger

  • This node will be the starting point of our workflow, initiating the order placement at the specified time.

  • Click the "+" button to add the first node.

  • Search for "Schedule Trigger" and select it.

  • Select the "Custom(Cron)" as trigger interval from the options.

  • In the Expression field, enter the following Cron expression: 0 20 9 * * *

  • Explanation of the Cron Expression:

    • 0: Seconds (set to 0)

    • 20: Minute (set to 20 for 9:20 AM)

    • 9: Hour (set to 9 for 9:00 AM in 24-hour format)

    • *: Day of the Month (any day)

    • *: Month (any month)

    • *: Day of the Week (any day of the week)

  • Important: Timezone: By default, n8n uses UTC time. To ensure the trigger fires at 9:20 AM Indian Standard Time (IST), you must set the timezone.

    • Click on Settings

    • Click on n8n settings

    • Under general settings.

    • Select Timezone : "Asia/Kolkata"

3. Add the First HTTP Request Node (SELL NIFTY Call Option)

  • Click the "+" button to the right of the "Schedule Trigger" node to add a new node.

  • Search for "HTTP Request" and select it.

  • Configure the node as follows:

    • Method: POST

    • URL: http://127.0.0.1:5000/api/v1/placeorder (This assumes OpenAlgo is running on your local machine. Adjust if you're using a different URL.)

    • Authentication: None (assuming your OpenAlgo instance doesn't require authentication for local requests. If you have authentication enabled, configure it accordingly.)

    • Send Body: Check this box.

    • Body Content Type: JSON

    • Specify Body: Choose Using JSON

    • JSON: Paste the following, replacing "YOUR_OPENALGO_API_KEY" with your actual API key:

{
    "apikey": "YOUR_OPENALGO_API_KEY",
    "strategy": "Test Strategy",
    "symbol": "NIFTY06MAR2522100CE",
    "exchange": "NFO",
    "action": "SELL",
    "pricetype": "MARKET",
    "product": "MIS",
    "quantity": "75"
}
  • Important Notes:

    • YOUR_OPENALGO_API_KEY: Replace this with your OpenAlgo API key.

    • strategy: You can name your strategy anything you like (e.g., "MyStraddleStrategy"). This helps you identify the source of the order within OpenAlgo.

    • symbol: Ensure this is the correct symbol for the NIFTY call option with the desired expiry and strike price. Double-check this!

    • exchange: Use "NFO" for NSE options.

    • action: "SELL" for the short straddle.

    • pricetype: "MARKET" for a market order.

    • product: "MIS" for intraday trading.

    • quantity: Set to "50" (or your desired quantity, likely a multiple of the lot size).

4. Add the Second HTTP Request Node (SELL NIFTY Put Option)

  • Click the "+" button again to add another HTTP Request node. We need a separate request for the put option. Connect the same cron node created to the second HTTP request also.

{
    "apikey": "YOUR_OPENALGO_API_KEY",
    "strategy": "Test Strategy",
    "symbol": "NIFTY06MAR2522100PE",
    "exchange": "NFO",
    "action": "SELL",
    "pricetype": "MARKET",
    "product": "MIS",
    "quantity": "75"
}

5. Save and Activate

  • Click "Save" in the top right corner to save your workflow.

  • Click the "Active" toggle switch in the top-right corner. It should turn green, indicating that the workflow is now active.

6. Test (Optional, but Highly Recommended!)

  • Important: Before testing with the schedule, use the "Test workflow" button (on schedule trigger node). This will execute the workflow immediately, bypassing the schedule. Use this only in analyzer mode! It's crucial to verify that your API calls and order parameters are correct before letting it run automatically.

7. Monitor Execution

  • Once the workflow is active, it will run automatically at 9:20 AM IST every day.

  • You can monitor the executions by clicking on the "Executions" tab in n8n. This will show you a history of when the workflow ran and whether it was successful.

  • You should also see the orders appearing in your OpenAlgo order book.

Troubleshooting

  • Workflow not triggering:

    • Is it active? Double-check that the "Active" toggle is switched on.

    • Cron expression: Verify that your Cron expression is correct. You can use online Cron expression generators to test your expression.

    • Timezone: Make absolutely sure the timezone in n8n's settings is set to "Asia/Kolkata" (or your correct local timezone).

    • n8n errors: Check the n8n logs (accessible through the settings or the command line if you're running it locally) for any error messages.

  • Orders not placing in OpenAlgo:

    • API Key: Double-check your API key in the HTTP Request nodes.

    • URL: Make sure the URL is the correct OpenAlgo endpoint.

    • JSON Format: Ensure your JSON body is correctly formatted. Any missing commas, brackets, or incorrect field names will cause errors.

    • OpenAlgo Logs: Check the OpenAlgo logs for any error messages.

Why Use n8n for OpenAlgo?

  • No-code / Low-code Automation: Simplifies complex trading workflows.

  • Open-source & Self-hosted: No expensive SaaS fees.

  • Customizable & Scalable: Adapt workflows based on trading needs.

  • Supports Webhooks & APIs: Seamless integration with OpenAlgo.

Basic Understanding of Cron Expressions: are used to define schedules. We'll provide the specific expression you need, but it's helpful to have a basic understanding.

Download Node.js from

Cron expressions
Node.js official website