AlgoTraderAlgoTrader Documentation

Appendix L. Example Strategy "Market Maker"

One can express their vision how market would behave in the nearest future. Having this in mind bid/ask price could be defined in the way that buying and selling at this price would be profitable. This example shows how market making strategy could be implemented. The key difference with other strategies is that market maker always ready to buy and sell instrument, thus providing liquidity to the market.

The main purpose of this strategy is to show how to use historical market data, live market data and do simple order management. The strategy calculates moving average price for USDBTC (using coinApi Pro historical data and coinbase Pro for live market data) and calculates mid price. The strategy uses assumption that current market mid price would reverse to the mean value (moving average in this example). During trading some position can accumulate, in such a case the strategy would place a hedge order which would square the position. Some statically configured spread will apply, also there is a threshold based on which current open orders would be adjusted (i.e. replaced according to the current market conditions).

The main artifacts needed for the implementation of a new strategy are described in Chapter 4, Strategy Development.

The market making strategy consist of the following main artifacts:

/src/main/java/ch/algotrader/strategy/marketmaker/MarketmakerService.java

The strategy service class providing the main methods invoked by the application on certain events.

/src/main/java/ch/algotrader/strategy/marketmaker/algo/Metrics.java

The metrics class is responsible for calculating order parameters (i.e. buy/sell/hedge) according to the current market conditions.

/conf/settings.csv

Config where the following parameters are specified:

securityDescription - security to trade,

maxUnits - max amount strategy can trade on each side for market making orders,

repricingThreshold - threshold after which orders will be resubmitted with updated prices - it prevents resubmitting orders with small price changes.

/src/main/resources/db/mysql/mysql-data.sql

Contains the MySQL database records. Needs to be imported into the database before running the strategy with the MySQL database.

To setup the strategy for back testing and live trading on a development workstation please execute the following steps:

Download the Example Strategies

If you have used the Section 2.1, “Windows Installer” to setup AlgoTrader, this project is already setup in the AlgoTrader IntelliJ IDEA and you can skip this step.

Download the Examples project zip file and unpack it in a directory of your choosing: https://www.algotrader.com/downloads/latest-examples

Note

user name and password will be provided when signing up for an AlgoTrader license

If you need an older AlgoTrader version, login to our maven repository (https://repo.algotrader.com/nexus) and click on Browse on the left and select code-general.

Then select the AlgoTrader version you want and download:

Import/open the project marketmaker

To start the strategy in live trading mode on a development workstation please execute the following steps:

Initialize the database

load the db-samples script into the MySQL database: /algotrader-conf/src/main/resources/db-samples/mysql/mysql-data.sql

load the strategy specific script into the MySQL database: /marketmaker/src/main/resources/db/mysql/mysql-data.sql

To start the Strategy please see the explanations in Chapter 3, Starting AlgoTrader. Please note: first reference data should be loaded. The following run configurations should be used:

Coinbase (sandbox) Reference Data

/runConfigurations/ReferenceDataStarter-Coinbase-sandbox.run.xml

Coin API refence data

/runConfigurations/ReferenceDataStarter-CoinAPI.run.xml

Strategy

/runConfigurations/EmbeddedStrategyStarter-marketmaker.run.xml