Broker API Calls 20211011 - Oct 2021
Broker API Calls 20211011 - Oct 2021
Broker API Calls 20211011 - Oct 2021
Broker API
User Manual
Damion Daley
4/23/2021
Broker API (BAPI) will enable Brokers via the Back Office System to connect directly to the Automated
Trading System (ATS). This manual will guide them on the steps required to integrate with and
consume BAPI service.
Revision History
Version
Revised Date Revised by Notes
#
1
BAPI-2021-03-12/02
Table of Contents
Revision History....................................................................................................................1
Overview..............................................................................................................................3
Things to Know....................................................................................................................4
How to connect to API..........................................................................................................4
Error Codes..........................................................................................................................4
API CALLS............................................................................................................................5
Company..........................................................................................................................5
GetBrokerCode...............................................................................................................5
Market..............................................................................................................................6
GetMarkets....................................................................................................................6
GetIndices.....................................................................................................................7
GetSymbolSummary.......................................................................................................8
GetSymbols...................................................................................................................9
GetOrderQueue............................................................................................................10
Order..............................................................................................................................11
GetOrderTypes.............................................................................................................11
Order...........................................................................................................................11
Order...........................................................................................................................13
Order...........................................................................................................................14
Order...........................................................................................................................15
GetFilteredOrders.........................................................................................................16
GetActiveOrders...........................................................................................................17
Security..........................................................................................................................18
Login...........................................................................................................................18
Logout.........................................................................................................................18
Trade..............................................................................................................................19
GetTrades....................................................................................................................19
GetCompletedTrades....................................................................................................20
Enums............................................................................................................................21
Definitions.......................................................................................................................22
Models............................................................................................................................23
Sample Code...................................................................................................................24
Login...........................................................................................................................24
ActiveOrders................................................................................................................25
Orders.........................................................................................................................27
Cancel Order................................................................................................................27
Edit Order....................................................................................................................28
Create Order................................................................................................................28
2
BAPI-2021-03-12/02
3
BAPI-2021-03-12/02
Overview
Broker API (BAPI) was developed to allow TTSE Brokers to communicate with the
Automated Trading System (ATS) from their Back Office Systems (BOS) via BAPI.
Developed with .NET CORE 3.1 using the Open API Specifications (OAS). The broker
will be required to have a username and password to connect to BAPI, from there they
can consume the endpoints available.
4
BAPI-2021-03-12/02
Things to Know
Here are a few things will be helpful to know to about BAPI:
Error Codes
400 – Token Not Supplied
5
BAPI-2021-03-12/02
API CALLS
Company
GetBrokerCode
RETURNS A LIST OF ALL BROKERS WITH THEIR BROKER CODE AND NAME.
GET /api/Company/GetBrokerCode
Parameters:
Returns: {
"results": [
{
"code": "string",
"name": "string"
}
]
}
6
BAPI-2021-03-12/02
Market
GetMarkets
RETURNS THE DIFFERENT MARKETS WITH THEIR NAME AND MARKET ID.
POST /api/Market/GetMarkets
Required
Parameters:
Optional
pageNumber (int) *Optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"name": "string",
"marketId": int
}
],
"count": int
}
7
BAPI-2021-03-12/02
GetIndices
RETURNS THE MARKET INDICES
POST /api/Market/GetIndices
Required
Parameters:
Optional
pageNumber (int) *Optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"tradeEngineId": "string",
"name": "string",
"lastUpdated": "DateTime",
"indexValue": double,
"marketCap": int,
"indexBase": int,
"previousValue": double,
"totalIssuedShares": int,
"change": double,
"percentageChange": double
}
],
"count": int
}
8
BAPI-2021-03-12/02
GetSymbolSummary
GIVES A SUMMARY OF THE MARKET SYMBOL ACTIVITY WITHIN A GIVEN PERIOD. THIS RETURNS ALL
RELEVANT INFORMATION FOR THE MARKET.
POST /api/Market/GetSymbolSummary
Required
Parameters: startDate (DateTime)
Optional
endDate (DateTime) *optional – defaults to current time
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"activityDate": "DateTime",
"bestBidPrice": double,
"bestAskPrice": double,
"bestBidVolume": int,
"bestAskVolume": int,
"totalBidVolume": int,
"totalAskVolume": int,
"symbolCode": "string",
"marketId": int,
"volumeTraded": int,
"percentChange": double,
"lastTradedQuantity": int,
"previousClosingPrice": double,
"marketMovement": double,
"externalClosePrice": double,
"lastTradePrice": double,
"openingPrice": double,
"totalValueTradedToday": double,
"high": double,
"low": double,
"marketIsOpen": Boolean,
"vwaptoday": double,
"termFormatId": "string",
"closeBid": double,
"closeAsk": double,
"currentMarketStatus": MarketStatus,
"referencePrice": double,
"currency": "string",
"lastUpdateTime": "DateTime"
}
],
"count": int
}
9
BAPI-2021-03-12/02
GetSymbols
GIVES A LIST OF THE MARKET SYMBOLS WITH THEIR SYMBOL CODE, COMPANY NAME, CURRENCY
CODE, TRADE STATUS, MARKET ID, ISIN, SHARE TYPE, AND THEIR MARKET STATUS
POST /api/Market/GetSymbols
Required
Parameters:
Optional
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"symbolCode": "string",
"companyName": "string",
"currencyCode": "string",
"tradable": Boolean,
"marketId": int,
"isin": "string",
"shareType": ShareType,
"marketStatus": MarketStatus
}
],
"count": int
}
10
BAPI-2021-03-12/02
GetOrderQueue
GIVES A LIST OF THE ORDERS THAT ARE CURRENTLY IN QUEUE WITH THEIR TYPE /ACTION, RANK IN
THE QUEUE, QUANTITY OF THE ORDER, PRICE, BROKER CODE, AND THE SYMBOL CODE.
POST /api/Market/GetOrderQueue
Required
Parameters:
Optional
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": Filter Type,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"action": ActionType,
"rank": int,
"quantity": int,
"price": double,
"brokerCode": "string",
"symbolCode": "string",
"currency": "string"
}
],
"count": int
}
11
BAPI-2021-03-12/02
Order
GetOrderTypes
RETURNS THE LIST OF THE NAMES AND ID OF THE DIFFERENT ORDER TYPES.
GET /api/Order/GetOrderTypes
Parameters: No Parameters
Returns: {
"Limit": "1",
"FillAndKill": "2",
"FillOrKill": "3",
"Iceberg": "4",
"Suspended": "5"
"MarketOrderFillOrKill": "6",
"MarketOrderTakeOrKill": "7",
"ReverseFillAndKill": "8"
}
Order
RETURNS THE DETAILS OF A SPECIFIED ORDER RETRIEVED BY THE GIVEN ORDER ID OR EXTERNAL REFERENCE
NUMBER
GET /api/Order
Required
Parameters: OrderId (int)
OR
External Reference Number (string)
OR
OrderReference
Optional
Returns: {
"order": [
{
"accountNumber": "string",
"clientCode": "string",
"brokerCode": "string",
"symbolCode": "string",
"marketId": int,
"actionType": ActionType,
"dateCreated": "DateTime",
"lastModifiedDate": "DateTime",
"currentPrice": double,
"currentVolume": int,
“icebergQuantity”: int,
"orderNumber": "string",
"currentExpiryType": ExpiryType,
"currentOrderStatus": OrderStatus,
"orderType": OrderType,
"currentExpiryDateUtc": "DateTime,
"lastErrorMessage": "string",
"lastErrorTime": "DateTime",
"externalId": int,
"externalReferenceNumber": "string",
"submitted": Boolean,
"orderReference": "string",
"currency": "string"
}
]
}
12
BAPI-2021-03-12/02
Order
CREATES A NEW ORDER FROM THE GIVEN PARAMETERS
POST /api/Order
Required
Parameters: accountNumber (string),
orderType (OrderType),
price (double),
volume (int),
symbolCode (string),
expiryType (ExpiryType),
actionType (ActionType)
Conditional
expiryDate (DateTime), *required when expiryType=GoodTillDate
Optional
externalReferenceNumber (string),
Returns: {
"order": {
"accountNumber": "string",
"clientCode": "string",
"brokerCode": "string",
"symbolCode": "string",
"marketId": int,
"actionType": ActionType,
"dateCreated": "DateTime",
"lastModifiedDate": "DateTime",
"currentPrice": double,
"currentVolume": int,
“iceburgeQuantity”: int,
"orderNumber": "string",
"currentExpiryType": ExpiryType,
"currentOrderStatus": OrderStatus,
"orderType": OrderType,
"currentExpiryDateUtc": "DateTime",
"lastErrorMessage": "string",
"lastErrorTime": "DateTime",
"externalId": int,
"externalReferenceNumber": "string",
"submitted": Boolean,
"orderReference": "string",
"currency": "string"
}
}
13
BAPI-2021-03-12/02
Order
UPDATES THE ORDER, USING WITH THE PARAMETERS PROVIDED
PUT /api/Order
Required
Parameters: orderReference (string),
OR
id (int),
accountNumber (string),
price (double),
volume (int),
symbolCode (string),
expiryType (ExpiryType),
Conditional
expiryDate (DateTime), *required when expiryType=GoodTillDate
Optional
Returns: {
"order": {
"accountNumber": "string",
"clientCode": "string",
"brokerCode": "string",
"symbolCode": "string",
"marketId": int,
"actionType": ActionType,
"dateCreated": "DateTime",
"lastModifiedDate": "DateTime",
"currentPrice": double,
"currentVolume": int,
“icebergQuantity”: int,
"orderNumber": "string",
"currentExpiryType": ExpiryType,
"currentOrderStatus": OrderStatus,
"orderType": OrderType,
"currentExpiryDateUtc": "DateTime",
"lastErrorMessage": "string",
"lastErrorTime": "DateTime",
"externalId": int,
"externalReferenceNumber": "string",
"submitted": Boolean,
"orderReference": "string",
"currency": "string"
}
}
14
BAPI-2021-03-12/02
Order
CANCELS THE ORDER THAT MATCHES THE ID PASSED.
DELETE /api/Order
Parameters: Required
externalId (string)
Optional
Returns: {
"order": {
"accountNumber": "string",
"clientCode": "string",
"brokerCode": "string",
"symbolCode": "string",
"marketId": int,
"actionType": ActionType,
"dateCreated": "DateTime",
"lastModifiedDate": "DateTime",
"currentPrice": double,
"currentVolume": int,
“icebergQuantity”: int,
"orderNumber": "string",
"currentExpiryType": ExpiryType,
"currentOrderStatus": OrderStatus,
"orderType": OrderType,
"currentExpiryDateUtc": "DateTime",
"lastErrorMessage": "string",
"lastErrorTime": "DateTime",
"externalId": int,
"externalReferenceNumber": "string",
"submitted": Boolean,
"orderReference": "string",
"currency": "string"
}
}
15
BAPI-2021-03-12/02
GetFilteredOrders
RETURNS A LIST OF THE ORDERS WITH A FILTER POSSIBLE IN THE PARAMETERS.
POST /api/Order/GetFilteredOrders
Parameters: Required
Optional
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"accountNumber": "string",
"clientCode": "string",
"brokerCode": "string",
"symbolCode": "string",
"marketId": int,
"actionType": ActionType,
"dateCreated": "DateTime",
"lastModifiedDate": "DateTime",
"currentPrice": double,
"currentVolume": int,
“icebergQuantity”: int,
"orderNumber": "string",
"currentExpiryType": ExpiryType,
"currentOrderStatus": OrderStatus,
"orderType": OrderType,
"currentExpiryDateUtc": "DateTime",
"lastErrorMessage": "string",
"lastErrorTime": "DateTime",
"externalId": int,
"externalReferenceNumber": "string",
"submitted": Boolean,
"orderReference": "string",
"currency": "string"
}
],
"count": int
}
16
BAPI-2021-03-12/02
GetActiveOrders
RETURNS A LIST OF ALL ACTIVE ORDERS ON THE TRADING PLATFORM FOR CURRENT BROKER.
POST /api/Order/GetActiveOrders
Parameters: Required
Optional
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"orderReference": "string",
"additionalOrderReference": "string",
"action": "string",
"symbolCode": "string",
"isin": "string",
"marketId": int,
"expiryDate": "DateTime",
"dealerCode": "string",
"icebergQuantity": int,
"orderNumber": "string",
"memberCode": "string",
"accountNumber": "string",
"quantity": int,
"price": double,
"state": "string",
"currency": "string"
}
],
"count": int
}
17
BAPI-2021-03-12/02
Security
Login
RETURNS A TOKEN USED TO LOG THE USER IN SECURELY
POST /api/Security/Login
Parameters: Required
username (string)
password (string)
Optional
Returns: {
"username": "string",
"fullname": "string",
"loggedIn": Boolean,
"accessToken": "string",
"accessTokenExpiresIn": long,
}
Logout
LOGS THE USER OUT SECURELY
POST /api/Security/Logout
Parameters: No Parameters
Returns: No Return
18
BAPI-2021-03-12/02
Trade
GetTrades
GET ALL THE TRADES, FOR ORDERS THAT THAT WERE PLACED USING THE API
POST /api/Trade/GetTrades
Parameters: Required
startDate (DateTime)
Optional
endDate (DateTime)
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"tradeEngineId": "string",
"tradeEngineTradeTime": "DateTime",
"volume": int,
"price": double,
"buyOrderNumber": "string",
"sellOrderNumber": "string",
"buyMemberNumber": "string",
"sellMemberNumber": "string",
"buyReferenceNumber": "string",
"sellReferenceNumber": "string",
"createdDate": "DateTime",
"tradeStatus": TradeStatus,
"wasRemoved": Boolean,
"currency": "string"
"settlementDate": "Datetime",
"orderReference": "string",
"actionType": "Buy",
"consideration": int,
, "symbolCode": "string",
"orderPrice": int,,
"orderType": "string",
"isin": "string",
"marketId": 0
}
],
"count": int
}
19
BAPI-2021-03-12/02
20
BAPI-2021-03-12/02
GetCompletedTrades
GET ALL THE TRADES, WITHIN THE GIVEN PARAMETERS, THAT WERE PLACED BY ALL CLIENTS FOR THE
BROKER.
POST /api/Trade/GetCompletedTrades
Parameters: Required
startDate (DateTime)
Optional
endDate (DateTime)
pageNumber (int) *optional – defaults to 1
amountPerPage (int) *optional – defaults to returning all
filters (Array[Filter])
orderBy (Array[OrderBy])
Returns: {
"pageNumber": int,
"amountPerPage": int,
"filters": [
{
"field": "string",
"filterType": FilterType,
"value": "string",
"joinType": JoinType,
"groupFilters": Array [Filter]
}
],
"orderBy": [
{
"field": "string",
"ascending": Boolean
}
],
"results": [
{
"orderReference": "string",
"id": int,
"additionalOrderReference": "string",
"action": "string",
"consideration": double,
"tradeEngineSymbolId": "string",
"symbolCode": "string",
"isin": "string",
"marketId": int,
"expiryDate": "DateTime",
"counterParty": "string",
"dealerCode": "string",
"memberCode": "string",
"price": double,
"tradeDate": "DateTime",
"tradeEngineId": "string",
"orderPrice": double,
"accountNumber": "string",
"volume": int,
"settlementDate": "DateTime",
"currency": "string"
}
],
"count": int
}
21
BAPI-2021-03-12/02
Enums
FilterType Enum:
[ Contains, GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo, Equal,
Group ]
JoinType Enum:
[ and, or ]
MarketStatus Enum:
[ PreOpened, Open, Closed, Halted]
ShareType Enum:
[ NotApplicable, Ordinary, Preference ]
ActionType Enum:
[ Buy, Sell ]
ExpiryType Enum:
[ GoodTillCancelled, GoodTillDate, GoodForDay ]
OrderStatus Enum:
[ Pending, Queued, RejectedByPlatform, PartiallyFilled, Filled, PendingCancel,
Cancelled, Expired, PendingEdit, PendingExpired, PartiallyFilledAndEdited,
PartiallyFilledAndCancelled, PartiallyFilledAndExpired, PendingUnsuspend,
PendingSuspend, Suspended ]
OrderType Enum:
[ Limit, FillAndKill, FillOrKill, Iceberg, Suspended, MarketOrderFillOrKill,
MarketOrderTakeOrKill, ReverseFillAndKill ]
TradeStatus Enum:
[ Inserted, Removed ]
22
BAPI-2021-03-12/02
Definitions
Order Status
Queued - Orders which have been queued and are awaiting a match in the trading platform.
RejectedByPlatform - Orders whose submission have been rejected by the trading platform
PendingEdit - Orders which were edited and are waiting to be queued in the trading platform.
PartiallyFilledAndCancelled - Orders which have been partially matched and the remaining
balance subsequently cancelled.
PartiallyFilledAndExpired - Orders which have been partially matched and the remaining
balance subsequently expired.
23
BAPI-2021-03-12/02
Models
Filter
field String nullable: true
filterType FilterType
value String nullable: true
joinType JoinType
groupFilters Array [Filter] nullable: true
OrderBy
field string
nullable: true
ascending boolean
24
BAPI-2021-03-12/02
Sample Code
Below is some sample code written in C#:
Login
MODELS
public class LoginRequestModel
{
public string Username { get; set; }
public string Password { get; set; }
}
METHOD
if (response.IsSuccessStatusCode)
{
var input = response.Content.ReadAsStringAsync().Result;
var _response =
JsonConvert.DeserializeObject<LoginResponseModel>(input);
auth_token = _response.AccessToken;
_response.Success = true;
return _response;
}
else
{
return new LoginResponseModel() { Error =
response.ReasonPhrase };
}
}
}
25
BAPI-2021-03-12/02
ActiveOrders
MODELS
public class BrokerApiListQuery
{
public int PageNumber { get; set; }
public int AmountPerPage { get; set; }
public ICollection<Filter> Filters { get; set; }
public ICollection<OrderBy> OrderBy { get; set; }
}
METHOD
26
BAPI-2021-03-12/02
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", auth_token);
if (response.IsSuccessStatusCode)
{
var input = response.Content.ReadAsStringAsync().Result;
var _response =
JsonConvert.DeserializeObject<ActiveOrderResponseModel>(input);
_response.Success = true;
return _response;
}
else {
return new ActiveOrderResponseModel() { Error =
response.ReasonPhrase };
}
}
}
27
BAPI-2021-03-12/02
Orders
Models
Cancel Order
public ResponseModel CancelOrder(string Id)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(base_url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", auth_token);
if (response.IsSuccessStatusCode)
28
BAPI-2021-03-12/02
{
var input = response.Content.ReadAsStringAsync().Result;
return new ResponseModel() { Success = true };
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
throw new UnauthorizedAccessException();
}
else
{
return new ResponseModel() { Error = response.ReasonPhrase };
}
}
}
Edit Order
public OrderResponseModel EditOrder(string AccountNumber, Order Order)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(base_url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", auth_token);
var Id = Order.Id.ToString();
if (response.IsSuccessStatusCode)
{
var input = response.Content.ReadAsStringAsync().Result;
var _response =
JsonConvert.DeserializeObject<OrderResponseModel>(input);
_response.Success = true;
return _response;
}
else if (response.StatusCode == HttpStatusCode.Unauthorized)
{
throw new UnauthorizedAccessException();
}
else
{
return new OrderResponseModel() { Error = response.ReasonPhrase };
}
}
}
Create Order
public OrderResponseModel CreateOrder (String AccountNumber, Order Order)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(base_url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", auth_token);
if (response.IsSuccessStatusCode)
{
var input = response.Content.ReadAsStringAsync().Result;
var _response =
JsonConvert.DeserializeObject<OrderResponseModel>(input);
_response.Success = true;
return _response;
}
29
BAPI-2021-03-12/02
else
{
return new OrderResponseModel() { Error = response.ReasonPhrase };
}
}
}
30
BAPI-2021-03-12/02