Configuration¶
There are two parts of configuration for the trader application: OS level environment variables, and TOML configuration file read by the trader application.
Environment variables¶
Environment variables are used to configure authentication to external resources, such as the trading database, broker access and more.
Authentication details should be kept separate from the rest of the execution code & configuration to have better protection as well as support dockerized executions.
Below is an example of a configuration variables script, which is not kept in the repository:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/bin/bash set -e # values can be either "polygon"/"alpaca"/"gemini"/"finnhub" export DATA_CONNECTOR="alpaca" # which broker to use? alpaca/gemini export LIU_BROKER="alpaca" # Polygon API key export POLYGON_API_KEY="" # Alpaca Credentials, note base URL needs to be changed # when switching to LIVE account export APCA_API_BASE_URL="https://paper-api.alpaca.markets" export ALPACA_STREAM_URL="wss://stream.data.alpaca.markets/v2/sip" export APCA_API_KEY_ID="" export APCA_API_SECRET_KEY="" # ALPACA market data subscription flag, note use "iex" for free and "sip" for PRO export ALPACA_DATA_FEED="iex" # Gemini export GEMINI_API_KEY= export GEMINI_API_SECRET= # lock number of CPUs & consumer processes to use export CPU_FACTOR=4 export NUM_CONSUMERS=4 # Where to look for tradeplan.toml export TRADEPLAN_DIR=. # Enable tracing, using OpenTelemetry, enabled = 1, disabled = 0 (DEFAULT) export LIU_TRACE_ENABLED=0 # Enable debugging, enabled = 1, disabled = 0 (DEFAULT) export LIU_DEBUG_ENABLED=1 |
Additional parameters¶
LiuAlgoTrader is a multi-processing framework with producer-consumers design pattern. There is a process for interacting with the data-stream providers (e.g Polygon.io), a process for scanning & picking stocks, and other processes specific to consumers.
The number of consumer processes depends on the number of CPU cores, load average and a multiplication factor. The default multiplication factor is 2.0 by default. However it is possible to override this by the environment variable CPU_FACTOR. If you notice that the load average of your system is quite low when running the trader application it’s recommended to increase the number (depending on the complexity of your strategies). If the load of the system is too high, it is recommended to lower the number.
It is also possible to by-pass LiuAlgoTrader calculation of optimal number of processes, and use a pre-defined number of consumer processes. To do so you can assign a positive integer to the environment variable NUM_CONSUMERS.
TRADEPLAN_DIR specifies the location of the tradeplan.toml configuration file. It’s used by both the trader and backtester applications.
TOML configuration file¶
the trader & backtester applications expect a TOML configuration file. Click here to learn more on the TOML file format.
By default the trader application will be looking for a configuration file with the name tradeplan.toml. The configuration file, as it’s name implies, defines the trade-plan for the trader execution: it defines which stock-scanners to use, and which algorithmic strategies to applied on the selected stocks.
Following is a sample of TOML configuration file. See Scanner and Strategies section respectively to learn more on the available tools, and how to extend them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # This is a TOML configuration file. # set max portfolio_value # portfolio_value = 25000.0 # set risk factor per trade # risk = 0.001 # how many minutes, before end of the trading day to enforce liqudation # market_liquidation_end_time_minutes = 15 # ticket scanners, may have several # scanners during the day [scanners] [scanners.momentum] # scan for tickers with minimal volume since day start min_volume = 30000 # minimum daily percentage gap min_gap = 3.5 # minimum last day dollar volume min_last_dv = 500000 max_share_price = 20.0 min_share_price = 2.0 # How many minutes from market open, to start running scanner from_market_open = 15 # recurrence = 5 # target_strategy_name = "MyStrategy" # trading strategies, can have several *strategy* blocks [strategies] # strategy class name, must implement Strategy class [strategies.MyStrategy] filename = "examples/my_strategy.py" # check_patterns = true # trading schedules block, trades many have # several windows within the same day [[strategies.MyStrategy.schedule]] duration = 150 start = 15 |