inst/pubsub/README.md

Pub/Sub Example with 'Live' Intra-Daily Market Data

What Is This?

This directory contains a pair of files to gather and display "live" (i.e. delayed by the usual amount as is common for non-subscribers to generally expensive live market data) futures data.

What Does It Look Like?

Here is a screenshot from a few months ago. The plotting logic and details have not changed. Displayed are two days worth of price snapshots every ten seconds.

Give Me More Details

One file uses package quantmod to gather the data. It collects the data points in Redis to build a history, but also publishes the on a channel by the name of the symbol.

The second file retrieves the recent history, and subscribes to the channel to receive updates which it displays as it gets them. Because it uses an R graphics device to plot (also via package quantmod) it is easiest to source() the file in an R session. (Rscript defaults to setting interactive to FALSE; otherwise R can be used with --interactive, or r from littler can be used with its -i switch).

The third file should be invoked weekly or daily from crontab and prunes the history down to just the last months. All three files could be generalized to read more than one symbol, or host, or ... from config files. For now, and for simplicity, just the front ES contract is monitored.

Going Further

The second set of files generalizes the approach to subscribe to a set of symbols---where we use a set of symbols from CME Globex, an electronic trading system with extended hours. Data for each symbols is cached, and published, in the 'to-Redis' file. The corresponding 'from-Redis' file consumes and plots the data, again using a single process to cover multiple symbols and subscriptions.

Acknowledgements

These files owes their basic structure to a gist by Josh Ulrich which also contained the basic subscription loop (and which is also the basis of this extended and documented version in package dang. This was then generalized to use a symbol such as ES=F (for the front month SP500 futures contract) for which no history is available by both caching in Redis and using pub/sub to distribute. The rredis package (installable from the ghrr drat repo) was used for the initial pub/sub approach. Bryan W. Lewis then ported and adapted the pub/sub model to this RcppRedis package.

Authors

Dirk Eddelbuettel, Joshua Ulrich, Bryan W. Lewis

License

GPL (>= 2)



Try the RcppRedis package in your browser

Any scripts or data that you put into this service are public.

RcppRedis documentation built on Aug. 19, 2023, 5:13 p.m.