VB Script for Placing Orders From Excelsheet to Algomojo Platform

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

8 thoughts on “VB Script for Placing Orders From Excelsheet to Algomojo Platform”

  1. for firstock its returning error: {“stat”:”Not_Ok”,”emsg”:”Invalid Input : uid or exch or qty or prc or trantype or prctyp or ret or actid or prd or tsym is Missing.”}

  2. I have tradejini code of excel the addins but still I cannot placeorder I get error invalid input The get limit works only with the api with both python and excel but place order does not work with both excel aswwell as python I have been rasing requests since last 1- 2 months with algomojo also opened account with tradejini through algomojoThey sent me the link for the vbscript but it is giving this error Missing input usid or tsyn or price I have entered evey value correctly Please ley me know what am I missing

  3. Is it possible to modify the option price in tradejini vba excel module and if possible how to do it I tried the Modifyorder in the documentation for tradejini but that does not work It is possible that is not for options order and the 2nd problem is thestop loss code for options does not work

  4. In the stop loss error I get error trigger price missing while I have already entered the
    trigger price value
    Please help me on these 2 issues apart from this everything else is clear about your platform

Leave a Comment

Your email address will not be published. Required fields are marked *