Passive Bridge Functions

Passive Bridge Functions

 

In passive mode, Bridge just works like a communication medium with some added intelligence. If your strategy needs full control over order processing you may choose this mode. In this mode you can manage the whole order processing cycle.

 

In this mode, Symbol Mapping will not be used, however you need to Configure User Settings and Strategy Setting, these will be applicable as usual. Signal Rules like Cancel Previous Open Signal, Stop and Reverse etc will not work in these calls.

 

Below is the list of functions which you are able to use in this mode. Each of the given parameters described below for more clarification.

 

Connectivity and Other Functions

 

  1. IB_Ping ()

Description: Used to check the status of the Bridge.

 

Return Type: boolean

 

If True, mean Stoxxo is running and  Trading also started, Otherwise Stoxxo is not started or some issue exists in connectivity or Trading is stopped

 

 

  1. IB_SquareOff (UserID)

Description: Square Off all the positions of provided User ID. It will square off all the positions including positions taken manually (if any) and further trading will be stopped for the session.

 

Imp Note

  • It square off Intraday CNC and NRML Positions as per the General Settings in Stoxxo.
  • Further trading will be stopped in the User for the session or untill bridge restarts.

Parameter: UserID (mandatory)- User ID of the user you wish to perform squareoff

If User ID supplied as null or empty string, the Bridge will initiate Square Off for the first active logged-in user.

 

If User ID supplied as ALL, then it will Square off all logged-in users.

 

Return Type: bool

 

 

  1. IB_SquareOffAll ()

Description: Square Off all the positions from all active logged-in users. It will square off all the positions including positions taken manually (if any) and further trading will be stopped for the session for all active users in the bridge.

 

Imp Note

  • It square off Intraday CNC and NRML Positions as per the General Settings in STOXXO.
  • Further trading will be stopped in all Users for the session or untill bridge restarts.

Return Type: bool

 

  1. IB_SquareOffStrategy(StrategyTag)

Description: Square Off / Exit all the Orders related to the provided Strategy ID.

 

Imp Note

  • It Exits the Intraday CNC and NRML Positions.
  • Further trading will be stopped for the Strategy until bridge restarts.
  • It will Exit all orders under the strategy from all the related users.

Parameter: StrategyTag(mandatory)- Strategy ID for which you wish to perform squareoff. Providing a valid Strategy Tag is mandatory.

 

Return Type: bool

 

 

  1. IB_MTM (UserID)

Description: Function to get the MTM of provided userid. It provides complete MTM including any manual positions as well.

 

Parameter: UserID – User ID of the user you wish to check MTM.

If UserID supplied as null or empty string, then Bridge will return the MTM for the first active logged-in user.

 

Return Type: bool

 

  1. IB_AvailableMargin (UserID)

Description: Function to get the Available Margin in the mentioned account. This is generally Equity Margin available or ALL margin depending upon the broker.

 

Parameter: UserID – User ID of the user you wish to check MTM.

If User ID supplied as null or empty string, then Bridge will return the Margin for the first active logged-in user.

 

If User ID supplied as ALL, then it will add Margins of all logged-in users and provide the same.

 

Return Type: Decimal

 

  1. IB_AvailableMarginCommodity (UserID)

Description: Function to get the Available Margin for commodity segment for the mentioned account.

 

Parameter: UserID – User ID of the user you wish to check MTM.

If User ID supplied as null or empty string, then Bridge will return the Margin for the first active logged-in user.

 

If User ID supplied as ALL, then it will add Margins of all logged-in users and provide the same.

 

Return Type: Decimal

 

