Skip to content

Fbraga/high_frequency_trading

 
 

Repository files navigation

This repo contains an oTree application customized for conducting real-time financial market experiments. Originally started as an attempt to build an pure oTree implementation of [AldrichVargas], it now generalizes over many small-scale financial market environments. It serves as an experiment software layer for a system with remote exchanges and traders (subjects). Each oTree subsession includes a trading day webpage, where subjects participate in a market by interacting with the components on the user interface. Naturally, this is oriented towards experimental environments with algorithmic and high frequency trading.

Setting Up

Redis is used as the primary data storage during a trade session for quick read/writes, and experiment data is written to the Postgres in background. We use Huey for this purpose. Both Redis and Huey is already required for oTree. The interface server is used to connect to remote exchanges.

To run a test:

1. Create a virtual environment, you will install a slightly modified version of oTree in this new environment. A virtual environment will keep this version separate from the oTree version you are already using.

mkdir otree_hft_env
virtualenv -p python3.6 otree_hft_env

For mac and linux:

source otree_hft_env/bin/activate

For windows:

otree_hft_env/Scripts/activate
  1. Clone this repository and install dependencies.
cd high_frequency_trading
pip install -r requirements.txt

3. For convenience the repository includes matching engine libraries as subrepo. Some modules are used by both the exchange server and application. Both applications decode/encode OUCH messages to talk with each other.

cd exchange_server
git submodule init
git submodule update

Follow the exchange server instructions and run a CDA exchange instance.

4. Postgres DB and Redis must be running and oTree must be configured to talk with both; explained in oTree docs . Also run:

otree resetdb
otree collectstatic
  1. In a separate shell start the background process.
otree run_huey
  1. Finally, run oTree in another shell.
otree runhftserver

In production, you should run each as a service. The method above is only intended for testing.

[AldrichVargas]https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3154070

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 63.5%
  • Python 20.9%
  • HTML 6.8%
  • JavaScript 6.7%
  • C++ 1.7%
  • CSS 0.3%
  • Other 0.1%