Building Trading Strategies Data Providers

Data Providers

A Botmain strategy receives its data from data subscriptions from the Market Data Server. Each strategy contains a primary data subscription and may also contain secondary data subscriptions. Each subscription is responsible for a certain data type, such as daily bars, intraday bars, tick prices, and/or fundamental market data. Data to subscriptions is provided by data providers.

There are 4 types of data providers that your strategy can subscribe to.

To subscribe to any of these providers, simply @Inject() one or more of them into your strategy:

import { DailyBarsProvider, IntradayBarsProvider, TicksProvider, FundamentalsProvider, InstrumentProcessorBase } from "@botmain/common";

export class InstrumentProcessor extends InstrumentProcessorBase {
  @Inject() override daily: DailyBarsProvider;
  @Inject() override bars: IntradayBarsProvider;
  @Inject() override quotes: TicksProvider;
  @Inject() override fundamentals: FundamentalsProvider;
}

By injecting any of these providers, you will be required to configure some parameters when running your strategy in the GUI. Some common parameters include specifying the data stream from the Market Data Server [Datastreams] from which to load data. You will also need to configure the stackSize, which is the maximum number of historical data points available to the strategy via lookback.

Timeframes

The DailyBarsProvider provides your strategy with bars of daily periodicity. For medium and long-term strategies, daily bars are typically enough and allow your strategy to process less data, resulting in faster backtests.

In general, your strategy needs only to subscribe to one price provider for the lowest resolution that it needs for its logic. For example, if your strategy requires 30-minute bars, there is no need to include a DailyBarsProvider, since daily bars will be aggregated from 30-minute bars using the IntradayBarsProvider (that you need anyways). Similarly, if your strategy includes a TicksProvider, then it doesn't need an IntradayBarsProvider, since any periodicity of bars can be aggregated from tick data. In both cases, your strategy will still have access to the InstrumentProcessorBase.daily and InstrumentProcessorBase.bars objects, even if you haven't configured a bars provider directly.

Warm-up

When a strategy is started in real-time mode, it may be configured to have a historical warm up.

During warm up, the strategy receives historical data for the given amount of time preceding the current time. It may be useful if the strategy needs historical data to prepare indicators or some statistics before trading. At the end of the warm up, but before actual real-time data will be sent to the strategy, it receives a special WarmUpEnd event.

From the strategy point of view, working in warm up is very close to working with real time market data. Strategy receives all events and can work with most Botmain objects. However there are some key differences in warm up mode:

• Historical data is sent to the strategy in warm up mode faster than real-time speed. Consequently using Date.now() and other properties related to local computer time may give undesired results. If possible, it is always better to use computer-independent Botmain time properties like InstrumentProcessorBase.currentTime.

• During warm up, the strategy can't issue, cancel, cancel, replace, or modify an order. Any call to these methods will result in an exception.