Order Placement Functions

 

  1. IB_PlaceOrder (Unique ID, Strategy Tag, UserID, Exchange, Symbol, TransactionType, OrderType, Validity, ProductType, Qty, Price, TriggerPrice, ProfitValue, StoplossValue, SLTrailingValue, DisclosedQuantity, SignalLTP, Data Provider)
  1. IB_PlaceOrderAdv (Unique ID, Strategy Tag, UserID, Exchange, Symbol, TransactionType, OrderType, Validity, ProductType, Qty, Price, TriggerPrice, ProfitValue, StoplossValue, SLTrailingValue, DisclosedQuantity, Data Provider, TgtTrailingValue, BreakEvenPoint, SignalLTP,  MaxLTPDifference, PriceSpread, TriggerSpread, CancelIfNotCompleteInSeconds)

 

Functions Signature For AmiBroker

 

  • IB_PlaceOrder (Strategy Tag, UserID, Exchange, Symbol, TransactionType, OrderType, Validity, ProductType, ProfitValue, StoplossValue, SLTrailingValue, Data Provider, Unique ID, Qty, Price, TriggerPrice, DisclosedQuantity, SignalLTP)
  • IB_PlaceOrderAdv (Strategy Tag, UserID, Exchange, Symbol, TransactionType, OrderType, Validity, ProductType, ProfitValue, StoplossValue, SLTrailingValue, Data Provider, TgtTrailingValue, BreakEvenPoint, MaxLTPDifference, PriceSpread, TriggerSpread, Unique ID, Qty, Price, TriggerPrice, DisclosedQuantity, SignalLTP, CancelIfNotCompleteInSeconds)

Description: Function to place order.

 

Parameter: Each parameter described in below grid.

 

Return Type: Integer (Request ID)

 

On Success:

Returns the RequestID as an integer which can be used to Cancel / Modify orders(s). If you’re having multiple users enabled, still this request id will be for the whole request and any cancellation etc will be performed for all users.

 

Valid RequestID should be greater than 90000

 

On Failure:

Returns the Failure ID, which again is an integer but this will be less than 90000. If you want to check for errors then you can call IB_GetError function by supplying this id to check the exact error message.

 

Imp Note

  1. To save from Strategy MisFire, These functions will decline any duplicate signal till next 5 mins. To find the duplicate Signal, it uses UniqueID, Exchange, Symbol, Strategy Tag, Transaction Type, Qty, Price, Trigger Price combination.
  1. If you had enabled Multiple Users in the Bridge then Bridge will process orders in different ways and you will just get a success response with request id of the bridge.

Now you can use this RequestID or UniqueID (if you provided at the time of placing order) to modify / cancel the Order.

 

  1. Use IB_CancelOrExitOrder To Cancel / Exit the Order even for MIS. Exiting using IB_CancelOrExitOrder will take care of executed quantity and other things while exiting the order properly.

However, if you want, you can place reverse orders as well in case of MIS / NRML.

 

  1. Bridge returns the RequestID immediately after accepting the request for processing so that your Charting Platform doesn’t get hung / freeze.

Intelligent bridge internally is fully asynchronous and multi-threaded as well as communications between the provided plugins and bridge is also multi-threaded / asynchronous.

 

  1. Receiving a Request ID from Bridge doesn’t mean that order was successful. Sometimes brokers reject the order due to any reason. You may check for status to confirm about the Order.

Order Modify Functions

 

  1. IB_ModifyOrder (Unique ID / Request ID, Qty, Price, TriggerPrice, ProfitValue, StoplossValue, SLTrailingValue, TgtTrailingValue, BreakEvenPoint)

            Functions Signature For AmiBroker

 

  • IB_ModifyOrder (ProfitValue, StoplossValue, SLTrailingValue, TgtTrailingValue, BreakEvenPoint, Unique ID / Request ID, Qty, Price, TriggerPrice)

Description: Function to modify the open order. It can also be used to modify the Target / SL for BO / CO orders. It is important to note that this function will only work for order placed through IB_PlaceOrder or IB_PlaceOrderAdv.

 

You can either supply the UniqueID or the Request ID received from IB_PlaceOrder call. This is a mandatory parameter and rest all are optional.

 

Here you can supply the parameter which you actually want to modify and rest others can be set as default values ( Meaning “” for string and 0 for numbers and decimals)

 

Parameter: Each parameter described in below grid.

 

