Files
spark/src/lib_python_md

lib_python_md

This library binds c++ market data providers to python modules which can be loaded at runtime.

Dependencies

Notes

  • Because this is python, market data enums (SecurityType, Venue, Side, etc.) are represented as strings
    • Parsing is NOT case sensitive (though it is conventional to use UPPER_CASE strings)
    • Type name prefixes (SECURITY_TYPE_, VENUE_, SIDE_ etc.) are NOT required
    • Having said that, we recommend UPPER_CASE strings without the type prefix. Here are a few examples:
      • SECURITY_TYPE
        • "SPOT"
        • "FUTURE"
        • "OPTION"
        • etc.
      • VENUE:
        • "BYBIT"
        • "GATEIO"
        • "DERIBIT"
        • "COINBASE"
        • etc.
      • SIDE, AGGRESSOR_SIDE:
        • "BUY"
        • "SELL"

Example

import time
import python_md_module as pymd


class MdProviderExample(pymd.MdProvider):
    def __init__(self):
        super(MdProviderExample, self).__init__()
        pass

    def start(self, sink: pymd.MdSink):
        print("Starting MdProviderExample")
        # An actual implementation would subscribe to market data here.
        # This is just an example to show you how to pass market data
        # back to the c++ Spark api.

        def add_dummy_security():
            # This example populates a dummy security for demonstrative purposes.
            # Of course, an actual implementation would populate the security list 
            # with data received from the exchange (or some other provider).
            sec = pymd.PySecurity()
            sec.set_venue("GLBX")
            sec.set_name("ESH8")
            sec.set_asset("ES")
            fut = pymd.PyFuture()
            fut.set_expiration("2025-03-28")
            sec.set_future(fut)
            # Note: the example only adds 1 sec, but batch adds are supported.
            sec_list = pymd.PySecurityList()
            sec_list.append(sec)
            sink.on_securities(sec_list)

        def add_dummy_trade():
            trade = pymd.PyTrade()
            trade.set_venue("GLBX")
            trade.set_security_type("FUTURE")
            trade.set_exchange_security_id("ESH8")
            trade.set_price(5684.25)
            trade.set_quantity(1)
            trade.set_aggressor_side("BUY")
            trade.set_timestamp(time.time_ns())

        add_dummy_security()
        add_dummy_trade()

    def stop(self):
        print("Stopping MdProviderExample")

Devs

Python files in python_md_providers/ (child dir of this dir) are copied to
the plugins directory at build time, and should automatically be loaded at runtime.