In this section, we will take a look at different parameters that are passed to the API functions.
Every trading platform has different formats for orders, positions, trades & margins. The job of AutoTrader is to hide these platform specific details and provide a standard format to our users. API functions accept standard formats as defined by AutoTrader team and our software internally converts it to a format specific to your trading platform.
AutoTrader API is provided in multiple programming languages. The description given below is generic and applies to all languages, hence there might be minor differences. Users are advised to look at language specific examples.
Order Id
Data Type – Text or String
Order id an id that uniquely identifies the order. In AutoTrader, you will deal with 3 types of order ids.
- Publisher Id – This is give in programming languages like AmiBroker AFL or MetaTrader MQL, where direct HTTP Rest communication is not possible. This id is generated by the API functions. AutoTrader will then map this to the actual order. This id might not be unique across different users, as the generation of id is done on client side.
- System Id – When AutoTrader receives a new order, it assigns a new id. This id is unique across all users of AutoTrader platform.
- Platform Id – This is an id given to the order by your stock broker’s trading platform.
Account
Data Type – Text or String
A pseudo account is basically a dummy account to be used for trading. The system internally maps it to an actual trading account. More details about how to create it.
Variety
Data Type – Text or String or Enumeration
Variety represents the kind of an order. We have 3 types of varieties:
- REGULAR – Represents a regular order
- BO – Represents a bracket order
- CO – Represents a cover order
Exchange
Data Type – Text or String or Enumeration
An exchange represents the stock exchange on which the order symbol is traded. We have 3 valid exchanges:
- NSE – National Stock Exchange
- BSE – Bombay Stock Exchange
- MCX – Multi Commodity Exchange
Symbol
Data Type – Text or String
A symbol represents a stock or derivative contract. Symbol must be a broker independent symbol. You can use this Indian API stock symbol search tool.
Trade Type
Data Type – Text or String or Enumeration
Represents a trade type or sometimes knows as transaction type. There are 2 valid trade types:
- BUY – Represents a buy order
- SELL – Represents a sell order
- SHORT – Represents a sell order (added for charting software support – only allowed in csv format used by Desktop client)
- COVER – Represents a buy order (added for charting software support – only allowed in csv format used by Desktop client)
Order Type
Data Type – Text or String or Enumeration
Represents an order type. There are 4 valid order types:
- LIMIT – Represents a limit order
- MARKET – Represents a market order
- STOP_LOSS – Represents a stoploss order
- SL_MARKET – Represents a stoploss market order
Product Type
Data Type – Text or String or Enumeration
Represents a product type. There are 3 valid product types:
- INTRADAY – Represents an intraday or MIS order
- DELIVERY – Represents a delivery order
- NORMAL – Represents a normal order
Validity
Data Type – Text or String or Enumeration
Represents order validity. There are 2 types of valid validity:
- DAY – Order is valid for the day (this is default)
- IOC – Immediate or cancel
Note: Do not confuse Validity with Product Type. Both are different things.
Quantity
Data Type – Numeric or Integer
AutoTrader functions pass the quantity as it is to the trading platform.
The confusion mostly happens for derivatives. Users are confused whether to pass quantity in multiple of lot size or number of lots? The answer is all trading platforms supported by AutoTrader take quantity in multiple of lot size.
Example: To buy 1 lot of NIFTY Future (assuming it has a lot size of 75), you need to enter quantity as
= (#lots * lots_size) = (1 * 75) = 75
Disclosed Quantity
Data Type – Numeric or Integer
Represents a disclosed quantity. It is an optional parameter and defaults to zero.
Price
Data Type – Decimal or Float
Represents order price. For a market order, this price is defaulted to zero.
Note: Price is automatically rounded to the nearest tick price. So users need not worry about price being a multiple of tick size. Example: A price of 50.54 with a tick size of 0.05 will be converted to 50.55.
Trigger Price
Data Type – Decimal or Float
Represents a trigger price. It is used in a stoploss order or a cover order.
Note: Trigger price is automatically rounded to the nearest tick price. So users need not worry about trigger price being a multiple of tick size. Example: A price of 50.54 with a tick size of 0.05 will be converted to 50.55.
Target (Bracket Order)
Data Type – Decimal or Float
Represents target of a bracket order.
Stoploss (Bracket Order)
Data Type – Decimal or Float
Represents stoploss of a bracket order.
Trailing Stoploss (Bracket Order)
Data Type – Decimal or Float
Represents trailing stoploss of a bracket order. In most cases, it should be an absolute value.
Upstox is a little different than other brokers, their system takes trailing stoploss in number of ticks. So if a stock or derivative has a tick size of 0.05, and you want to put a trailing stoploss of 1/-. The on upstox system, you need to enter 20, calculated as 1 divide by 0.05.
But as AutoTrader is broker independent, it takes trailing stoploss as absolute value (example, 1/- as explained above). Even for upstox accounts, the value should be entered as absolute (not in number of ticks). The system internally looks at the tick size and converts it into number of ticks.
AMO
Data Type – Text or String or Boolean
Indicates whether an order is an After Market Order.
- TRUE – means an order is AMO
- FALSE – means an order is not AMO (this is default)
Validate
Data Type – Boolean
This parameter is only used in AmiBroker. When it set to True, the system will not accept back to back BUY or back to back SELL orders. It will consider them as duplicate orders generated due to a known limitation of AmiBroker. When you get a signal in AmiBroker, it remains active until the candle is complete. Unfortunately, every time strategy runs during this active state; it will see that signal is active and place order; which results in duplicate orders being generated.
AmiBroker experts can set it to False and manage the signal in their strategy code. This simple flag was built for beginners.
OrderStatus
Data Type – Text or String or Enumeration
Represents order status which is broker independent. Broker specific statuses are not uniform, hence AutoTrader parses them into a standard status.
Valid values are:
- OPEN – Open
- COMPLETE – Complete
- CANCELLED – Cancelled
- REJECTED – Rejected
- TRIGGER_PENDING – Trigger pending
- UNKNOWN – Unknown (when system cannot determine the type from the raw order status received from stock broker)
MarginCategory
Data Type – Text or String or Enumeration
Represents margin category.
- EQUITY – Represents margin for Equity section of your account
- COMMODITY – Represents margin for Commodity section of your account
- ALL – Represents combined margin for Equity & Commodity
PositionCategory
Data Type – Text or String or Enumeration
Represents position category.
- DAY – snapshot of the buying and selling activity for that particular day
- NET – actual or current net position
PositionType
Data Type – Text or String or Enumeration
Represents position type.
- MIS – MIS or intraday position
- CNC – CNC or delivery position
- NRML – Normal position position
- BO – BracketOrder position
- CO – CoverOrder position
PositionState
Data Type – Text or String or Enumeration
Represents state of the position, which can be either OPEN or CLOSED.
- OPEN – The position is open
- CLOSED – The position is closed
PositionDirection
Data Type – Text or String or Enumeration
Represents direction of the position.
- LONG – A long position
- SHORT – A short position
- NEUTRAL – A neutral position