Return Type: bool

 

Order Exit or Cancellation Functions

 

  1. IB_CancelOrExitOrder (Unique ID / Request ID)

Description: Function to cancel the open order or to exit any running MIS / BO / CO Order.

You can either supply the UniqueID or the Order ID received from IB_PlaceOrder call. It is important to note that this function will only work for order placed through IB_PlaceOrder or IB_PlaceOrderAdv.

 

For Simple / MIS Order, this function can be used to cancel the order if that order is still open. If Simple / MIS Order was completed then This function will place a reverse order. Example if the order placed a SELL order then IB_CancelOrExitOrder will place the BUY order for the executed quantity and it will exit if that Order fails if that order was already completed.

 

For BO and CO order, this function will cancel the order if order is still open. In case the main order is already completed and their SL / Target orders are still pending then this function will exit the BO / CO Order.

 

Return Type: bool

 

Imp Note

 

  1. If you had enabled Multiple Users in the Bridge then Bridge may have placed multiple orders for a single PlaceOrder call.

In this case bridge will Cancel / Exit all the associated orders.

 

Market Data Functions

 

  1. IB_Subscribe (Exchange, Symbol, DataProvider)

Description: Function to Subscribe for the particular symbol in Broker’s Feed. This is a one time activity and do not subscribe every time.

 

It is strongly advisable to subscribe for feed before calling IB_LTP etc functions.

 

Return Type: void

 

  1. IB_LTP (Exchange, Symbol, DataProvider)

Description: Function to get the Last Trading Price for mentioned Symbol. This function will only work when the broker is providing Market Feed Data. Very first call of the functions may be delayed with a few seconds, however subsequent calls will be much faster.

 

Return Type: decimal

If Success then returns the LTP from Market Feed from Broker, else returns 0.

 

  1. IB_BID (Exchange, Symbol, DataProvider)

Description: Function to get the Best BID Price for mentioned Symbol. This function will only work when the broker is providing Market Feed Data. Very first call of the functions may be delayed with a few seconds, however subsequent calls will be much faster.

 

Return Type: decimal

If Success then returns the Best BID from Market Feed from Broker, else returns 0.

 

  1. IB_ASK (Exchange, Symbol, DataProvider)

Description: Function to get the Best ASK Price for mentioned Symbol. This function will only work when the broker is providing Market Feed Data. Very first call of the functions may be delayed with a few seconds, however subsequent calls will be much faster.

 

Return Type: decimal

If Success then returns the Best ASK from Market Feed from Broker, else returns 0.

 

  1. IB_FeedLTP (Exchange, Symbol, DataProvider, LTP, BID, ASK)

Description: If Broker is not providing feed and still you wanted to use advanced functionality of Intelligent Bridge, Then you can submit LTP Data from your Charting Platform.

 

Return Type: void

 

Order Details Functions

 

Below functions will only work if order was placed using IB_PlaceOrder or IB_PlaceOrderAdv.

 

  1. IB_OrderID (Unique ID / Request ID)

Description: Function to get the Order ID for provided Unique ID. If orders were placed for more than one user then it will provide comma separated Order IDs for all users.

 

Return Type: String

If Success then returns the Broker Order ID, else returns the empty string.

For multiple Users, you will get list of comma separated Order IDs

 

  1. IB_LastOrderID (UserID)

Description: Function to get the Order ID for last placed order. It will return the Order ID for the very last order placed.

 

Return Type: String

If Success then returns the Broker Order ID, else returns the empty string.

 

  1. IB_OrderStatus (Unique ID / Request ID)

Description: Function to check the latest status of the Entry Order. If orders were placed for more than one user then it will provide comma separated Order IDs for all users.

 

You can either supply the UniqueID or the Request ID received from the Place Order call.

 

Return Type: String

If Success then returns the below given statuses, else returns the empty string.

For multiple Users, you will get list of comma separated Order IDs

 

Possible Status Values

  • open
  • completed
  • rejected
  • cancelled

