Engine API
The Engine module provides the core execution framework for Planar strategies. It handles data management, order execution, and coordinates between different execution modes (simulation, paper trading, and live trading).
Overview
The Engine serves as the central coordinator that:
- Manages strategy execution across different modes
- Handles data loading and OHLCV management
- Coordinates with exchanges and executors
- Provides unified interfaces for backtesting and live trading
Data Structures and Types
Core Types
The Engine module works with several key types.
Complete API Reference
PlanarCore.Strategies.Strategy — Method
Initializes a Strategy object in the Strategies module.
Strategy(
self::Module,
assets::Union{AbstractSet{String}, Tuple{Vararg{String}}, Dict, AbstractVector{String}};
load_data,
config,
params,
account,
mode,
margin,
sandbox,
timeframe
)
The Strategy function takes the following parameters:
self: a Module object representing the current module.assets: a Union of a dictionary or iterable of strings representing the assets to be included in the strategy.load_data(optional, default is true): a boolean indicating whether to load data for the assets.config: a Config object representing the configuration settings for the strategy.mode(optional, default is config.mode): a mode setting for the strategy.margin(optional, default is config.margin): a margin setting for the strategy.sandbox(optional, default is true): a boolean indicating whether to run the strategy in a sandbox environment.timeframe(optional, default is config.min_timeframe): a timeframe setting for the strategy.
The function initializes a Strategy object with the specified settings and assets.
Base.fill! — Method
fill! all the instances with given timeframes data...
fill!(
ac::PlanarCore.Collections.InstrumentCollection,
tfs...;
kwargs...
) -> DataFrames.DataFrame
Base.fill! — Method
Pulls data from storage, or resamples from the shortest timeframe available.
fill!(
ii::PlanarCore.Instances.InstrumentInstance,
tfs...;
exc,
force,
from
)
This fill! function takes the following parameters:
ii: an InstrumentInstance object which represents an instance of an asset.tfs...: one or more TimeFrame objects that represent the desired timeframes to fill the data for.exc(optional, default isii.exchange): an Exchange object that represents the exchange to pull data from.force(optional, default is false): a boolean that indicates whether to force the data filling, even if the data is already present.from(optional, default is nothing): a DateTime object that represents the starting date from which to fill the data.
Fills the data for the specified timeframes. If the data is already present and force is false, the function does nothing.
PlanarCore.Data.stub! — Method
Replaces the data of the asset instances with src which should be a mapping. Used for backtesting.
stub!(
ac::PlanarCore.Collections.InstrumentCollection,
src;
fromfiat
)
The stub! function takes the following parameters:
ac: an InstrumentCollection object which encapsulates a collection of assets.src: The mapping, should be a pairTimeFrame => Dict{String, PairData}.fromfiat(optional, default is true): a boolean that indicates whether the assets are priced in fiat currency. If true, the assets are priced in fiat currency.
The function replaces the OHLCV data of the assets in the ac collection with the data from the src mapping. This is useful for backtesting trading strategies.
Example:
using PlanarDownloadTool.BinanceData as bn
using Strategies
using Exchanges
setexchange!(:binanceusdm)
cfg = Config(Symbol(exc.id))
strat = strategy!(:Example, cfg)
data = bn.binanceload()
stub!(strat.universe, data)See Also
- Strategies API - Strategy base classes and interfaces
- Data API - Data structures and management
- Executors API - Order execution and management
- Execution Modes Guide - Understanding sim, paper, and live modes
- Data Management Guide - Working with market data