Get stock prices using REST with ADS

Gurpreet Bal
Platform Application Developer Platform Application Developer

Refinitiv Real-Time Advanced Distribution Server (ADS) version 3.5.0 and greater introduced the REST snapshot server to enable the client applications to retrieve snapshots of market data (Quote) over the internet through the HTTP/REST interface. The responses provided by the REST interface follow the same Refinitiv Simplified JSON protocol which is also used with the WebSocket API. While Websocket interface of ADS allows an application to open a streaming connection, the REST service offers the advantage of simplified application without the overhead of the session management. Almost all application programming languages offer some library for making REST API calls.

The REST interface had existed in Refinitiv Real-Time Distribution System for a while now; but it was mainly geared towards component manageability and monitoring capabilities. With the addition of Snapshot service, it opens the interface up to the releam of the applications.

This article will discuss the ADS Snapshot interface briefly. For details regarding ADS Configuration Management, Shared Memory Resources or Item Database over the REST interface, please refer to the ADS installation guide. For more information on the streaming Websocket connection, please visit Refinitiv Developers Forum.

REST Syntax

The snapshots of market data can be retrieved through new /snapshot URI on the ADS. Currently only the level 1 MarketPrice domain data is supported. The basic syntax of a REST endpoint is:

    	
            http<s>://ads-server:<port>/snapshot
        
        
    

where
ads-server: is the hostname or IP address of the ADS server on your local network
port: is the the port number, if the default port of 80 or 443 is not used
https: Using https protocol requires that you provide a server certificate to ADS

The additional parameters can be provided either in the HTTP GET or POST as shown:

    	
            

GET|POST http://ads-server/snapshot

{

    "items" : ["itemName 1", "itemName 2", "itemName n"],

    "view" : ["BID", "ASK", "BIDSIZE"],

    "service" : "serviceName",

    "qos" : "delayed",

    "worstQos" : "delayed",

    "userName" : "userA",

    "position" : "192.168.0.1",

    "appId" : 256

}

Following example will get all the fields for Microsoft on NASDAQ in a JSON format:

    	
            http://ads-server/snapshot/MSFT.O
        
        
    

Response JSON to above request:

    	
            

[{

    "ID": 2,

    "Type": "Refresh",

    "Key": {

      "Service": "IDN_SELECTFEED",

      "Name": "MSFT.O"

    },

    "State": {

      "Stream": "NonStreaming",

      "Data": "Ok",

      "Text": "All is well"

    },

    "Qos": {

      "Timeliness": "Realtime",

      "Rate": "TickByTick"

    },

    "PermData": "AwAXdMA=",

    "SeqNumber": 10928,

    "Fields": {

      "PROD_PERM": 74,

      "RDNDISPLAY": 66,

      "DSPLY_NAME": "MICROSOFT CP",

      "RDN_EXCHID": "   ",

      "TRDPRC_1": 309.203300,

      "TRDPRC_2": 309.20,

      "TRDPRC_3": 309.19,

      "TRDPRC_4": 309.18,

      "TRDPRC_5": 309.17,

      "NETCHNG_1": -1.556700,

      "HIGH_1": 311.09,

      "LOW_1": 307.80,

      "PRCTCK_1": "⇧",

      "CURRENCY": "USD",

      "TRADE_DATE": "2021-10-22",

      "TRDTIM_1": "16:39:00",

      "OPEN_PRC": 310.40,

      "HST_CLOSE": 310.760000,

      "BID": 309.19,

      "BID_1": 309.19,

      "BID_2": 309.19,

      "ASK": 309.21,

      "ASK_1": 309.21,

      "ASK_2": 309.21,

      .

      .

      "ELG_ACVOL": 6021427,

      "ELG_TNOV": 1862651244.6313,

      "ODDTRN_UNS": 825419176.0523,

      "TRNOVR_UNS": 2774479348.917652,

      "ACVOL_UNS": 8969220

    }

  }

]

Login and Entitlements

All the requests serviced through the REST snapshot interface are subject to the Data Access Control System (DACS) permissions. If DACS is enabled on the ADS server, the REST snapshot client applications must supply the username, position and application Id information in the HTTP request message.

Example GET:

    	
            http://ads-server/snapshot/MSFT.O?userName=user1&position=192.168.0.1&appId=256
        
        
    

or POST

    	
            

http://ads-server/snapshot

{

    "items" : ["MSFT.O"],

    "userName" : "user1",

    "position" : "192.168.0.1",

    "appId" : 256

}

Additional Examples:

Limit the number of fields in the response JSON message by specifying a view parameter. Note that both field names or FIDs are accepted in the view:

    	
            http://ads-server/snapshot/MSFT.O?view=BID,ASK,BIDSIZE
http://ads-server/snapshot/MSFT.O?view=22,25

Response from ADS:

    	
            

[{

    "ID": 2,

    "Type": "Refresh",

    "Key": {

      "Service": "IDN_SELECTFEED",

      "Name": "MSFT.O"

    },

    "State": {

      "Stream": "NonStreaming",

      "Data": "Ok",

      "Text": "All is well"

    },

    "Qos": {

      "Timeliness": "Realtime",

      "Rate": "TickByTick"

    },

    "PermData": "AwAXdMA=",

    "SeqNumber": 48288,

    "Fields": {

      "TRDPRC_1": 307.31,

      "BID": 307.29,

      "ASK": 307.32

    }

  }

]

Request data for a batch of instruments:

    	
            

http://torsrmds15:8070/snapshot?items=MSFT.O,INVALID.N,GE.N&view=BID,ASK,TRDPRC_1