This gives the status of the whole signal, in case of multiple users it is possible that order may get placed in few and it may get rejected in others. In this case Bridge will give status of signal as completed as order was executed for few users.

 

  1. IB_OrderQty (Unique ID / Order ID)

Description: Function to get the Quantity of the order.

 

Return Type: Integer

If Success then returns the Quantity used while placing the order, else returns the 0.

For multiple Users, this will return Order Qty for very first user.

 

  1. IB_OrderFilledQty (Unique ID / Order ID)

Description: Function to get the Filled Quantity of the very first order of signal. Filled Quantity is the actual quantity which is actually executed against the order. Eg we placed an order for 100 qty but till now we received only 25 qty then this function will return only 25.

 

Return Type: Integer

If Success then returns the Filled Quantity, else returns the 0.

For multiple Users, this will return Filled Order Qty for very first user.

 

  1. IB_OrderAvgPrice (Unique ID / Order ID)

Description: Function to get the Average execution price of the very first Entry Order of the signal. If order is still open then this function will return 0.

 

Return Type: Decimal

If Success then returns the Avg Price, else returns the 0.

For multiple Users, this will return Avg Price for very first user.

 

  1. IB_IsOrderOpen (Unique ID / Request ID)

Description: Function to check the status of the first Entry Order of signal, if that is still open. For CO and BO orders it will check only for Main Order.

 

Return Type: bool

If order is still open then true otherwise false.

For multiple Users, this will check and return status for very first order placed for signal.

 

  1. IB_IsOrderRejected (Unique ID / Request ID)

Description: Function to check the status of the  first Entry Order of signal, if that is Rejected. For CO and BO orders it will check only for Main Order.

 

Return Type: bool

If the order is rejected then true otherwise false.

For multiple Users, this will check and return status for very first order placed for signal.

 

  1. IB_IsOrderCompleted (Unique ID / Request ID)

Description: Function to check the status of the  first Entry Order of signal, if that is Completed. For CO and BO orders it will check only for Main Order.

 

Return Type: bool

If the order is completed then true otherwise false.

For multiple Users, this will check and return status for very first order placed for signal.

 

  1. IB_IsOrderCancelled (Unique ID / Request ID)

Description: Function to check the status of the  first Entry Order of signal, if that is cancelled. For CO and BO orders it will check only for Main Order.

 

Return Type: bool

If the order is cancelled then true otherwise false.

For multiple Users, this will check and return status for very first order placed for signal.

PARAMETERS DETAILS

 

S.NO

PARAMETER

OPTIONAL/ MANDATORY

VALID INPUT

WHAT IT DOES?

DESCRIPTION

1

Unique ID

Mandatory

Integer

You can send a unique number with every place order call so that the same can be used to perform the order order functions such as modification, cancellation, status check etc.

➢   This also ensures that no duplicate order gets placed for the same ID.

➢    This ID can be used to manage order by using Modification, cancellation functions etc.

➢    If no proper response was received for order call, then this ID can be used to check status / order id.

2

Strategy Tag

Mandatory

String

Implements strategy rules as per Strategy Grid

➢   One can create their own strategy tags and can apply strategy rules.

➢    Strategy’s signal rules such as Cancel Previous Open Signal, Stop and Reverse etc will not work here.

3

UserID

Mandatory

String

UserID from the User Settings Grid.

If you want to perform operations on ALL Logged-In users, then just pass UserID as ALL.

Example: IB_MTM(“ALL”) will return the combined MTM.

In place Order, it will place orders into all users.

➢   This ensures that the given order is placed in the mentioned user with his settings.

➢    If you wish to place for multiple users, then you can call a function for multiple times with different user ids.

➢    In most of the cases, if you supply UserID as empty string or null then Bridge will select the first logged-in user.

➢    If you’re using only one user, this can be an empty or null string.

4

Exchange

Mandatory

String

NSE, NFO, BSE, CDS, MCX

➢   Exchange to place the order. Send the exchange from provided values only.

