Workspace Blended Order Book data stream

Hi, I am working on a monitoring tool for SAFEX contracts. I'm trying to pull the blended order book and log the transactions per broker in excel. I'm stuck on the data stream though, I cant find a way to get the data to pull the data from the "BY order" tab seen in Refinitiv Workspace, it keeps pulling from the first tab "best only". Thus, the broker names don't get pulled. They appear in the format of "JSE:broker code". See the screenshot below what i mean by the tabs.


The specific function in the script I have is in the stream, which is seen here:

def setup_stream(contract_code: str, retries: int = 3) -> None:

"""Set up market data stream with BY ORDER view configuration"""

for attempt in range(retries):

try:

# Create fields list for BY ORDER view

fields = [

# Core fields

"OPEN_PRC", "ACVOL_1",


# Venue columns

"VENUE.BID.0.ID", "VENUE.ASK.0.ID", # First row venue

"VENUE.BID.CNT", "VENUE.ASK.CNT", # Count

"VENUE.BID.ACC", "VENUE.ASK.ACC", # AccSize

"VENUE.BID.SZ", "VENUE.ASK.SZ", # Size

"VENUE.BID.PRC", "VENUE.ASK.PRC", # Bid/Ask prices


# Try additional market depth fields

"MARKET_DEPTH",

"ORDER_DEPTH",

"BOOK_DEPTH",


# Row fields

*[f"DEPTH_{i}" for i in range(50)],


# State fields

"VIEW", # Current view

"MODE", # Display mode

"STATE" # Order book state

]

# Set up stream with view configuration

pricing_stream = pricing.Definition(

universe=[f"{contract_code}:BOB", contract_code], # Try BOB suffix

fields=fields,

domain="MARKET_PRICE" # Specify market price domain

).get_stream()

def on_refresh(fields, instrument_name, stream):

logging.info(f"\n{'='*80}")

logging.info(f"REFRESH {instrument_name} - BY ORDER View:")

logging.info(f"{'='*80}")


# Log all fields for debugging

for key, value in sorted(fields.items()):

if value is not None:

logging.info(f"{key:30} | {str(value):>20} | Type: {type(value).__name__}")


process_data(fields, contract_code)

def on_update(fields, instrument_name, stream):

logging.info(f"\n{'-'*80}")

logging.info(f"UPDATE {instrument_name} - BY ORDER View:")

logging.info(f"{'-'*80}")


# Log all changes

for key, value in sorted(fields.items()):

if value is not None:

logging.info(f"{key:30} | {str(value):>20} | Type: {type(value).__name__}")


process_data(fields, contract_code)

pricing_stream.on_refresh(on_refresh)

pricing_stream.on_update(on_update)


# Try to set view before opening stream

pricing_stream.set_attribute("VIEW", "BY_ORDER")


pricing_stream.open()

logging.info(f"Stream opened for {contract_code} with BY ORDER view")

return

except Exception as e:

logging.error(f"Error setting up stream for {contract_code}, attempt {attempt + 1}: {e}")

if attempt < retries - 1:

time_module.sleep(2)

else:

logging.error(f"Failed to set up stream for {contract_code} after {retries} attempts.")


I have attempted multiple ways of getting the stream to open the right tab to no avail. I have attached the full script for reference.

Any assistance will be greatly appreciated.


Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @peter.jackson

    Thank you for reaching out to us.

    I found that the application adds the ":BOB" behind the contract code and subscribes to the fields that are in the Real-Time Dictionary, such as VENUE.BID.0.ID. Does this code work?

    pricing_stream = pricing.Definition(
                    universe=[f"{contract_code}:BOB", contract_code],  # Try BOB suffix
                    fields=fields,
                    domain="MARKET_PRICE"  # Specify market price domain
                ).get_stream()

    # Venue columns

    "VENUE.BID.0.ID", "VENUE.ASK.0.ID", # First row venue

    "VENUE.BID.CNT", "VENUE.ASK.CNT", # Count

    "VENUE.BID.ACC", "VENUE.ASK.ACC", # AccSize

    "VENUE.BID.SZ", "VENUE.ASK.SZ", # Size

    "VENUE.BID.PRC", "VENUE.ASK.PRC", # Bid/Ask prices



    # Try additional market depth fields

    "MARKET_DEPTH",

    "ORDER_DEPTH",

    "BOOK_DEPTH",


    The "MarketPrice" domain only provides the Level I market information such as trades, indicative quotes, and top-of-book quotes.

    To retrieve Level II market by order data, you need to subscribe to the MarketByOrder domain. Please see the Level II subscription in GitHub.