Wolfinch: Introduction to the friendly trading bot

Joshith Rayaroth Koderi
7 min readJul 9, 2020

--

Algorithmic trading systems are quickly outpacing traditional traders in all sorts of equity and cryptocurrency markets. Nowadays a good chunk of the daily trading volume is controlled by the algorithmic trading platforms across all the exchanges. However, retail traders exposure to algorithmic trading is still very limited because of the lack of good algorithmic trading platforms available to them.

Wolfinch is an open source algorithmic trading platform written in Python. It can ingest market data and perform trading actions in real time based on a trading strategy. It supports automated trading on both equity markets and cryptocurrency exchanges. Wolfinch supports number of major cryptocurrency exchanges and equity brokers for trading and provides multiple trading strategies out of the box.

The platform is very flexible and easily extensible so that creating new strategies and adding support for more brokers and exchanges are easily achievable.

Let’s see how can we put Wolfinch to work and explore some of the features while at it.

Wolfinch workflow

We will start by looking at a typical workflow for creating a live algorithmic trading setup with Wolfinch. The steps here will become more clear in the subsequent sections. As you get more comfortable using Wolfinch, you can streamline the workflow and focus on creating your own strategies.

  1. Download and install Wolfinch
  2. Identify and setup the exchange/broker you want to trade with
  3. Identify the products/symbols you want to trade and setup the fund limits for trade
  4. Identify and configure strategy you want to use for trading. You can pick an existing TA or AI/ML strategy or create your own strategy
  5. Import and setup historic candlestick data with Wolfinch for the trading pairs you have identified
  6. Perform backtesting with historic data using strategy and observe and understand strength/weakness of strategy or config
  7. Tweak and tune strategy based on backtesting observations. Wolfinch’s Genetic backtesting can be used here to find the best parameters for a strategy
  8. Reconfigure the strategy with the optimized parameters
  9. Enable simulated(paper) trading mode with realtime data and observe trading with realtime data
  10. go live! Sit back and relax while Wolfinch does the work for you!

Now that we have seen a high level workflow for setting up live trading session, let’s dive in to a little more details on installing and setting up various features.

Starting up with Wolfinch

Starting up with Wolfinch is pretty straight forward. Wolfinch is an open source project hosted in github. So the first step is to clone the project.

git clone https://github.com/ldmonko/wolfinch.git

Before we are able to run Wolfinch, we should resolve the python module dependencies.

First, install the core dependencies

pip3 install -r requirement.txt

Next, install the dependencies specific to the exchange/broker you are interested in.

pip3 install -r exchanges/<exchange-name>/requirement.txt

Once the dependencies are resolved, let’s configure Wolfinch for our use. This is where we configure the exchange/broker for trading and the strategies we want to use.

Wolfinch configuration files are in a very intuitive YAML format. Many sample configuration files are available and should serve as a starting point. More in to configuration is on the next section.

Now that the dependencies are resolved and configuration is complete, it is time to let the real fun begin. Starting the Wolfinch bot is a simple command line.

python3 Wolfinch.py --config config/<config.yml>

The bot will complete setup and start running in a short while. There is a simple integrated UI available out of the box. Bot activity can be monitored and many simple interactions can be done using the UI. UI can be enabled with the configuration file.

Decision and trading strategies

The brain of an algorithmic trading bot is the strategy it uses for the trading decisions. There can be various different kind of trading strategies ranging from simple ‘buy in the morning, sell before close’ to complex technical analysis (TA) and sentiment based strategies and AI/ML strategies.

Wolfinch supports pluggable decision engines and strategies. While it provides number of TA and AI/ML based strategies out of the box, the real potential of the bot is in its flexibility to create and fine tune custom strategies.

New strategies can be implemented by extending the strategy base class and implementing required methods. A TA based strategy can utilize various technical indicators for the underlying symbol for a trade decision. A strategy can also access indicators for other symbols/markets as well. This is useful if the strategy wants to analyze the movement on multiple indices/symbols or for creating arbitrage strategies.

All the available strategies are in the strategy/’ directory under the project home. Any of the existing strategies can serve as a good starting point for understanding and implementing new strategies for Wolfinch.

Practical trading strategies generally includes ‘stop-loss’ and ‘take-profit’ setups as well. Wolfinch supports multiple different kinds of ‘stop-loss’ and ‘take-profit’ configurations, including- simple percentage, trailing, ATR and strategy based setups.

Exchanges