or

http://ads-server/snapshot

{

    "items" : ["MSFT.O", "INVALID.N", "GE.N"],

    "view": ["BID", "ASK", "TRDPRC_1"]

}

The response JSON from ADS contains an array with data for each of the requested instruments. The invalid instrument will contain the status message stating the reason:

    	
            

[{

    "ID": 5,

    "Type": "Refresh",

    "Key": {

      "Service": "IDN_SELECTFEED",

      "Name": "GE.N"

    },

    "State": {

      "Stream": "NonStreaming",

      "Data": "Ok",

      "Text": "All is well"

    },

    "Qos": {

      "Timeliness": "Realtime",

      "Rate": "TickByTick"

    },

    "PermData": "AwAXYsA=",

    "SeqNumber": 64864,

    "Fields": {

      "TRDPRC_1": 104.960000,

      "BID": 104.950000,

      "ASK": 104.990000

    }

  }, {

    "ID": 3,

    "Type": "Refresh",

    "Key": {

      "Service": "IDN_SELECTFEED",

      "Name": "MSFT.O"

    },

    "State": {

      "Stream": "NonStreaming",

      "Data": "Ok",

      "Text": "All is well"

    },

    "Qos": {

      "Timeliness": "Realtime",

      "Rate": "TickByTick"

    },

    "PermData": "AwAXdMA=",

    "SeqNumber": 17488,

    "Fields": {

      "TRDPRC_1": 307.97,

      "BID": 307.96,

      "ASK": 307.99

    }

  }, {

    "ID": 4,

    "Type": "Status",

    "Key": {

      "Service": "IDN_SELECTFEED",

      "Name": "INVALID.N"

    },

    "State": {

      "Stream": "Closed",

      "Data": "Suspect",

      "Code": "NotFound",

      "Text": "The record could not be found"

    }

  }

]

Specify a service name for the snapshot request. If the service name is not specified, the request will be made to the default snapshot service configured in ADS:

    	
            http://ads-server/snapshot/MSFT.O?service=ELEKTRON_DD
        
        
    

If a service name does not exist on the ADS, an invalid service error message will be returned

    	
            

{

  "Error": "The service specified in the URI is not currently available."

}

Specify the desired quality of service timeliness (real time or delayed):

    	
            http://ads-server/snapshot/MSFT.O?qos=realtime|delayed
        
        
    

Specify the worst acceptable quality of service (real time or delayed). Notice the use of a service group name in the parameter service:

    	
            

http://ads-server/snapshot/MSFT.O?service=SVCGROUP&qos=realtime|delayed&worstQos=realtime|delayed

or

http://ads-server/snapshot/

{

    "items" : ["MSFT.O"],

    "service" : "SVCGROUP",

    "qos" : "realtime",

    "worstQos" : "delayed"

}

Security Key

REST interface provides the security key mechanism for authorization. When the security key is enforced, client applications must supply the security key in the HTTP requests. If an HTTP request does not supply the security key or contains an incorrect security key value, the HTTP request is denied. The security key is a secret that the administrators of Refinitiv Real-Time Distribution System infrastructure know. Different values of the security key can be associated to different REST resource families for each supported HTTP method.

The security key can be passed to ADS as a regular parameter securityKey in the GET or POST command as shown:

    	
            

POST http://torsrmds15:8070/snapshot

{

  "securityKey": "dqUjtRFc^8dfRlkvs_3FuJp",

  "items": ["MSFT.O", GE.N"],

}

ADS configuration

Following configuration can be specified in the ADS to enable Market Price snapshots on the REST interface:

    	
            

!

! REST Parameters

!

*ads*enableRest : True

*ads*enableRestAudit : False

*ads*rest*HTTPResponseHeaders : X-Frame-Options: deny, X-XSS-Protection: 1; mode=block, X-Content-Type-Options: nosniff, Access-Control-Allow-Origin: *

*ads*rest*allowedIPAddressList : *

*ads*rest*defaultSnapshotService : IDN_SELECTFEED

*ads*rest*defaultSnapshotUserName : RestSnapshot

*ads*rest*enableManageabilityResources : True

*ads*rest*enableSnapshotServer : True

*ads*rest*restRequestTimeout : 60

*ads*rest*securityKey : 

 

*ads*restAudit*file : /logs/ads/ads.rest.log

*ads*restAudit*max_bytes : 3000000

*ads*restAudit*max_swapfiles : 0

*ads*restAudit*microSecTimeStamps : False

*ads*restAudit*timeStampFormat : %a %b %d  %H:%M:%S %Y

*ads*restPort : 8070

*ads*restThread*bindRestThread : 

 

*ads*8070*cipherSuite : 

*ads*8070*clientToServerPings : True

*ads*8070*compressionType : 0

*ads*8070*connectionType : 0

*ads*8070*dhParams : 

*ads*8070*flushInterval : 1

*ads*8070*interfaceName : 

*ads*8070*maxMounts : 256

*ads*8070*minCompressionThreshold : 0

*ads*8070*minPingTimeout : 6

*ads*8070*pingTimeout : 30

*ads*8070*poolSize : 16000

*ads*8070*serverCert : 

*ads*8070*serverPrivateKey : 

*ads*8070*serverToClientPings : True

*ads*8070*tcpRecvBufSize : 64240

*ads*8070*tcpSendBufSize : 64240

*ads*8070*timedWrites : True

*ads*8070*zlibCompressionLevel : 3

Downloads

Sample Webpage