0% found this document useful (0 votes)
346 views5 pages

Amibroker Specific Pi Bridge - Help 2way

The Pi Bridge help document provides instructions on installing and using the Pi Bridge software to place orders, modify orders, cancel orders, and view positions and account information through a connection between PI and AmiBroker. Key functions of the Pi Bridge include placing orders, modifying orders, cancelling orders, viewing pending and filled orders, equity holdings, positions and available funds.

Uploaded by

saurabhjain2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
346 views5 pages

Amibroker Specific Pi Bridge - Help 2way

The Pi Bridge help document provides instructions on installing and using the Pi Bridge software to place orders, modify orders, cancel orders, and view positions and account information through a connection between PI and AmiBroker. Key functions of the Pi Bridge include placing orders, modifying orders, cancelling orders, viewing pending and filled orders, equity holdings, positions and available funds.

Uploaded by

saurabhjain2009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Pi Bridge Help Document

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 1: Once Pi/PiBridge is connected to Amibroker,all orders/trades will be logged in [Amibroker


installation directory]\ PIBRIDGE_[date].log (eg. C:\Program Files (x86)\AmiBroker\PIBRIDGE_07SEP2015.log )

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

2)Modify Orders:(Not enabled in 2 Way Semi Mode)

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 "".

3)Cancel Orders: :(Not enabled in 2 Way Semi Mode)

API details:

CancelOrder(string pOrderId)

where ,

pOrderId = Pi Order ID from the PiBridge log file for pending orders

Example:
brd.CancelOrder("150825000058324");

4)Pending Orders (logging mechanism):

API details:

GetPendingOrders()

Example:
brd.GetPendingOrders();

5)Completed Orders/Trades (logging mechanism):

API details:

GetTrades()

Example:
brd.GetTrades();

6)Equity Holdings (logging mechanism):

API details:

GetEqHoldings()

Example:
brd.GetEqHoldings();
Pi Bridge Help Document

7) Admin Positions (logging mechanism):

API details:

GetFoPositions()

Example:
brd.GetFoPositions();

8)View Admin Position values:

API details: (return value is in comma separated format ,which needs to be parsed)

string GetNetPosition(string pTrdSymbol, string pProdType,string positiontype)

or

string GetNetPosition() //Returns all AdminPositions values

==================================================================================================

Example:

Values= brd.GetNetPosition("NIFTY15JUL9100CE", "NRML","Carry");

or Values = brd.GetNetPosition("NIFTY15JUL9100CE", "NRML","Day");

or Values = brd.GetNetPosition();

==================================================================================================
where,
pTrdSymbol = NIFTY15AUGFUT
pProdType = NRML or MIS or CNC
positiontype ="Carry" or "Day"

9) Funds available (logging mechanism):

RequestCash()

Example:
brd.RequestCash ();

10) View Funds values:

API details: (return value is in comma separated format ,which needs to be parsed)

string GetCash(int pExchnge)

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

Other dll fuction call:

1) Connection Status:

It returns true/false if client is connected to Pi

bool GetConnectionStatus()

2) Pause Code:

This stops the code for the specified number of seconds.

PauseCode(int seconds)

3) Reconnect:

Reconnect()

This reconnects client to Pi

=======================
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");

brd.PauseCode(60); //Pause the code for 60 seconds


_SECTION_END();

================================================================
_SECTION_BEGIN("test");
plus=Null;
if(IsNull(plus))
{
plus = CreateStaticObject("pibridge.Bridge");
}

Trading_Symbol = ParamStr("Symbol", " NIFTY15OCTFUT");


Quantity = Param("Lots/Quantity",1, 1, 10, 1 ,1);
Strategy = ParamStr("Strategy Name", "Zerodha");
Button_Cover = ParamTrigger( "BUY", "Click Here To Buy");
Button_Sell = ParamTrigger( "SELL", "Click Here To Sell");
Start_Trading = ParamToggle("Start Trading", "No|Yes",0);
Trigger_Price = Param("Trigger Price",7900.00,0.00,10000.00,1.00);

if(Start_Trading)
{
GfxSetBkColor(colorBlack);
Pi Bridge Help Document
GfxSetTextColor( colorWhite );
GfxSelectFont("Times New Roman", 25, 900, True );
GfxTextOut("You Are Trading", 200 , 20 );
}

if(Button_Cover==1 AND Start_Trading==1)


{plus.PlaceOrder("NFO", Trading_Symbol, "NIFTY",Strategy, 1, Quantity, Quantity, Trigger_Price, 0, "L", "NRML",
"DN0005","DAY");
PopupWindow("Time: " + Now() + "\n\n\n\n Price: " + Trigger_Price,"Turtle: Cover " + Trading_Symbol, 7200,
640*mtRandom(), 480*mtRandom());
PlaySound("C:\\Windows\\Media\\tada.wav");}

if(Button_Sell==1 AND Start_Trading==1)


{plus.PlaceOrder("NFO", Trading_Symbol, "NIFTY",Strategy, 2, Quantity, Quantity, Trigger_Price, 0, "L", "NRML",
"DN0005","DAY");
PopupWindow("Time: " + Now() + "\n\n\n\n Price: " + Trigger_Price,"Turtle: Sell " + Trading_Symbol, 7200,
640*mtRandom(), 480*mtRandom());
PlaySound("C:\\Windows\\Media\\tada.wav");}
_SECTION_END();

For Admin Position Values:

_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());

brd.PauseCode(60);//Paused the code for 60 seconds


_SECTION_END();

You might also like