engine.md
1 # Engine 2 3 Within the Planar "model", we use the _call!_ and _call!_ functions to communicate between _strategies_ and _executors_. The executor calls the [strategy](../guides/strategy-development.md), implying that the [strategy](../guides/strategy-development.md) should do or return something. The [strategy](../guides/strategy-development.md) calls the executor, expecting it to do or return something. 4 5 In the Planar framework, the user generally only writes `call!` functions within their [strategies](../guides/strategy-development.md). 6 7 Unlike other trading bots that offer a set of methods for tuning purposes, usually tied to the super class of the strategy, Planar conventionally deals only with `call!` functions. This allows you to know that whenever a _call!_ call is made from the strategy, it is a point where [simulation](../guides/execution-modes.md#simulation-mode) and live execution may diverge. 8 9 The functions are implemented in a way that they dispatch differently according to the execution mode of the strategy. There are 3 execution modes: 10 11 - `Sim`: This mode is used by the backtester to run simulations. 12 - `Paper`: This is the dry run mode, which runs the bot as if it were live, working with live data feeds and simulating order execution with live prices. 13 - `Live`: Similar to `Paper`, but with order execution actually forwarded to a live exchange (e.g., through CCXT). 14 15 If the strategy is instantiated in `Sim` mode, calling `call!(s, ...)`, where `s` is the strategy object of type `Strategy{Sim, N, E, M, C}`, the `call!` function will dispatch to the `Sim` execution method. The other two parameters, `N` and `E`, are required for concretizing the strategy type: 16 - `N<:Symbol`: The symbol that matches the module name of the strategy, such as `:Example`. 17 - `E<:ExchangeID`: The symbol that has already been checked to match a valid CCXT exchange, which will be the exchange that the strategy will operate on. 18 - `M<:MarginMode`: The margin mode of the strategy, which can be `NoMargin`, `IsolatedMargin`, or `CrossMargin`. Note that the margin mode also has a type parameter to specify if hedged positions (having long and short on the same asset at the same time) are allowed. `Isolated` and `Cross` are shorthand for `IsolatedMargin{NotHedged}` and `CrossMargin{NotHedged}`. 19 - `C`: The symbol of the `CurrencyCash` that represents the balance of the strategy, e.g., `:USDT`. 20 21 To follow the `call!` dispatch convention, you can expect the first argument of every call function to the executor to be the strategy object itself, while strategy functions might have either the strategy object or the type of the strategy as the first argument (`Type{Strategy{...}}`). 22 23 24 25 26 ## See Also 27 28 - **[Exchanges](../exchanges.md)** - Exchange integration and configuration 29 - **[Config](../config.md)** - Exchange integration and configuration 30 - **[Optimization](../optimization.md)** - Performance optimization techniques 31 - **[Performance Issues](../troubleshooting/performance-issues.md)** - Troubleshooting: Performance optimization techniques 32 - **[Data Management](../guides/data-management.md)** - Guide: Data handling and management 33 - **[Exchanges](../exchanges.md)** - Data handling and management