-
Notifications
You must be signed in to change notification settings - Fork 129
How to Create Custom Strategy
10.1.1 Take dexbot/strategies/strategy_template.py
and dexbot/strategies/config_parts/strategy_config.py
as templates for a new strategy. strategy_template.py
contains strategy skeleton, while strategy_config.py
contains strategy config options.
10.2 Workers in DEXBot are callback based. WorkerInfrastructure
(dexbot/worker.py) manage subscriptions to the node via bitshares.Notify. When some event is received from the node, a callback function is called. A strategy can set several callbacks:
- 10.2.1 self.onMarketUpdate: called when market event happened, e.g. a new order was placed
- 10.2.2 self.onAccount: something happened with worker account, like: account placed an order, incoming transfer
- 10.2.3 self.ontick: called on each block
10.3.2.1 To add into cli configure: dexbot/cli_conf.py
add the strategy into STRATEGIES
constant. Note that "tag" field must be unique.
10.3.2.2 To add into GUI: dexbot/controllers/worker_controller.py
add the strategy into strategies()
10.3.3.1 If you don't need custom logic in the GUI, just use ConfigElement
like shown in strategy_config.py
. Corresponding GUI elements will be generated automatically.
10.3.3.2 If you need custom elements in the GUI, specify custom 'form_module'
in WorkerController.strategies()
to point to some ui file. For example the Relative Orders strategy and it's UI are in dexbot/views/ui/forms/relative_orders_widget.ui
. You can create such a custom UI file via qt-designer tool.
10.3.4.1 To set up GUI elements connections and signals, you need to define StrategyController
class (see dexbot/controllers/strategy_controller.py
). Built-in strategies have their controllers right there, but external strategy may have its own StrategyController
class in the same my_strategy.py
file.
10.3.5.1 DEXBot uses importlib
when launching a worker. For each worker there is a "module" directive in config.yml, like module: dexbot.strategies.staggered_orders
. dexbot/helper.py
contains the external strategy discovery mechanism which tries to import strategies from dexbot.strategy
namespace.
10.3.5.1.1 This means you can package a custom strategy into "dexbot.strategies" namespace and it will be discovered automatically.
10.3.5.2 To provide a custom UI, you need to have class Ui_Form
defined inside your strategy module. See the example in dexbot/views/ui/forms/relative_orders_widget_ui.py
(this file is autogenerated by python setup.py build_ui
from the originating UI file).