Rajandran R Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and 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. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

How to Send Orders from Google SpreadSheets using Algomojo API

2 min read

You might think “Is it really possible to do 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.

You you access the Appscript Editor from Tools->Script 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 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 = "86cbef19e7e61ccee91e497690d5814e";
var apisecret = "8dbb8a1c91649810c82ccfc0ea9d715a";
var Version = "1.0";
var stgy = "Excel";
var Broker =  SpreadsheetApp.getActiveSheet().getRange('B3').getValue();
var ClientID = SpreadsheetApp.getActiveSheet().getRange('C3').getValue();
var Exchange = SpreadsheetApp.getActiveSheet().getRange('D3').getValue();
var Symbol = SpreadsheetApp.getActiveSheet().getRange('E3').getValue();
var Ttranstype = SpreadsheetApp.getActiveSheet().getRange('F3').getValue();
var prctyp = SpreadsheetApp.getActiveSheet().getRange('G3').getValue();
var qty = SpreadsheetApp.getActiveSheet().getRange('H3').getValue();
var Price = SpreadsheetApp.getActiveSheet().getRange('I3').getValue();
var TrigPrice = SpreadsheetApp.getActiveSheet().getRange('J3').getValue();
var Pcode = SpreadsheetApp.getActiveSheet().getRange('K3').getValue();


var response = PlaceOrder(apikey, apisecret, Broker, Version, stgy, ClientID, Symbol, Exchange, Ttranstype, prctyp, qty, Price, TrigPrice, Pcode);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1").getRange('C9').setValue(response);
}


function PlaceOrder(user_apikey, api_secret, Broker, Version, stgy_name, ClntID, Tsym, exch, Ttranstype, prctyp, qty, Price, TrigPrice, Pcode){
  
    var s_prdt_ali = "BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML";
    var Ret = "DAY";
    var discqty = "0";
    var MktPro = "NA";
    if(TrigPrice == ""){
        TrigPrice = "0";
    }
    var AMO = "NO";

    var InTD = "{\"" 
            + "strg_name" + "\":\"" + stgy_name + "\",\""
            + "s_prdt_ali" + "\":\"" + s_prdt_ali + "\",\"" + "Tsym" + "\":\"" + Tsym + "\",\"" 
            + "exch" + "\":\"" + exch + "\",\"" + "Ttranstype" + "\":\"" + Ttranstype + "\",\"" 
            +"Ret" + "\":\"" + Ret + "\",\"" + "prctyp" + "\":\"" + prctyp + "\",\"" 
            +"qty" + "\":\"" + qty + "\",\"" + "discqty" + "\":\"" + discqty + "\",\"" 
            + "MktPro" + "\":\"" + MktPro + "\",\"" + "Price" + "\":\"" + Price + "\",\"" 
            + "TrigPrice" + "\":\"" + TrigPrice + "\",\"" + "Pcode" + "\":\"" + Pcode + "\",\"" 
            + "AMO" + "\":\"" + AMO + "\"}";
   
           
    var result = AMConnect(user_apikey, api_secret, Broker, 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.

Assinging 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 a Automated Trading task is endless creativity. Playaround 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 Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, USDINR and 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. Writing about Markets, Trading System Design, Market Sentiment, Trading Softwares & Trading Nuances since 2007 onwards. Author of Marketcalls.in and Co-Creator of Algomojo (Algorithmic Trading Platform for DIY Traders)

Mini Certification Course on Algorithmic Trading Strategies

If you are new to Automated trading? This certification course will help you to kickstart your automated trading with your broker and get to...
Rajandran R
1 min read

AllinOneAlerts – Amibroker Alerts Module for Amibroker Users

AllinOneAlerts is one of the most important and most requested modules to bring all sorts of alerts with no extra coding efforts. Now even...
Rajandran R
5 min read

Intraday Straddle Execution Module – Amibroker for AngelOne Users

This tutorial focus on how to automate your time-based index straddle/strangle management with intraday stop-loss levels with time-based entry and exits using Algomojo Platform...
Rajandran R
11 min read

Leave a Reply

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