Using instruments: futures, indices, stocks
In your strategy code, you can define which instruments are used by the strategy using the @Instruments annotation.
Although we only used to provide futures in previous versions, we started supporting a few indices from version 1.3, and stocks from version 1.4.
Basic mechanism
To create a strategy that trades on the CAC 40 and FTSE futures, define your instruments as follows:
@Instruments(futures = {Futures.CAC_40, Futures.FTSE})
Auto-completion under Eclipse
If you are using Eclipse to design your strategy, you can type Futures. (including the period) and then press Ctrl+Space to obtain the full list of available futures. This implies that the Futures class is imported at the beginning of the source file, as it is the case in the samples, with the line com.algodeal.data.marketData.instruments.Futures.*.
It works the same way for Stocks and Indices.

More readable strategy code
This code can be improved by statically importing the Futures enum:
import static com.algodeal.marketData.instruments.Futures.*;
...
@Instruments(futures = {CAC_40, FTSE})
To trade on Stocks, you can list them in the same way you list Futures:
import static com.algodeal.marketData.instruments.Stocks.*;
...
@Instruments(stocks={APPLE, GOOGLE, AMAZON_COM})
For indices:
import static com.algodeal.marketData.instruments.Indices.*;
...
@Instruments(indices = { VIX_INDEX })
All combinations of Futures, Stock and Indices are supported. For example:
import static com.algodeal.marketData.instruments.Futures.*;
import static com.algodeal.marketData.instruments.Indices.*;
import static com.algodeal.marketData.instruments.Stocks.*;
...
@Instruments(futures = { CAC_40, E_MINI_SP }, indices = { VIX_INDEX }, stocks = { APPLE, BAYER_AG })
Don't trade indices
Since indices do not have trades, it is not possible to place an order on them. If you do so by mistake, you'll get an exception when running your strategy.
If your strategy needs indices to run, it might be a good idea to guard your order placing with checks. For example, here, we check that the current instrument is not the requested index:
@Instruments(futures = CAC_40, indices = VIX_INDEX)
public class MyStrategy extends AbstractStrategy {
@Override
public void onOpen(OpenPrice open) {
if (getInstrument() != VIX_INDEX) {
buy(1);
}
}
}
Another way is to check if the instrument is tradeable, which is convenient if there are many indices being requested:
@Instruments(futures = CAC_40, indices = VIX_INDEX)
public class MyStrategy extends AbstractStrategy {
@Override
public void onOpen(OpenPrice open) {
if (getInstrument() instanceof Tradeable) {
buy(1);
}
}
}
Also, you must have at least one tradeable instrument (a futures or a stock) in the definition of your strategy. Otherwise, you'll get an error when trying to run in, before it is even started.
What instruments are available?
To get the complete list of supported instruments, check out the Futures, Indices and Stocks classes on the Market Runner API documentation.