5

Symbol

Mandatory

String

Trading Symbol as per the Selected User’s Broker.

➢    Every broker is having a different format for symbols especially in case of Futures and Options. For your ease, here we are providing a few simple formats so that the bridge can convert into the proper format required for a user’s broker.

➢    NSE, BSE: Symbol will be used as it is.

➢   For Futures: Send in below format Symbol Month FUT

Eg ACCMAYFUT, PNBNOVFUT

 

➢    For Options:

Symbol Expiry (ddMMM) CE or PE

Eg. ACC29OCTCE, NIFTY05NOVPE

6

Transaction Type

Mandatory

String

BUY, SELL

➢   BUY for Long and SELL for Short.

7

Order Type

Mandatory

String

MARKET, LIMIT, SL, SL-M

Type of the Order you wanted to place.

Valid For BO: SL and SL-M

Valid For CO: MARKET, LIMIT

8

Validity

Optional

String

DAY,

IOC

If not supplied, then DAY will be used as default value.

9

Product Type

Mandatory

String

MIS,

CNC,

NRML,

BO,

CO

Product type of the Order.

10

Quantity

Mandatory

N/A

Specify the quantity for Order

➢   For Futures and Options, specify quantity in lots. Eg For Nifty Future 1 quantity will be converted into 75

10

Price

Mandatory for L and SL Order Types.

Else Not Required

Decimal

It conveys the price for Limit or Stop Loss Limit Orders

➢   Should be mandatorily conveyed to STOXXO for LIMIT and SL orders.

➢   Not Required if the order types are Market / SL-M

11

Trigger Price

Mandatory for SL and SL-M Order Types.

Else Not Required

Decimal

Trigger Price for SL and SL-M Order.

 

12

Profit Value

Depends on Product Type

Required for BO Orders

Decimal as String

Specifies the target for BO Order

➢   Should be mandatorily conveyed to Bridge for BO orders.

➢   Optional for other order types.

➢   If the broker is providing the streaming data, then Bridge will take care of Targets for Simple and CO Orders as well.

➢   If you want to specify in target points then just fill the value and if you want to specify in percentage then put a % sign after value Eg 0.50%. IB automatically computes the target based on your input and the entry / execution price.

9

Stop Loss Value

Mandatory for BO & CO

Optional for MIS and  others

Decimal as String

Specifies the SL for BO & CO Orders

➢   Should be mandatorily conveyed to STOXXO for BO & CO orders.

➢   Unsupported for other order types.

➢   If the broker is providing the data feed, then Bridge will take care of Stop loss for Simple Entry Orders.

➢    If you want to specify in points then just fill the value and if you want to specify in percentage then put a % sign after value Eg 0.40%.

10

SL Trailing Value

Optional

Decimal as String

Specifies the Trailing SL for BO Orders.

➢   Can be optionally conveyed to IAB for BO orders.

➢   Unsupported for other order types.

➢   If the broker is providing the data feed, then Bridge will take care of Trailing Stop loss for Simple and CO Orders.

➢    If you want to specify in points then just fill the value and if you want to specify in percentage then put a % sign after value Eg 0.10%.

11

Disclosed Quantity

Optional

Integer

Specifies the Disclosed Quantity for Orders.

Default is 0

 

➢    This should be more than 10% of Quantity mentioned in above fields.

12

Tgt Trailing Value

Optional

Decimal as String

Once the price reaches your target, Bridge will keep your position open and wait for the price to give more movement.

In uncommon scenarios it is possible your trade may get exit below then the Target specified.

It is mandatory to set the Target for using this field.

➢    Never specify any big value for Target Trailing. It is suggested to set between 10 to 30% of original target value. Eg if Target is 5% then Trailing can be 1%.

➢    It is important to note that bridge has to give some space for price fluctuations because price never goes simply in one direction, so in certain conditions your target may be hit lower than Target specified.

➢    This feature will not work with BO as Target is already supplied to the broker while placing the Order.

