Third-party packages in Python algorithms¶
When building Python-based cBots, indicators or plugins for cTrader, you may need to use third-party packages such as pandas
, numpy
or other libraries. This guide shows you how to declare such dependencies in a requirements.txt
file, which ensures your algorithm runs properly across environments.
File setup and rules¶
requirements.txt
is a plain text file used to specify external Python packages that a project needs. Your requirements.txt
file should follow these rules:
- The file must be named exactly
requirements.txt
- The file must be placed at the project root, alongside your Python entry file (for example,
Super cBot_main.py
). - The file should be included in the project files so that it is packaged with the algorithm.
Once the requirements.txt
file is present and properly formatted, simply build your project, and all listed dependencies will be added and resolved automatically. Here is an example:
...\Documents\cAlgo\Sources\Robots\Super cBot\Super cBot
1 2 |
|
Supported features¶
The requirements.txt
format follows the standard conventions used by pip
. The following examples demonstrate how to specify package versions using version specifiers, add comments and use blank lines for readability:
Pinning to an exact version¶
1 |
|
Allowing a minimum version¶
1 |
|
Using comments and blank lines¶
1 2 3 4 5 |
|
Best practices¶
- Pin critical libraries to avoid unexpected behaviour when new releases introduce breaking changes.
- If you use range specifiers for less critical packages, test your algo whenever the dependency updates.
- Consider writing meaningful comments to explain why certain packages were used or why specific versions were chosen.
- Rebuild your project every time you edit
requirements.txt
to ensure dependencies are installed correctly.