Skip to content

Latest commit

 

History

History

README.md

Python Examples

Example Code Disclaimer: ALL EXAMPLE CODE IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS FOR ILLUSTRATIVE PURPOSES ONLY. LSEG MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, AS TO THE OPERATION OF EXAMPLE CODE, OR THE INFORMATION, CONTENT OR MATERIALS USED IN CONNECTION WITH EXAMPLE CODE. YOU EXPRESSLY AGREE THAT YOUR USE OF EXAMPLE CODE IS AT YOUR SOLE RISK

Summary

The purpose of these examples is to show retrieving JSON-formatted market content from a WebSocket server. The examples are as follows:

  • market_price: Retrieves market-price content for TRI.N.
  • market_price_batch_view: Retrieves market-price content for TRI.N, IBM.N, and T.N, using a batch request. It also specifies a view that requests content only for fields BID, ASK, and BIDSIZE.
  • market_price_authentication: Retrieves market-price content for TRI.N, after authenticating with an authentication server.
  • market_price_posting: Retrieves market-price content for TRI.N, and posts market-price content back to it.
  • market_price_ping: Retrieves market-price content for TRI.N, and monitors connection health by sending ping messages.

market_price forms the basis of the other examples, which implement additional features. To see the code specific to each feature, a diff tool can be used to compare the market_price source file with that of the appropriate example.

These applications are intended as basic usage examples. Some of the design choices were made to favor simplicity and readability over performance. This application is not intended to be used for measuring performance.

NOTE: The posting example must be run with Python3.0 or greater. The other examples may be run with Python2.7 or greater.

Command Line Usage

python market_price.py [--hostname hostname] [--port port] [--app_id appID] [--user user] [--snapshot]

python market_price_batch_view.py [--hostname hostname ] [--port port] [--app_id appID] [--user user]

python market_price_authentication.py [--hostname hostname ] [--port port] [--app_id appID] [--user user] [--password password] [--auth_port port]

python market_price_posting.py [--hostname hostname ] [--port port] [--app_id appID] [--user user]

Pressing the CTRL+C buttons terminates any example.

Compiling Source

Windows/Linux/macOS

  1. Install Python
    • Go to: https://www.python.org/downloads/
    • Select the Download tile for the Python 3 version
    • Run the downloaded python-<version> file and follow installation instructions
  2. Install libraries
    • Run (in order):
      • pip install requests
      • pip install websockets The websocket-client must be version 0.48
      • (Only for Python versions less than 3.3) pip install ipaddress
  3. Run examples
    • cd to streamingtools/Applications/Examples/python
    • To run market_price.py with options:
      • python market_price.py --hostname <hostname>

Source File Description

  • market_price.py - Source file for the market_price example.

  • market_price_batch_view.py - Source file for the market_price_batch_view example.

  • market_price_authentication.py - Source file for the market_price_authentication example.

  • market_price_posting.py - Source file for the market_price example.

  • market_price_ping.py - Source file for the market_price_ping example.

Websockets Library Information

By default, this application uses the Websockets library to initiate websocket connections. It may use environment variables to alter its connection, such as http_proxy and https_proxy. See details about the websockets library here: https://pypi.org/project/websockets/

Versions Used In Test

  • Python 3.13.1