Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

How to Send Orders from Google SpreadSheets using Algomojo API

2 min read

You might think “Is it really possible to send automated orders from Google Sheets? Are you crazy?” but hey thanks to Google Appscript which is an alternative to VBscript to automate your tasks in your Google Excel Sheets.

What is Google AppScript?

Apps Script lets you do more with Google Spreadsheets and with other Google Products, all on a modern JavaScript platform in the cloud. Build solutions to boost your collaboration and productivity.

Access the Appscript Editor from Extension->AppScript Editor from your Google Spreadsheet.

Creating Button Controls

The Next Step is to Create the Datasheet that you want to transmit and PlaceOrder button to send and transmit those orders to the Algomojo Platform as shown below.

Button Controls can be created by goto Insert Menu -> Drawings and create a Button Control with “PlaceOrder” as text in the button.

Writing the Google Appscript

Open the Script Editor and Paste the below appscript code and save the code as Algomojo Buttons.

Get the API Key and API Secret Key from Algomojo Platform and replace the apikey and apisecret key in the below code with yours.

function Algomojo() {


var apikey = "af672a6019523acd27bc4d48ca12cb73";
var apisecret = "8b5befaa9ff7e0269326170ac572b67c";
var Version = "v1";
var broker =  SpreadsheetApp.getActiveSheet().getRange('B3').getValue();
var strategy = "Google Sheet";
var exchange = SpreadsheetApp.getActiveSheet().getRange('C3').getValue();
var symbol = SpreadsheetApp.getActiveSheet().getRange('D3').getValue();
var action = SpreadsheetApp.getActiveSheet().getRange('E3').getValue();
var pricetype = SpreadsheetApp.getActiveSheet().getRange('F3').getValue();
var quantity = SpreadsheetApp.getActiveSheet().getRange('G3').getValue();
var price = SpreadsheetApp.getActiveSheet().getRange('H3').getValue();
var trigger_price = SpreadsheetApp.getActiveSheet().getRange('I3').getValue();
var product = SpreadsheetApp.getActiveSheet().getRange('J3').getValue();
var splitorder = SpreadsheetApp.getActiveSheet().getRange('K3').getValue();
var split_quantity = SpreadsheetApp.getActiveSheet().getRange('L3').getValue();


var response = PlaceOrder(apikey, apisecret, Version, broker, strategy, exchange, symbol, action, pricetype, quantity, price, trigger_price, product, splitorder,split_quantity);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange('C9').setValue(response);
}


function PlaceOrder(apikey, apisecret, Version, broker, strategy, exchange, symbol, action, pricetype, quantity, price, trigger_price, product, splitorder,split_quantity){
  
    
    var amo = "NO";
    var disclosed_quantity = "0"

    var InTD = "{\"" 
            + "broker" + "\":\"" + broker + "\",\""
            + "strategy" + "\":\"" + strategy + "\",\"" + "exchange" + "\":\"" + exchange + "\",\"" 
            + "symbol" + "\":\"" + symbol + "\",\"" + "action" + "\":\"" + action + "\",\""  
            + "product" + "\":\"" + product + "\",\"" + "pricetype" + "\":\"" + pricetype + "\",\"" 
            + "quantity" + "\":\"" + quantity + "\",\"" + "price" + "\":\"" + price + "\",\"" 
            + "disclosed_quantity" + "\":\"" + disclosed_quantity + "\",\"" + "trigger_price" + "\":\"" + trigger_price + "\",\"" 
            + "amo" + "\":\"" + amo + "\",\"" + "splitorder" + "\":\"" + splitorder + "\",\"" 
            + "split_quantity" + "\":\"" + split_quantity + "\"}";
   
           
    var result = AMConnect(apikey, apisecret, "am", Version, "PlaceOrder", InTD);
    return result;
}


function AMConnect(api_key, api_secret, Broker, Version, api_name, InTD){
    
    var BaseURL = "https://" + Broker.toLowerCase() + "api.algomojo.com/" + Version + "/";
    var postdata = "{\"" + "api_key" + "\":\"" + api_key + "\",\"" 
                    + "api_secret" + "\":\"" + api_secret + "\",\""
                    + "data" + "\":" + InTD + "}";
  

 
    
    var Url = BaseURL + api_name;
  
     
  
  var raw = postdata;
  Logger.log(raw);
  
    var options = {
      'method' : 'post',
      'contentType': 'application/json',
      // Convert the JavaScript object to a JSON string.
      'payload' : raw
    };
    var result = UrlFetchApp.fetch(Url, options);
    return result.getContentText();
    
}


Run the code.gs with code execution set to Algomojo() function. There should not be any errors and you should be able to see the executions happening in your trading terminal.

Assigning the Button Controls to Google Appscript Function

1)Now right-click over the button and click on the triple dots and select the Assign script option

2)Enter the Function Name as Algomojo in the Assign Script Popup Dialog box

Now come back to Google Spreadsheets and click on the Place Order button and check the orders got executed in the Algomojo Order Log section in realtime.

For sending a different type of orders in your Google Appscript kindly check with the latest algomojo API documentation

The possibilities of creating an Automated Trading task are endless creativity. Play around with Google Appscript and if in case you are able to build something interesting with google appscript let us know here in the comment section.

Happy Spreadsheet Trading!

Rajandran R Creator of OpenAlgo - OpenSource Algo Trading framework for Indian Traders. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Strongly believe that market understanding and robust trading frameworks are the key to the trading success. Building Algo Platforms, Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in

Algomojo Platform Now Open to Finvasia (Shoonya) Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to Finvasia (Shoonya) users. This partnership aims...
Rajandran R
5 min read

Algomojo Platform Now Open to 5Paisa Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to 5Paisa users. This partnership aims to...
Rajandran R
5 min read

Algomojo Platform Now Open to Goodwill Commodities Users

Algomojo, a leading Algotrading platform for DIY traders, is excited to announce that it is now open to Goodwill Commodities users. This partnership aims...
Rajandran R
5 min read

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More