Broker API Calls 20211011 - Oct 2021

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

SOFTWARE ARCHITECTS LTD.

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 Feb. 17, 2020 D.Daley Completed the first draft of document.

2 March 12, 2021 DDaley Completed the second draft of document


3 April 23, 2021 MMyers
Updated API Calls: Get Trades
4 Oct. 11, 2021 MMyers Added order Types: Market Fill or Kill, Reverse Fill
and Kill, Market Take or Kill

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.

Please note the Endpoints available via BAPI:

 Company (Not for Brokers)


 Market
o Market – Will give you a listing of all the markets on the TTSE
o Indices – This will give you the information for the current days Indices
o Symbols – Returns a list of symbols listed on TTSE
o Symbol Summary – Give the current day latest symbol summary
information e.g. price, best bid and ask etc…
o Order Queue – Get the active Buy and Sell request for each symbol
 Order – Cover the Order Management process as listed below:
o Create – Submit Order to be places on ATS
o Edit – Modify an Order e.g. price, quantity
o Cancel – Send request to remove previously submitted order from ATS
o Active – Request list of Active orders available on ATS
 Security – This relates to the User management and access to system. With
endpoints as follows:
o Login – This is required for you to access the API to retrieve or submit
requests.
o Logout – When completed using the API you can disconnect.
o Create Login – Used by TTSE admins to create credentials for Brokers to
use to access API.
 Trade – This returns all the trades for the day or a designated period.

4
BAPI-2021-03-12/02
Things to Know
Here are a few things will be helpful to know to about BAPI:

 BAPI was developed using .NET Core and OAS.


 The link to the test API is https://top1.stockex.co.tt/swagger/index.html/.
Production link will be provided by TTSE IT.
 You will require a Username and Password. This will be provided by TTSE IT.
 The BAPI will only give recent data, in some cases only current day. You are
responsible for the storing of Historical data.
 To get the most recent data for Symbols or Order Status you will be required to
keep requesting updates from system.
 When you submit orders, you will be required to query Active Orders to get
Order Update.
 For expired orders you will not receive any update. You will simply change order
status to “Expired”. If you check the Active Orders list that order should no
longer exist.
 This API is a REST service. User must be authenticated for all calls.
 The parameters and the responses are JSON formatted.

How to connect to API


Using the LOGIN API call, pass over the username and password. If successful, the
response will contain an Access Token. This is used as an authorization token needed
for the calls to the other methods. This token is passed over in a Bearer Header as part
of the requests to the other endpoints.

Error Codes
400 – Token Not Supplied

401 – Invalid Token

500- Internal Server Error. Contact Administrators.

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

Pending - Orders which are waiting to be queued in the trading platform.

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

PartiallyFilled - Orders which have been partially matched

Filled - Orders which have been fully matched.

PendingCancel - Orders which are waiting to be cancelled in the trading platform.

Cancelled - Orders which have been cancelled.

Expired - The expiry date for the order has passed.

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.

Suspended - Orders which have been suspended in the trading platform.

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; }
}

public class LoginResponseModel


{
public string Username { get; set; }
public string Fullname { get; set; }
public bool LoggedIn { get; set; }
public string AccessToken { get; set; }
public long AccessTokenExpiresIn { get; set; }
}

METHOD

public LoginResponseModel Login(LoginRequestModel model)


{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(base_url);
client.DefaultRequestHeaders.Clear();
HttpResponseMessage response = await
client.PostAsJsonAsync("api/security/login", model);

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; }
}

public class ActiveOrderResponseModel : PagedResponseModel


{
public ICollection<ActiveOrder> results { get; set; }
}

public class PagedResponseModel


{
public int count { get; set; }
public int pageNumber { get; set; }
public int amountPerPage { get; set; }
public ICollection<OrderBy> orderBy { get; set; }
public ICollection<Filter> filters { get; set; }
}

public class ActiveOrder


{
public int Id { get; set; }
public string OrderReference { get; set; }
public string AdditionalOrderReference { get; set; }
public string SymbolCode { get; set; }
public string TradeEngineSymbolId { get; set; }
public string MemberCode { get; set; }
public DateTime? ExpiryDate { get; set; }
public string DealerCode { get; set; }
public string AccountNumber { get; set; }
public decimal Price { get; set; }
public string State { get; set; }
public int Quantity { get; set; }
public int IcebergQuantity { get; set; }
public string OrderNumber { get; set; }
public string Action { get; set; }
public string ISIN { get; set; }
}

METHOD

public ActiveOrderResponseModel GetActiveOrdersAsync(BrokerApiListQuery


query)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(base_url);
client.DefaultRequestHeaders.Clear();

26
BAPI-2021-03-12/02
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", auth_token);

var response = await


client.PostAsJsonAsync("api/Order/GetActiveOrders/", query);

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

public class ResponseModel


{
public bool Success { get; set; }

public string Error { get; set; }


}
public class OrderResponseModel : PagedResponseModel
{
public ICollection<Order> results { get; set; }
}

public class Order


{
public Guid Id { get; set; }
public Guid AccountId { get; set; }
public Guid CompanyId { get; set; }
public string SymbolCode { get; set; }
public int ActionType { get; set; }
public DateTime DateCreated { get; set; }
public DateTime? LastModifiedDate { get; set; }
public decimal CurrentPrice { get; set; }
public int CurrentVolume { get; set; }
public string OrderNumber { get; set; }
public int CurrentExpiryType { get; set; }
public int CurrentOrderStatus { get; set; }
public DateTime? CurrentExpiryDateUtc { get; set; }
public string LastErrorMessage { get; set; }
public DateTime? LastErrorTime { get; set; }
public int ExternalId { get; set; }
public bool Submitted { get; set; }
public string OrderReference { get; set; }
public virtual Account Account { get; set; }
public virtual Company Company { get; set; }
public virtual Symbol SymbolCodeNavigation { get; set; }
public virtual ICollection<OrderVersion> OrderVersions { get; set; }
public virtual ICollection<Trade> Trades { get; set; }
}

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

HttpResponseMessage response = await client.DeleteAsync("api/Order/" +


Id);

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

HttpResponseMessage response = await client.PutAsJsonAsync("api/Order/" +


Id, new { AccountNumber , Order });

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

HttpResponseMessage response = await client.PostAsJsonAsync("api/Order/",


new { AccountNumber, Order });

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

You might also like