Skip to main content

A pandas interface for working with dxFeed data

Project description

dxFeed (pandas)

build-status PackageVersion PythonVersion Stable Format License

A package for loading dxFeed data in pandas.

Installation

The preferred installation of dxFeed is from pip:

pip install dxFeed

Windows

You'll need to install the Visual-Studio 17.0 tools for Windows installation. The Visual Studio Community package provides these tools for free.

Testing

To run the Python unit-test suite, run:

python -m unittest discover .

Usage

Basic usage function just like the pandas read_csv function with an additional positional parameter that describes the kind of dataset (see table below).

import dxFeed
df = dxFeed.read_csv('AAPL.csv', 'order-ntv')
Dataset Key Description
order-ntv Depth of book data from NTV
order-edgx Depth of book data from EDGX
tns Time and Sale data
tns-reg Time and Sale data (Reg)
quote-bbo CTA Quote data (BBO)
quote-reg CTA Quote data (Reg)

Flags

The package provides functionality to parse flags from the dxFeed data based on the documentation.

Order Flags

To parse order flags (NTV, EDGX data):

import dxFeed
df = dxFeed.read_csv('AAPL.csv', 'order-ntv')
df = df.flags.order.parse(df)

Event Flags

To parse event flags (NTV, EDGX data):

import dxFeed
df = dxFeed.read_csv('AAPL.csv', 'order-ntv')
df = df.flags.event.parse(df)

Time and Sale Flags

To parse time and sale flags (TNS data):

import dxFeed
df = dxFeed.read_csv('SPX.csv', 'tns')
df = df.flags.time_and_sale.parse(df)

Order Book Reconstruction

To reconstruct the order book using the dxFeed order book model, first load and parse appropriate flags:

import dxFeed
df = dxFeed.read_csv('AAPL.csv', 'order-ntv')
df = df.flags.order.parse(df)
df = df.flags.event.parse(df)

Next define the on_tick callback function that handles an immutable limit order book at each tick (i.e., event):

def on_tick(book: dxFeed.LimitOrderBook, event: object,
        adds_sell: int = 0,
        adds_buy: int = 0,
        trades_sell: int = 0,
        trades_buy: int = 0,
        trade_volume_sell: int = 0,
        trade_volume_buy: int = 0,
        cancels: int = 0
    ) -> None:
    """
    Handle a tick on the book.

    Args:
        book: the book from the order book model
        event: the event that was just handled
        adds_sell: the number of sell limit orders that were added
        adds_buy: the number of buy limit orders that were added
        trades_sell: the number of sell market trades that occurred
        trades_buy: the number of buy market trades that occurred
        trade_volume_sell: the volume of sell market trades that occurred
        trade_volume_buy: the volume of buy market trades that occurred
        cancels: the number of orders that were canceled

    Returns:
        None

    """
    print(book.best_buy(), book.best_sell())

To reconstruct the book, pass the dataset and on tick handler to an instance of OrderBookModel:

model = dxFeed.OrderBookModel()
model.reconstruct(df.itertuples(), on_tick)

Note: reconstruct expects an iterable set of events, so use itertuples to pass an iterator over the rows (i.e., events) in the data.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dxFeed, version 1.1.4
Filename, size File type Python version Upload date Hashes
Filename, size dxFeed-1.1.4.tar.gz (10.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page