Professional Documents
Culture Documents
Pre-Requisites:
Latest Pi installed
AmiBroker 32 bit/any other application(MetaTrader/Ninjatrader etc) Installed
Installation:
Download and run PiBridgeInstaller.exe
Note: Start PI, You will see the status bar showing pibridge status(RED) on the right end in the footer and
then start Amibroker.
Functionalities in PiBridge:
Note 2: All requests/responses Qty will be in LOTS (sent from PiBridge client)
1)Place orders:
To place orders, create pibridge object using CreateStaticObject (Amibroker function to create a global
instance) function and place orders using PlaceOrder function.
API Details:
PlaceOrder(string pExchnge, string pTrdSymbol, string pSymbol, string pUserStrategyName, short
pOrderSide, int pInitialQty, int pDiscQty, double pLimitPrice, double pTriggerPrice, string pOrderType, string
pProdType, string pClientCode, string pValidity)
==================================================================================================
Example:
//COM Calling function:
brd=Null;
if(IsNull(brd))
{
brd = CreateStaticObject("pibridge.Bridge");
}
//AFL Buy Logic
brd.PlaceOrder("NFO", "NIFTY15SEPFUT", "NIFTY","STRATEGYNAME", 1, 1, 1, 8500.05, 0, "L", "NRML",
"DN0005","DAY");
==================================================================================================
where ,
pExchange = "NSE" or NFO or BSE or or "BFO" or CDS or MCX
pTrdSymbol = NIFTY15OCTFUT
(you could see from Pi Marketwatch Trading symbol columns)
pSymbol = NIFTY or BANKNIFTY etc. should be within 10 characters
pUserStrategyName = strategy name through which orders are put to distinguish orders from different strategies..
pOrderSide = 1 or2 . 1 for Buy or 2 for sell
pInitialQty = 1 (put quantities in LOTS to trade)
pDiscQty = 0 for default
pLimitPrice = 8500.05 (price in INR for NIFTY15SEPFUT)
pTriggerPrice = 0 price in INR (send non-zero values in case of SL and SL-M order type)
pOrderType = L, MKT, SL, SL-M for Limit Market, StopLoss and StopLoss Market ordertypes.
pProdType = NRML or MIS or CNC
pClientCode = DN0005 Your Pi User id like DN0005
pValidity = DAY or IOC
Pi Bridge Help Document
API details:
ModifyOrder(string pOrderId, double pLimitPrice, int pQty, int pDiscQty, double pTriggerPrice, string
orderType)
where ,
pOrderId = Pi Order ID from the PiBridge log file for pending orders [mandatory cannot be empty]
pLimitPrice = Limit Price (price in INR for NIFTY15AUGFUT) [0 if not required to change]
pQty = quantity (qts in LOTS to trade ) [0 if not required to change]
pDiscQty = disclosed qty [0 if not required to change]
pTriggerPrice = trigger price (price in INR is 0 in L or MKT , non-zero values in case of SL and SL-M order type)
orderType ="L" or "MKT" or "SL" or "SL-M" or "" ["" if not required to modify the orderType]
Example:
brd.ModifyOrder("15085000058324", 1.51,0,0,0,""); //if Limit price needs to be modified, rest fields have to be 0 or "".
API details:
CancelOrder(string pOrderId)
where ,
pOrderId = Pi Order ID from the PiBridge log file for pending orders
Example:
brd.CancelOrder("150825000058324");
API details:
GetPendingOrders()
Example:
brd.GetPendingOrders();
API details:
GetTrades()
Example:
brd.GetTrades();
API details:
GetEqHoldings()
Example:
brd.GetEqHoldings();
Pi Bridge Help Document
API details:
GetFoPositions()
Example:
brd.GetFoPositions();
API details: (return value is in comma separated format ,which needs to be parsed)
or
==================================================================================================
Example:
or Values = brd.GetNetPosition();
==================================================================================================
where,
pTrdSymbol = NIFTY15AUGFUT
pProdType = NRML or MIS or CNC
positiontype ="Carry" or "Day"
RequestCash()
Example:
brd.RequestCash ();
API details: (return value is in comma separated format ,which needs to be parsed)
Example:
brd.GetCah (1); //EQUITY
brd.GetCash(2);//COMMODITY
where,
pExchnge = 1 (for Equity -NSE,BSE,BFO,CDS)
2 (for Commodity -MCX)
Pi Bridge Help Document
1) Connection Status:
bool GetConnectionStatus()
2) Pause Code:
PauseCode(int seconds)
3) Reconnect:
Reconnect()
=======================
Sample Codes in Ami-broker
=======================
For Order Placing:
_SECTION_BEGIN("PiBridge Test");
brd=Null;
if(IsNull(brd))
{
brd = CreateStaticObject("pibridge.Bridge");
}
if(!brd.GetConnectionStatus()) brd.Reconnect();
brd.PlaceOrder("NFO", "NIFTY15OCTFUT", "NIFTY","STRATEGY-S", 1,1, 1, 8700.25, 0, "L", "NRML", "RB0799","DAY");
================================================================
_SECTION_BEGIN("test");
plus=Null;
if(IsNull(plus))
{
plus = CreateStaticObject("pibridge.Bridge");
}
if(Start_Trading)
{
GfxSetBkColor(colorBlack);
Pi Bridge Help Document
GfxSetTextColor( colorWhite );
GfxSelectFont("Times New Roman", 25, 900, True );
GfxTextOut("You Are Trading", 200 , 20 );
}
_SECTION_BEGIN("PiBridge");
brd=Null;
TrdSymbol ="NIFTY15OCT6600PE";
ProdType="NRML";
positiontype="Carry";
TrdSymbol1 ="NIFTY15OCT9100CE";
ProdType1="NRML";
positiontype1="Day";
if(IsNull(brd))
{
brd = CreateStaticObject("pibridge.Bridge");
}
if(!brd.GetConnectionStatus()) brd.Reconnect();
CarryValues= brd.GetNetPosition(TrdSymbol, ProdType, positiontype);
DayValues= brd.GetNetPosition(TrdSymbol1, ProdType1,positiontype1);
PopupWindow("Time: " + Now() + "\n\n\n\n CarryForward values "+TrdSymbol+" "+ProdType+" is: " + CarryValues,"Pi
Admin Positions", 7200, 640*mtRandom(), 480*mtRandom());
PopupWindow("Time: " + Now() + "\n\n\n\n Daywise val for "+TrdSymbol1+" "+ProdType1+" is: " + DayValues,"Pi Admin
Positions", 7200, 640*mtRandom(), 480*mtRandom());