Algo Registry¶
If you have a large portfolio of algos you are distributing to users, you may want to also offer a custom panel or system that allows these users easily manage your algos on their local machines. Such a system would be especially valuable if you offer several products that all complement each other (e.g., two cBots and a custom indicator that all need to be installed to function properly). If a user skips installing a required product, you will be able to alert them to this fact.
In addition, when a user has access to many algorithms, sometimes it can be difficult to keep track of all of them. For example, a user may accidentally delete a valuable algorithm only to later realise that they cannot operate with it anymore.
To help you and your users, the Algo API exposes the AlgoRegistry
interface, which offers a convenient means of dynamically tracking statistics about currently installed and uninstalled algos of different types.
Working With the Algo Registry¶
In the AlgoRegistry
, each algo is represented by an AlgoType
, which contains the unique name of the algorithm and its AlgoKind
(e.g., an AlgoKind.CustomIndicator
).
You can retrive a specific algorithm from the registry by calling the following method.
1 |
|
To retrieve a count of algorithms of a particular kind, call the following method.
1 |
|
You can also add custom handlers to the following events.
AlgoTypeInstalled
, which is triggered every time a new algo is installed.AlgoTypeDeleted
, which is triggered every time a new algo is deleted.AlgoTypeChanged
, which is triggered every time an installed algo is modified.
AlgoRegistry in Different Modes
AlgoRegistry
works as intended in backtesting and optimisation. It does not work when using cTrader CLI.
Creating an Example Plugin¶
The AlgoRegistry
is perfect for creating a plugin that will display information about algos directly in the cTrader UI. The below plugin does just that.
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
Upon building our plugin, we should see the following block in the 'Active Symbol Panel'. The data in the block will be dynamically updated every second.
Installing an Algo Through Another Algo¶
The AlgoRegistry
interface enables developers to create algorithms that can install other algorithms. For example, you can code a cBot (on start) to automatically install another cBot, an indicator or a plugin.
The following cBot is coded to install another cBot:
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 |
|
Summary¶
AlgoRegistry
is a great feature for plugin developers but it can also be used with other types of algos. For example, you may create an indicator that references another custom indicator, in which case your algo would first need to check whether the required indicator is installed by the user. We also recommend adding the AlgoRegistry
to your existing algos to simplify the management of custom indicators and other types of algos.