Rajandran R Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

VB Script for Placing Orders From Excelsheet to Algomojo Platform

2 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 Founder of Marketcalls and Co-Founder Algomojo. Full-Time Derivative Trader. Expert in Designing Trading Systems (Amibroker, Ninjatrader, Metatrader, Python, Pinescript). Trading the markets since 2006. Mentoring Traders on Trading System Designing, Market Profile, Orderflow and Trade Automation.

AllinOneAlerts – Amibroker Alerts Module for Algomojo Users

AllinOneAlerts is one of the most important and most requested modules is to bring all sorts of alerts with few lines of coding efforts....
Rajandran R
58 sec read

Algomojo Platform Now Open to Angel Broking Users

We are proud to provide our Algomojo access to Angel Broking users. Now users of Angel Broking can enjoy Free API-based algotrading access. Free...
Rajandran R
4 min read

Algomojo Trading Platform Fee Reduced for Existing Brokers Clients

Algomojo strives to bring low-cost Algo trading services with a better user experience. We are always looking for new ways to improve our services and...
Rajandran R
50 sec read

Leave a Reply

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