➢    If you want to specify in points then just fill the value and if you want to specify in percentage then put % sign after value Eg 0.30%.

13

Break Even Point

Optional

Decimal as String

Once price reaches the mentioned value in break even point, Bridge will modify the Stoploss to Avg Price + 0.05% which is approximately break even point after deducting the brokerage and taxes.

Example: You set a value of 0.25% in break even point for a buy trade. Now whenever price will reach the Avg Buy Price + 0.25%, STOXXO will modify the Stoploss to Avg Buy Price + 0.05%.

If you want to specify in points then just fill the value and if you want to specify in percentage then put % sign after value Eg 0.50%.

It is Important to note that, if you had also set for Stop Loss trailing, it will be still continuing and whenever trailing calculations cross the modified stop loss it will start trailing again.

14

Signal LTP

Optional

Decimal as String

Captures the signal price from charting platform

➢   LTP from the charting platform.

15

Max LTP Difference

Optional

Decimal as String

Data vendors and brokers both are different and there are occasions where prices can be different between data vendors and the broker.

This is a common situation for options / derivative traders.

If this is set and Charting LTP (Signal LTP) is provided with signal then bridge will match the Broker LTP with Charting LTP and if it is in mentioned range, then only it will allow the order.

If no Charting LTP was provided with a signal, then this cannot be validated and this field will be ignored.

Example: You set a value of 0.10% and Signal is having LTP of 101 but the Broker LTP is 100.50, then bridge will reject this order as LTP Difference is higher then the set limit.

If you want to specify in points then just fill the value and if you want to specify in percentage then put % sign after value Eg 0.50%.

 

16

Price Spread

Optional

Decimal as String

There are occasions where you want to place LIMIT, SL order with respect to current LTP.

In other means, a trader doesn’t want to place a market order as it can be executed way beyond his expected price. So he can set Price Spread with Limit Order so that he need not to worry for any unexpected price.

For Limit and SL orders Limit price needs to be fed with the order as a mandatory parameter. Bridge is providing 2 ways to provide the price required for LIMIT / SL Orders.

1.     You can supply the Price with the Signal and the same will be sent as Price for Limit / SL orders.

2.     Or you can mention the Price Spread field which will calculate the price based on current LTP of the stock and will be sent as a price for Limit / SL orders.

If Price was supplied with the signal, then that will be used as it is. In that case this field doesn’t have any impact.

Example: You set a value of 0.50% and current LTP is 100 then bridge will send the Price as 100.50 for LIMIT, SL Order.

If you want to specify in points then just fill the value and if you want to specify in percentage then put % sign after value Eg 0.50%.

17

Trigger Spread

Optional

Decimal as String

Likewise Price Spread, Trigger spread can also be set. Remember to give proper values to both. Trigger Spread should be lesser than or equal to the price spread.

If Trigger was supplied with signal, then that will be used as it is. In that case this field doesn’t have any impact.

Suppose, You set a value of 0.40% and current LTP is 100 then IAB will send the Trigger Price as 100.40 for Sl-Market, SL Orders.

If you want to specify in points then just fill the value and if you want to specify in percentage then put % sign after value Eg 0.40%.

18

Cancel If Not Complete In Seconds

Optional

Integer

There are occasions where you want to cancel an order which was left uncompleted for a certain period of time. Here you can set time in seconds and the bridge will check order status after time elapses and if found open then order will be cancelled.

Minimum value for this is 5 Seconds.

Example: a limit buy order placed with a price of 100 but price kept moving upward and this order was left open.

Now after 2 hours, stock takes bearish movement and now coming back to 100 and order will get executed then.

This field can be used to save from these kinds of situations.

19

DataProvider

Optional

String

It is possible that your Charting software may be using different Stock Symbol then your broker.

IAB can parse the Symbol from all standard data providers.

If you don’t know the data provider, then try using Symbol Mapping checker with different data provider and see which data provider is capable to parse your symbol properly.

Check section How to select dataprovider if you don’t know.

Leave a Reply

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