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)

VB Script for Placing Orders From Excelsheet to Algomojo Platform

3 min read

This tutorial provides a sample VB Script code to place orders from the Algomojo Platform. Algomojo offers Free API + Free Trading Platform to algomojo users to automate their trading ideas.

One can use VBscript inside excelsheet to create Macros to automate their trading ideas.

Getting the Algomojo API Key

Before Applying the code log into your Algomojo Account -> Go My API section and get the api key and api secret key and replace the API key and API secret key as mentioned in the code below

apikey = "xxxxxxxxxxxxxxxxxxxxxxx"
apisecret = "xxxxxxxxxxxxxxxxxxxxxxx"

Sample VBScript Macro

Here is the sample VBScript Macro which is connected to the Excel sheet Place Order Button to send Automated Orders on the click of the Button.

Sub Algomojo()


Dim apikey As String
Dim apisecret As String
Dim Broker As String
Dim Version As String
Dim stgy As String
Dim ClientID As String
Dim Symbol As String
Dim Exchange As String
Dim Ttranstype As String
Dim prctyp As String
Dim qty As String
Dim Price As String
Dim TrigPrice As String
Dim Pcode As String
Dim response As String

apikey = "xxxxxxxxxxxxxxxxxxxxxxx"
apisecret = "xxxxxxxxxxxxxxxxxxxxxxx"
Version = "1.0"
stgy = "Excel"
Broker = Cells(5, "B").Value
ClientID = Cells(5, "C").Value
Exchange = Cells(5, "D").Value
Symbol = Cells(5, "E").Value
Ttranstype = Cells(5, "F").Value
prctyp = Cells(5, "G").Value
qty = Cells(5, "H").Value
Price = Cells(5, "I").Value
TrigPrice = Cells(5, "J").Value
Pcode = Cells(5, "K").Value

response = PlaceOrder(apikey, apisecret, Broker, Version, stgy, ClientID, Symbol, Exchange, Ttranstype, prctyp, qty, Price, TrigPrice, Pcode)
Cells(9, "C") = response
MsgBox ("Order Placed")

End Sub


Public Function PlaceOrder(user_apikey As String, api_secret As String, Broker As String, Version As String, stgy_name As String, ClntID As String, Tsym As String, exch As String, Ttranstype As String, prctyp As String, qty As String, Price As String, TrigPrice As String, Pcode As String) As String
    Dim InTD As String
    Dim sOutput As String
    Dim s_prdt_ali As String
    Dim Ret As String
    Dim discqty  As String
    Dim MktPro As String
    Dim AMO As String
    s_prdt_ali = "BO:BO||CNC:CNC||CO:CO||MIS:MIS||NRML:NRML"
    Ret = "DAY"
    discqty = "0"
    MktPro = "NA"
    If (TrigPrice = "") Then
        TrigPrice = "0"
    End If
    AMO = "NO"
    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 & """}"
    PlaceOrder = AMConnect(user_apikey, api_secret, Broker, Version, "PlaceOrder", InTD)
End Function


Private Function AMConnect(api_key As String, api_secret As String, Broker As String, Version As String, api_name As String, InTD As String) As String
    Dim objHTTP As Object
    Dim result As String
    Dim postdate As String
    Dim BrkPrefix As String
    Dim BaseURL As String
    BaseURL = "https://" & LCase(Broker) & "api.algomojo.com/" & Version & "/"
    postdata = "{""" & "api_key" & """:""" & api_key & """,""" _
                    & "api_secret" & """:""" & api_secret & """,""" _
                    & "data" & """:" & InTD & "}"
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    Url = BaseURL & api_name
    objHTTP.Open "POST", Url, False
    objHTTP.setRequestHeader "Content-type", "application/json"
    objHTTP.send (postdata)
    result = objHTTP.responseText
    Set objHTTP = Nothing
    AMConnect = result
    
End Function

Download the Excel Enabled Macro to send Automated Orders from Excel

Disabling Protected View in Excel

If the Excel Sheet is not working then consider trying disabling the protected view in Excel. You can choose to disable the Protected View feature within Excel so that you no longer receive the warning upon opening any Excel file that has been downloaded. In Excel go to File > Options > Trust Center > Trust Center Settings > Protected View, and then uncheck Enabled Protected View for files originating from the Internet.

For Creating more functionalities like Placing Bracket Orders, Placing Multiple Orders and more visit Algomojo API documentation

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)

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