Skip to content

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

Image title

1
2
pandas==2.2.2
numpy>=1.26.4

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
pandas==2.2.2

Allowing a minimum version

1
numpy>=1.26.4

Using comments and blank lines

1
2
3
4
5
# Data science libraries
pandas==2.2.2
numpy>=1.26.4

# You can leave blank lines for readability

Best practices

  1. Pin critical libraries to avoid unexpected behaviour when new releases introduce breaking changes.
  2. If you use range specifiers for less critical packages, test your algo whenever the dependency updates.
  3. Consider writing meaningful comments to explain why certain packages were used or why specific versions were chosen.
  4. Rebuild your project every time you edit requirements.txt to ensure dependencies are installed correctly.