public interface IStrategy extends IJFRunnable<IContext>
Modifier and Type | Method and Description |
---|---|
void |
onAccount(IAccount account)
Called when account information update is received
|
void |
onBar(Instrument instrument,
Period period,
IBar askBar,
IBar bidBar)
Called on every bar for every basic period and instrument that application is subscribed on.
|
void |
onMessage(IMessage message)
Called when new message is received.
|
void |
onStart(IContext context)
Called on strategy start.
|
void |
onStop()
Called before strategy is stopped.
|
void |
onTick(Instrument instrument,
ITick tick)
Called on every tick of every instrument that application is subscribed on.
|
void onStart(IContext context) throws JFException
It is imperative to subscribe with IContext.setSubscribedInstruments(java.util.Set, boolean)
to the instruments that the strategy is going to work with, one can do it in the following way:
context.setSubscribedInstruments(new HashSet<Instrument>(Arrays.asList(Instrument.EURUSD, Instrument.AUDCAD), true));
onStart
in interface IJFRunnable<IContext>
context
- allows access to all system functionalityJFException
- when strategy author ignores exceptionsvoid onTick(Instrument instrument, ITick tick) throws JFException
In order to only work with ticks of a particular instrument consider tick filtering:
public void onTick(Instrument instrument, ITick tick) throws JFException { if (!instrument.equals(Instrument.EURUSD) || !instrument.equals(Instrument.AUDCAD)){ return; } //the strategy from here on only works with either EURUSD or AUDCAD ticks }
instrument
- instrument of the ticktick
- tick dataJFException
- when strategy author ignores exceptionsvoid onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
In order to only work with bars of a particular instrument and period consider bar filtering:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException { if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.ONE_HOUR)){ return; } //the strategy from here on only works with EURUSD ONE_HOUR bars }
instrument
- instrument of the barperiod
- period of the baraskBar
- bar created of ask side of the ticksbidBar
- bar created of bid side of the ticksJFException
- when strategy author ignores exceptionsvoid onMessage(IMessage message) throws JFException
IMessage
whenever the order state of any order changes,
this way allowing to manage order state.message
- messageJFException
- when strategy author ignores exceptionsvoid onAccount(IAccount account) throws JFException
account
- updated account informationJFException
- when strategy author ignores exceptionsvoid onStop() throws JFException
onStop
in interface IJFRunnable<IContext>
JFException
Copyright © 2024. All rights reserved.