PiBridge For Excel

Excel Version of PiBridge.
Excel users can download sample Excel Spreadsheet from here
The Excel spreadsheet is open and the user can modify the code as required.
This will be most efficient, comprehensive and clean VBA code ever made to Place orders using PiBridge in Excel.
It does all kind of validation before passing order to PiBridge, like
*Checking for valid exch name,
*Quantity, Prices for Non Zero values etc.

User can directly call the function in excel cell.

Example:
=PlaceOrder( "NSE" , "AXISBANK-EQ" , "BUY" , "MKT" , 10, 0 , 0 , "MIS" , "AB1234" )

Here is the VBA Code.
Public Function PlaceOrder(ByVal Exch As String, ByVal TrdSym As String, ByVal Trans As String, _
ByVal OrdType As String, ByVal Qty As Long, ByVal LmtPrice As Double, ByVal TrgPrice As Double, _
ByVal ProdType As String, ByVal ClientId As String, Optional ByVal Validity As String = “DAY”, _
Optional ByVal StgyName As String = “EXCEL”, Optional ByVal Symbol As String = “”, Optional DiscQty As Long = 0)

'‘Created By HowUTrade
’‘https://howutrade.in
’'[email protected]

On Error GoTo ErrHandler:
Exch = UCase(Exch)
TrdSym = UCase(TrdSym)
Trans = UCase(Trans)
OrdType = UCase(OrdType)
ProdType = UCase(ProdType)
ClientId = UCase(ClientId)
Validity = UCase(Validity)
Symbol = UCase(Symbol)

If Len(Exch) < 3 Or InStr(ExchList, Exch) = 0 Then
    PlaceOrder = "InvalidExch"
    Exit Function
End If

If Len(TrdSym) < 3 Or TrdSym = vbNullString Then
    PlaceOrder = "NullTrdSym"
    Exit Function
End If

If Len(Trans) < 3 Or InStr(TransList, Trans) = 0 Then
    PlaceOrder = "InvalidTrans"
    Exit Function
End If

If Len(OrdType) < 1 Or InStr(OrdTypeList, OrdType) = 0 Then
    PlaceOrder = "InvalidOrdType"
    Exit Function
End If

If Len(ProdType) < 3 Or InStr(ProdTypeList, ProdType) = 0 Then
    PlaceOrder = "InvalidProdType"
    Exit Function
End If

If Len(Validity) < 3 Or InStr(ValidityList, Validity) = 0 Then
    PlaceOrder = "InvalidValidity"
    Exit Function
End If

If Len(ClientId) < 6 Or ClientId = vbNullString Then
    PlaceOrder = "NullClientId"
    Exit Function
End If

If Len(StgyName) < 3 Then
    PlaceOrder = "NullStgyName"
    Exit Function
End If

If Qty <= 0 Then
    PlaceOrder = "QtyZero"
    Exit Function
End If

If DiscQty < 0 Then
    PlaceOrder = "DiscQtyNegative"
    Exit Function
End If

If OrdType = "MKT" Then
    LmtPrice = 0
    TrgPrice = 0
ElseIf OrdType = "L" Then
    If LmtPrice <= 0 Then
        PlaceOrder = "LmtPriceZero"
        Exit Function
    End If
    TrgPrice = 0
ElseIf OrdType = "SL" Then
    If TrgPrice <= 0 Then
        PlaceOrder = "TrgPriceZero"
        Exit Function
    End If
    If LmtPrice <= 0 Then
        PlaceOrder = "LmtPriceZero"
        Exit Function
    End If
ElseIf OrdType = "SL-M" Then
    If TrgPrice <= 0 Then
        PlaceOrder = "TrgPriceZero"
        Exit Function
    End If
    LmtPrice = 0
Else
    PlaceOrder = "InvalidOrdType"
    Exit Function
End If

If PiBridge Is Nothing Then
    Set PiBridge = CreateObject("pibridge.Bridge")
End If

Dim OrdSide As Integer
If Trans = "BUY" Then
    OrdSide = 1
Else
    OrdSide = 2
End If

If Len(Symbol) < 3 Or Symbol = vbNullString Then
    Symbol = Left(TrdSym, 10)
End If

Call PiBridge.PlaceOrder(Exch, TrdSym, Symbol, StgyName, OrdSide, Qty, DiscQty, LmtPrice, TrgPrice, OrdType, ProdType, ClientId, Validity)

PlaceOrder = 1
Exit Function

ErrHandler:
If Err.Description = “Object reference not set to an instance of an object.” Then
PlaceOrder = 1
Else
PlaceOrder = Err.Description
End If
End Function

4 Likes

The files are not available? any further information?

i ma unablke to download the zip pls help

@sateeshm

It’s shared here