Set the Python interpreter used by the Python strategy program
Strategies written in Python, when backtesting or live trading, if the docker system environment has bothPython2 and Python3 installed, you can set the Python version to be launched at runtime on the first line of the strategy, such as #!python3
and #!python2
, so that the system will find the interpreter automatically. And you can also specify an absolute path, such as: #!/usr/bin/python3
.
Python-based Strategy Security
When trading strategies are developed on FMZ Quant Trading Platform, the strategy contents are only visible to the FMZ account holders. And on the FMZ Quant Trading Platform, you can achieve complete localization of strategy code. For example, a strategy logic can be encapsulated into a Python package, which is loaded in the strategy code, so that the strategy content localization can be realized.
The security of Python code:
Because Python is an open-source language that is extremely easy to decompile, if the strategy is not for personal use but for rent, you can run the strategy on your own deployed docker and rent it out in the form of sub-account or full docker management if you are worried about strategy leakage.
The encryption of Python strategy code:
By default, Python strategy code is not encrypted when used by the author and encrypted when rented to others. By editing the following code at the beginning of the Python strategy, you can specify whether to encrypt the strategy code for personal use or rental. The Python versions that support the encryption of strategy codes are as follows: Python 2.7, Python 3.5 and Python 3.6.
When the strategy author runs it himself or uses it for others through a registration code, the strategy code is encrypted:
Specify #!python
as the version of Python interpreter, and then use ,
to keep apart; input the encryption command encrypt
. If you don’t specify the version of Python, you can add #!,encrypt
directly.
#!python,encrypt
Or
#!encrypt
It will not encrypt the strategy codes when strategy writers run for their own use and share with others through the registration code:
#!python,not encrypted
Or
#!not encrypted
Use code os.getenv('__FMZ_ENV__')
to determine whether the encryption code is valid; the return of the string "encrypt"
indicates that it has taken effect. It is only valid in the live trading, and the backtest will not encrypt the Python
strategy codes.
#!encrypt
def main():
ret = os.getenv('__FMZ_ENV__')
# If the print variable ret is the string "encrypt" or ret == "encrypt" is true, that means the encryption is valid.
Log(ret, ret == "encrypt")