{"id":95,"date":"2023-01-16T07:20:00","date_gmt":"2023-01-16T07:20:00","guid":{"rendered":"https:\/\/algomojo.com\/blog\/?p=95"},"modified":"2023-09-13T04:31:31","modified_gmt":"2023-09-13T04:31:31","slug":"how-to-send-orders-from-google-spreadsheets-using-algomojo-api","status":"publish","type":"post","link":"https:\/\/algomojo.com\/blog\/how-to-send-orders-from-google-spreadsheets-using-algomojo-api\/","title":{"rendered":"How to Send Orders from Google SpreadSheets using Algomojo API"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1280\" height=\"720\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/sheets.png\" alt=\"\" class=\"wp-image-96\"\/><\/figure>\n\n\n\n<p>You might think &#8220;Is it really possible to send automated orders from Google Sheets? Are you crazy?&#8221; but hey thanks to <strong>Google Appscript<\/strong> which is an alternative to VBscript to automate your tasks in your Google Excel Sheets.<\/p>\n\n\n\n<p><strong>What is Google AppScript<\/strong>?<\/p>\n\n\n\n<p>Apps Script lets you&nbsp;do more with Google Spreadsheets and with other Google Products, all on a&nbsp;<a href=\"https:\/\/developers.google.com\/apps-script\/guides\/v8-runtime\">modern JavaScript platform<\/a>&nbsp;in the cloud. Build&nbsp;solutions&nbsp;to boost your collaboration and productivity.<\/p>\n\n\n\n<p>You access the Appscript Editor from Extensions-&gt;AppScript Editor from your Google Spreadsheet.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1751\" height=\"386\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/01\/image-1.png\" alt=\"\" class=\"wp-image-488\"\/><\/figure>\n\n\n\n<p><strong>Creating Button Controls<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1748\" height=\"392\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2023\/01\/image-2.png\" alt=\"\" class=\"wp-image-489\"\/><\/figure>\n\n\n\n<p>Button Controls can be created by goto Insert&nbsp;<strong>Menu -&gt; Drawings<\/strong>&nbsp;and create a Button Control with \u201cPlaceOrder\u201d as text in the button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-9.png\"><img loading=\"lazy\" width=\"405\" height=\"681\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-9.png\" alt=\"\" class=\"wp-image-99\"\/><\/a><\/figure>\n\n\n\n<p><strong>Writing the Google Appscript<\/strong><\/p>\n\n\n\n<p>Open the Script Editor and Paste the below appscript code and save the code as&nbsp;<strong>Algomojo Buttons<\/strong>.<\/p>\n\n\n\n<p>Get the API Key and API Secret Key from Algomojo Platform and replace the apikey and apisecret key in the below code with yours.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\">function Algomojo() {\n\n\nvar apikey = &quot;af672a6019523acd27bc4d48ca12cb73&quot;;\nvar apisecret = &quot;8b5befaa9ff7e0269326170ac572b67c&quot;;\nvar Version = &quot;v1&quot;;\nvar broker =  SpreadsheetApp.getActiveSheet().getRange(&#039;B3&#039;).getValue();\nvar strategy = &quot;Google Sheet&quot;;\nvar exchange = SpreadsheetApp.getActiveSheet().getRange(&#039;C3&#039;).getValue();\nvar symbol = SpreadsheetApp.getActiveSheet().getRange(&#039;D3&#039;).getValue();\nvar action = SpreadsheetApp.getActiveSheet().getRange(&#039;E3&#039;).getValue();\nvar pricetype = SpreadsheetApp.getActiveSheet().getRange(&#039;F3&#039;).getValue();\nvar quantity = SpreadsheetApp.getActiveSheet().getRange(&#039;G3&#039;).getValue();\nvar price = SpreadsheetApp.getActiveSheet().getRange(&#039;H3&#039;).getValue();\nvar trigger_price = SpreadsheetApp.getActiveSheet().getRange(&#039;I3&#039;).getValue();\nvar product = SpreadsheetApp.getActiveSheet().getRange(&#039;J3&#039;).getValue();\nvar splitorder = SpreadsheetApp.getActiveSheet().getRange(&#039;K3&#039;).getValue();\nvar split_quantity = SpreadsheetApp.getActiveSheet().getRange(&#039;L3&#039;).getValue();\n\n\nvar response = PlaceOrder(apikey, apisecret, Version, broker, strategy, exchange, symbol, action, pricetype, quantity, price, trigger_price, product, splitorder,split_quantity);\nSpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;Sheet1&quot;).getRange(&#039;C9&#039;).setValue(response);\n}\n\n\nfunction PlaceOrder(apikey, apisecret, Version, broker, strategy, exchange, symbol, action, pricetype, quantity, price, trigger_price, product, splitorder,split_quantity){\n  \n    \n    var amo = &quot;NO&quot;;\n    var disclosed_quantity = &quot;0&quot;\n\n    var InTD = &quot;{\\&quot;&quot; \n            + &quot;broker&quot; + &quot;\\&quot;:\\&quot;&quot; + broker + &quot;\\&quot;,\\&quot;&quot;\n            + &quot;strategy&quot; + &quot;\\&quot;:\\&quot;&quot; + strategy + &quot;\\&quot;,\\&quot;&quot; + &quot;exchange&quot; + &quot;\\&quot;:\\&quot;&quot; + exchange + &quot;\\&quot;,\\&quot;&quot; \n            + &quot;symbol&quot; + &quot;\\&quot;:\\&quot;&quot; + symbol + &quot;\\&quot;,\\&quot;&quot; + &quot;action&quot; + &quot;\\&quot;:\\&quot;&quot; + action + &quot;\\&quot;,\\&quot;&quot;  \n            + &quot;product&quot; + &quot;\\&quot;:\\&quot;&quot; + product + &quot;\\&quot;,\\&quot;&quot; + &quot;pricetype&quot; + &quot;\\&quot;:\\&quot;&quot; + pricetype + &quot;\\&quot;,\\&quot;&quot; \n            + &quot;quantity&quot; + &quot;\\&quot;:\\&quot;&quot; + quantity + &quot;\\&quot;,\\&quot;&quot; + &quot;price&quot; + &quot;\\&quot;:\\&quot;&quot; + price + &quot;\\&quot;,\\&quot;&quot; \n            + &quot;disclosed_quantity&quot; + &quot;\\&quot;:\\&quot;&quot; + disclosed_quantity + &quot;\\&quot;,\\&quot;&quot; + &quot;trigger_price&quot; + &quot;\\&quot;:\\&quot;&quot; + trigger_price + &quot;\\&quot;,\\&quot;&quot; \n            + &quot;amo&quot; + &quot;\\&quot;:\\&quot;&quot; + amo + &quot;\\&quot;,\\&quot;&quot; + &quot;splitorder&quot; + &quot;\\&quot;:\\&quot;&quot; + splitorder + &quot;\\&quot;,\\&quot;&quot; \n            + &quot;split_quantity&quot; + &quot;\\&quot;:\\&quot;&quot; + split_quantity + &quot;\\&quot;}&quot;;\n   \n           \n    var result = AMConnect(apikey, apisecret, &quot;am&quot;, Version, &quot;PlaceOrder&quot;, InTD);\n    return result;\n}\n\n\nfunction AMConnect(api_key, api_secret, Broker, Version, api_name, InTD){\n    \n    var BaseURL = &quot;https:\/\/&quot; + Broker.toLowerCase() + &quot;api.algomojo.com\/&quot; + Version + &quot;\/&quot;;\n    var postdata = &quot;{\\&quot;&quot; + &quot;api_key&quot; + &quot;\\&quot;:\\&quot;&quot; + api_key + &quot;\\&quot;,\\&quot;&quot; \n                    + &quot;api_secret&quot; + &quot;\\&quot;:\\&quot;&quot; + api_secret + &quot;\\&quot;,\\&quot;&quot;\n                    + &quot;data&quot; + &quot;\\&quot;:&quot; + InTD + &quot;}&quot;;\n  \n\n \n    \n    var Url = BaseURL + api_name;\n  \n     \n  \n  var raw = postdata;\n  Logger.log(raw);\n  \n    var options = {\n      &#039;method&#039; : &#039;post&#039;,\n      &#039;contentType&#039;: &#039;application\/json&#039;,\n      \/\/ Convert the JavaScript object to a JSON string.\n      &#039;payload&#039; : raw\n    };\n    var result = UrlFetchApp.fetch(Url, options);\n    return result.getContentText();\n    \n}\n\n\n<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><strong>Assigning the Button Controls to Google Appscript Function<\/strong><\/p>\n\n\n\n<p>1)Now right-click over the button and click on the triple dots and select the&nbsp;<strong>Assign script<\/strong>&nbsp;option<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-10.png\"><img loading=\"lazy\" width=\"443\" height=\"297\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-10.png\" alt=\"\" class=\"wp-image-100\"\/><\/a><\/figure>\n\n\n\n<p>2)Enter the Function Name as&nbsp;<strong>Algomojo&nbsp;<\/strong>in the&nbsp;<strong>Assign Script<\/strong>&nbsp;Popup Dialog box<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"387\" height=\"243\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-11.png\" alt=\"\" class=\"wp-image-101\"\/><\/figure>\n\n\n\n<p>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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1828\" height=\"275\" src=\"https:\/\/algomojo.com\/blog\/wp-content\/uploads\/2020\/12\/image-12.png\" alt=\"\" class=\"wp-image-102\"\/><\/figure>\n\n\n\n<div class=\"wp-block-buttons\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link\" href=\"https:\/\/docs.google.com\/spreadsheets\/d\/1jh9ZsxWa2JvoY7fie4xM2UYZltckOwc3m0T3b7TQZeQ\/edit?usp=sharing\">Access the Algomojo Google Spreadsheet &#8211; Public View<\/a><\/div>\n<\/div>\n\n\n\n<p>For sending a different type of orders in your Google Appscript kindly check with the latest&nbsp;<a href=\"https:\/\/algomojo.com\/docs\/\">algomojo API documentation<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Happy Spreadsheet Trading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might think &#8220;Is it really possible to do send automated orders from Google Sheets? Are you crazy?&#8221; but hey thanks to Google Appscript which is an alternative to VBscript to automate your tasks in your Google Excel Sheets.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[38],"tags":[4,34,58,56,59,57,46],"_links":{"self":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/95"}],"collection":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":8,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/posts\/95\/revisions\/594"}],"wp:attachment":[{"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algomojo.com\/blog\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}