Trading bots require an underlying exchange or a broker for performing the actual trades. This is also where various real time data and order-flows are fetched. Wolfinch supports a pluggable exchange implementation model. The details on how the orders are placed and how various data is retrieved are left to the exchange module implementation.

More than one exchanges and products can be configured at the same time and can work in both active and passive trading modes. This is particularly useful for using arbitrage strategies or convergence/divergence based strategies.

Wolfinch supports multiple cryptocurrency exchanges out of the box. Robinhood is supported for regular equity trading at the moment. List of currently supported exchanges are the following.

  • Binance — More details on using Wolfinch with Binance is here
  • BinanceUS
  • Coinbase Pro
  • Robinhood — More details on using Wolfinch with Robinhood is here

Adding support for more exchanges are possible by extending the exchange base class provided. The exchange class implementation should implement the basic functions that should be supported on an exchange/broker.

Backtesting, Simulation, Pre-roll

For any algorithmic trading platform, two important features are the ability to backtest the strategies with historic data and the ability to simulate the trades with real time data (a.k.a paper trading). Wolfinch supports both simulation and the backtesting modes of operation. The configurations are simple flip of a switch enable/disable modes in the config file. Pre-roll feature allows the user to backfill the historic data for a specified amount of time with a specified interval.

Genetic Optimizer

Those who familiar with TA and algorithmic trading strategies know that there can be numerous parameters affecting a trading strategy. Tuning these parameters are the real challenge in an efficient algorithmic trading strategy. The parameters are often very dependent on the underlying product/symbol and market conditions. A parameter set for one product/symbol is hardly suited for another. Usually traders use their experience and experiment with various combinations for finding optimal parameters.
This is where the Genetic Optimizer provided by the Wolfinch comes in handy, it helps tune the parameters automatically using the Genetic Algorithms.

GA in itself is a vast topic and how it is done is outside our scope here. However for those interested, there are great deal of literature available online but here is a starting point — https://towardsdatascience.com/introduction-to-genetic-algorithms-including-example-code-e396e98d8bf3

Integrated UI

Wolfinch comes with an embedded UI. The embedded UI is simple but good enough for the regular monitoring and life cycle events while the bot is running. It provides a candlestick chart overlaid by the indicators used in the strategy, a trade history page, a simple bot-control page where manual trades and other actions can be performed.

Optional security features are available for UI. The UI reachability and bot control can be secured with passcodes. UI security can be enabled using ui_code_gen.py script.

By default, UI can be accessed with the following link — http://127.0.0.1:8080/wolfinch

Configuring wolfinch

Wolfinch is a powerful and feature rich trading bot. There are tons of nuts and bolts available to configure the bot and fine tune various features and strategies. Thanks to the YAML based configuration file, configuring Wolfinch is very intuitive yet powerful enough to unleash the full potential of the bot.

Here is a sample configuration file-

The configuration file has multiple sections -

  • Exchange configuration: Exchange/broker related config goes here. The products/tickers we are planning to trade on the exchange are also configured here along with their limits and finer details like exchange fees etc. The exchange configuration also takes an additional exchange-config file. This file is specific to the exchange and contents are defined by the exchange module. Generally, sensitive data related to exchanges — passwords, private keys are configured in the exchange-config file.
  • Decision and trading configuration: Wolfinch allows pluggable decision engines. Examples are simple technical analysis (TA) based strategies and AI/ML based decision engines. Other trading parameters like stop loss, take profit and their strategies are also configured here.
    Trading configuration can be done at a global level as well as at a market/exchange level. This allows different strategy and parameters to be configured for different products and exchanges. More on trading strategies in the strategies section.
  • Simulation/Backtesting/pre-roll: Configuration flags to enable/disable simulation and backtesting modes of operation. Pre-roll configuration allows to setup the number of days of historical data required along with the candle interval.
  • Genetic optimizer: Genetic optimizer configuration allows configuring size of population, number of generations and the number of parallel threads. The enable/disable flag specifies whether the genetic optimizer is enabled or disabled.
  • Embedded UI: UI configuration is simple with a simple enable/disable switch. The port can be configured as well. Default port configured is 8080.

Closing notes

The world is moving fast towards automation in every walk of life. If you are a swing trader or a day trader and you a have logic or a method to identify a potential trade, this can be automated as well. Wolfinch provides a powerful platform and tools to setup a trading strategy and automate your trading while you can focus on more interesting things in life.
Happy trading!

--

--