Skip to main content
Version: 1.2.0 - Production

Trade Streaming

This component creates a web socket with clients. Once established the Clients can receive trade updates through this service.

How to connect

In order to connect to GTN API TRADE STREAMING UAT, setup a WebSocket connection should be established to the following endpoint,

wss://gtn-api-uat.globaltradingnetwork.com/websocket/v1.2

Authenticate

Once a Websocket connection is established, the program is required to send a message with token information as following for authentication purposes.

{
"token": "auth_token"
}

Users cannot do anything without getting authenticated with GTN. Socket connection will be closed within 1 min if the authentication process has failed.

A server token or a customer token can be used; to connect to trade streaming. However only 1 server token will be support at any given time for an institution.

A valid token must be used to establish socket connection.

Snapshot

Whenever trade streaming is down, the client can get the lost data for a down period. Response contains all open orders till now & status updated orders from the requested time till now.

If the connection is requested by a customer token, response only contains orders related to customer number. If the connection is requested by a server token, response contains all orders related to the institution.

Snapshot can be requested for:
  • only once for a connection
  • a maximum 24hrs time period

If the client is disconnected for more than 24hrs from trade-streaming or the client wants to check the status of a particular order, Order Search or Get Oder Details endpoints can be used for it.

Request:
{
"command": "snapshot",
"sTime": "string",
"type": "trade"
}
Request Fields:
  • command (required)
  • sTime (optional)
    • starting time
    • Value must match regular expression yyyy/MM/dd HH:mm:ss
    • If the sTime is not specified, 24hrs time period is considered
  • command (required)
Response:

Response contains a multiple types list of CS(Equity), OPT(Option), BND(Fixed Income), and FND(Mutual Fund). If there are more than 100 orders for the snapshot, a series of paginated response messages will be sent. Page width of each message will be 100.

{
"type": "trade",
"snapshot": [
{
"orderNumber": "xxxxxx",
"orderId": "xxxxxx",
"exchange": "xxxx",
"symbol": "xxxxxx",
"currency": "xxx",
"settleCurrency": "xxx",
"accountNumber": "xxxxxx",
"orderSide": "x",
"orderType": "x",
"averagePrice": x.x,
"orderQty": x.x,
"filledQty": x.x,
"orderValue": x.x,
"netOrderValue": x.x,
"orderNetSettle": x.x,
"filledOrderValue": x.x,
"commission": x.x,
"vat": x.x,
"cumulativeQty": x.x,
"cumulativeOrderValue": x.x,
"cumulativeOrderNetValue": x.x,
"cumulativeOrderNetSettle": x.x,
"cumulativeCommission": x.x,
"cumulativeVatAmount": x.x,
"createdDate": "yyyy/MM/dd-HH:mm:ss",
"rejectReason": "xxxxxx",
"orderStatus": "x",
"institutionCode": "xxxxxx",
"customerNumber": "xxxxxx",
"tif": "x",
"executionId": "xxxxxx",
"orderReferenceId": "xxxxxx"
},
{
"orderNumber": "xxxxxx",
"orderId": "xxxxxx",
"originalOrderId": "xxxxxx",
"accountNumber": "xxxxxx",
"customerNumber": "xxxxxx",
"orderStatus": "x",
"symbol": "xxxxxx",
"exchange": "xxxx",
"orderValue": x.x,
"currency": "xxx",
"settleCurrency": "xxx",
"createdDate": "yyyy/MM/dd-HH:mm:ss",
"orderSide": "x",
"lastUpdatedTime": "yyyy/MM/dd-HH:mm:ss",
"principal": x.x,
"price": x.x,
"tif": x,
"orderType": "x",
"expiryDate": "yyyy/MM/dd-HH:mm:ss",
"orderQty": x.x,
"accruedInterest": x.x,
"commission": x.x,
"orderReferenceId": "xxxxxx"
}
]
}

Heartbeat

After creating a web socket, the web socket client is required to send a heartbeat pulse (recommend ; 1 pulse/30 s) to the server. If a heartbeat message is not received within 1 min period, the server will close Websocket session.

The client application is required to send following message a heartbeat and the sever will respond to each with same message.

h

Responses

{
"orderNumber": "xxxxxx",
"orderId": "xxxxxx",
"originalOrderId": "xxxxxx",
"exchange": "xxxx",
"symbol": "xxxxxx",
"currency": "xxx",
"settleCurrency": "xxx",
"accountNumber": "xxxxxx",
"orderSide": "x",
"orderType": "x",
"averagePrice": x.x,
"orderQty": x.x,
"filledQty": x.x,
"orderValue": x.x,
"netOrderValue": x.x,
"orderNetSettle": x.x,
"filledOrderValue": x.x,
"commission": x.x,
"vat": x.x,
"cumulativeQty": x.x,
"cumulativeOrderValue": x.x,
"cumulativeOrderNetValue": x.x,
"cumulativeOrderNetSettle": x.x,
"cumulativeCommission": x.x,
"cumulativeVatAmount": x.x,
"createdDate": "yyyy/MM/dd-HH:mm:ss",
"rejectReason": "xxxxxx",
"orderStatus": "x",
"institutionCode": "xxxxxx",
"customerNumber": "xxxxxx",
"tif": "x",
"executionId": "xxxxxx",
"orderReferenceId": "xxxxxx"
}

Web Socket Client sample code

export class WebsocketService {

websocket: WebSocket | undefined;
public webSocketMessage: string[] = [];

constructor() { }

openWebSocketConnection(url:string){
this.websocket = new WebSocket(url);

this.websocket.onopen = (e)=>{
console.log(e);
}

this.websocket.onmessage = (e) =>{
console.log(e);
this.webSocketMessage.push(e.data);
}

this.websocket.onclose= (e)=>{
console.log(e);
}
}

sendWebSocketMessage(msg: string){
if(this.websocket!= undefined)
this.websocket.send(JSON.stringify(msg));
}

closeWebSocketConnection(){
if(this.websocket!= undefined)
this.websocket.close();
}

}
Is this page helpful for you?