com.dukascopy.api
Interface IContext


public interface IContext

Gives access to the various parts of the system


Method Summary
 void addConfigurationChangeListener(java.lang.String parameter, java.beans.PropertyChangeListener listener)
          Register a listener for a strategy configuration parameter which is preceded by a Configurable annotation.
 void closeChart(IChart chart)
          Close specified chart.
<T> java.util.concurrent.Future<T>
executeTask(java.util.concurrent.Callable<T> callable)
          Every strategy executes in it's own thread.
 IAccount getAccount()
          Returns last known state of the account info.
 IChart getChart(Instrument instrument)
          Returns first chart for specified instrument.
 java.util.Set<IChart> getCharts(Instrument instrument)
          Returns set of charts for specified instrument.
 IConsole getConsole()
          Returns interface that allows to write messages into the Messages table
 IDataService getDataService()
          Returns interface that allows access to system data.
 IDownloadableStrategies getDownloadableStrategies()
          Returns interface that allows to handle downloadable strategies
 IEngine getEngine()
          Returns interface of the main engine (order submitting, merging etc)
 java.io.File getFilesDir()
          Returns directory where reading and writing is allowed.
 IHistory getHistory()
          Returns interface that allows access to history data
 IIndicators getIndicators()
          Returns interface that allows to calculate indicator values
 IChart getLastActiveChart()
           
 IReportService getReportService()
          Returns interface that give access to reporting system
 IStrategies getStrategies()
          Returns interface that allows to start/stop and control other strategies
 java.util.Set<Instrument> getSubscribedInstruments()
          Returns set of the currently subscribed instruments
 IUserInterface getUserInterface()
          Returns an interface which provides control to custom strategy tabs in the main and bottom panels
 JFUtils getUtils()
          Returns interface with JForex utility methods, e.g., currency converter
 boolean isFullAccessGranted()
          Returns true if strategy is granted full access.
 boolean isStopped()
          Returns true if user requested to stop the strategy.
 IChart openChart(IFeedDescriptor feedDescriptor)
          Opens new chart with specified in IFeedDescriptor parameters.
 void pause()
          Pauses historical testing, doesn't have any effect if not in historical tester
 void removeConfigurationChangeListener(java.lang.String parameter, java.beans.PropertyChangeListener listener)
          Unregister a listener for a certain configuration parameter which is preceded by a Configurable annotation.
 void setSubscribedInstruments(java.util.Set<Instrument> instruments)
          Checks that the instruments are subscribed and subscribes to the instrument if it's not.
 void setSubscribedInstruments(java.util.Set<Instrument> instruments, boolean lock)
          Checks that the instruments are subscribed and subscribes to the instrument if it's not.
 void stop()
          Stops strategy execution.
 void subscribeToBarsFeed(Instrument instrument, Period period, OfferSide offerSide, IBarFeedListener listener)
          Subscribes passed listener on bars feed notification by passed instrument, period and offer side.
 void subscribeToFeed(IFeedDescriptor feedDescriptor, IFeedListener feedListener)
          Subscribes passed listener on feed notification by passed feed descriptor
 void subscribeToPointAndFigureFeed(Instrument instrument, OfferSide offerSide, PriceRange priceRange, ReversalAmount reversalAmount, IPointAndFigureFeedListener listener)
          Subscribes passed listener on point and figure feed notification by passed instrument, offer side, price range and reversal amount
 void subscribeToRangeBarFeed(Instrument instrument, OfferSide offerSide, PriceRange priceRange, IRangeBarFeedListener listener)
          Subscribes passed listener on range bars feed notification by passed instrument, offer side and price range
 void subscribeToRenkoBarFeed(Instrument instrument, OfferSide offerSide, PriceRange brickSize, IRenkoBarFeedListener listener)
          Subscribes passed listener on renko bars feed notification by passed instrument, offer side and brick size
 void subscribeToTickBarFeed(Instrument instrument, OfferSide offerSide, TickBarSize tickBarSize, ITickBarFeedListener listener)
          Subscribes passed listener on tick bar feed notification by passed instrument, offer side and tick bar size
 void subscribeToTicksFeed(Instrument instrument, ITickFeedListener listener)
          Subscribes passed listener on ticks feed notification by passed instrument.
 void unsubscribeFromBarsFeed(IBarFeedListener listener)
          Unsubscribes passed listener from bars feed notification
 void unsubscribeFromFeed(IFeedListener feedListener)
          Unsubscribes passed listener from feed notification
 void unsubscribeFromPointAndFigureFeed(IPointAndFigureFeedListener listener)
          Unsubscribes passed listener from point and figure feed notification
 void unsubscribeFromRangeBarFeed(IRangeBarFeedListener listener)
          Unsubscribes passed listener from range bars feed notification
 void unsubscribeFromRenkoBarFeed(IRenkoBarFeedListener listener)
          Unsubscribes passed listener from renko bars feed notification
 void unsubscribeFromTickBarFeed(ITickBarFeedListener listener)
          Unsubscribes passed listener from tick bar feed notification
 void unsubscribeFromTicksFeed(ITickFeedListener listener)
          Unsubscribes passed listener from ticks feed notification
 

Method Detail

getEngine

IEngine getEngine()
Returns interface of the main engine (order submitting, merging etc)

Returns:
main engine

getChart

IChart getChart(Instrument instrument)
Returns first chart for specified instrument. If there is more than one chart for this instrument, then method returns one of them, but always the same.

Parameters:
instrument - currency pair
Returns:
chart or null if there is no chart opened for the instrument

getCharts

java.util.Set<IChart> getCharts(Instrument instrument)
Returns set of charts for specified instrument.

Parameters:
instrument - currency pair
Returns:
Set<IChart>

getLastActiveChart

IChart getLastActiveChart()
Returns:
corresponding IChart object of the last active chart, i.e., the chart which last had focus

openChart

IChart openChart(IFeedDescriptor feedDescriptor)
Opens new chart with specified in IFeedDescriptor parameters.

Parameters:
feedDescriptor -
Returns:
IChart newly created chart
Throws:
java.lang.IllegalArgumentException - when feedDescriptor not formed well

closeChart

void closeChart(IChart chart)
Close specified chart.

Parameters:
chart -

getUserInterface

IUserInterface getUserInterface()
Returns an interface which provides control to custom strategy tabs in the main and bottom panels

Returns:
singleton instance of the IUserInterface

getHistory

IHistory getHistory()
Returns interface that allows access to history data

Returns:
interface for history access

getConsole

IConsole getConsole()
Returns interface that allows to write messages into the Messages table

Returns:
interface for messages sending

getIndicators

IIndicators getIndicators()
Returns interface that allows to calculate indicator values

Returns:
interface for indicator calculations

getAccount

IAccount getAccount()
Returns last known state of the account info. This state is updated once in 5 seconds and can be inaccurate if significant price changes happen on the market

Returns:
account

getStrategies

IStrategies getStrategies()
Returns interface that allows to start/stop and control other strategies

Returns:

getDownloadableStrategies

IDownloadableStrategies getDownloadableStrategies()
Returns interface that allows to handle downloadable strategies

Returns:
interface for downloadable strategies handling

getUtils

JFUtils getUtils()
Returns interface with JForex utility methods, e.g., currency converter

Returns:

getDataService

IDataService getDataService()
Returns interface that allows access to system data.

Returns:
interface for system data

getReportService

IReportService getReportService()
Returns interface that give access to reporting system

Returns:
interface for consolidated reports' data TODO: enable on Oracle/API/DFS upgrade

setSubscribedInstruments

void setSubscribedInstruments(java.util.Set<Instrument> instruments)
Checks that the instruments are subscribed and subscribes to the instrument if it's not. Method returns fast after invoking and doesn't wait for subscription will be done. Ticks passed in onTick method will have full depth for this instruments, while other instruments are not guaranteed to have full depth.
Equivalent to setSubscribedInstruments(Set, boolean) with lock set as false

Parameters:
instruments - set of instruments, that strategy needs for it's work

setSubscribedInstruments

void setSubscribedInstruments(java.util.Set<Instrument> instruments,
                              boolean lock)
Checks that the instruments are subscribed and subscribes to the instrument if it's not. Ticks passed in onTick method will have full depth for this instruments, while other instruments are not guaranteed to have full depth.

Parameters:
instruments - set of instruments, that strategy needs for it's work
lock - false - method returns fast after invoking and doesn't wait for subscription will be done. true - otherwise.

getSubscribedInstruments

java.util.Set<Instrument> getSubscribedInstruments()
Returns set of the currently subscribed instruments

Returns:
set of the subscribed instruments

stop

void stop()
Stops strategy execution. Current task will be completed. This method doesn't work in IStrategy.onStart()


isStopped

boolean isStopped()
Returns true if user requested to stop the strategy. Can be used to check if strategy was stopped (for example from non strategy threads running in parallel)

Returns:
true if strategy stop was requested

isFullAccessGranted

boolean isFullAccessGranted()
Returns true if strategy is granted full access.

Returns:
true of false depending on access level

executeTask

<T> java.util.concurrent.Future<T> executeTask(java.util.concurrent.Callable<T> callable)
Every strategy executes in it's own thread. This will ensure single threaded model: Any handle method of IStrategy will be executed in order. Submission of orders can be called only from this thread. If some critical action like submitting order needs to be called from another thread, you need to use this method to access strategy thread. For instance:
 Thread thread = new Thread(new Runnable() {
      public void run() {
          try {
              context.executeTask(task);
          } catch (Exception e) {
              console.getErr().println(Thread.currentThread().getName() + " " + e);
          }
      }
  });
 thread.start();
 

Type Parameters:
T - type of the return value
Parameters:
callable - task to execute
Returns:
Future<T> that can be used to get result of execution

getFilesDir

java.io.File getFilesDir()
Returns directory where reading and writing is allowed. Usually ~/My Documents/My Strategies/files

Returns:
directory with free read/write access

pause

void pause()
Pauses historical testing, doesn't have any effect if not in historical tester


subscribeToBarsFeed

void subscribeToBarsFeed(Instrument instrument,
                         Period period,
                         OfferSide offerSide,
                         IBarFeedListener listener)
Subscribes passed listener on bars feed notification by passed instrument, period and offer side.

Parameters:
instrument - Instrument of bars to listen
period - Period period of bars to listen (Tick period is not supported).
offerSide - OfferSide of bars to listen
listener - IBarFeedListener listener

unsubscribeFromBarsFeed

void unsubscribeFromBarsFeed(IBarFeedListener listener)
Unsubscribes passed listener from bars feed notification

Parameters:
listener -

subscribeToRangeBarFeed

void subscribeToRangeBarFeed(Instrument instrument,
                             OfferSide offerSide,
                             PriceRange priceRange,
                             IRangeBarFeedListener listener)
Subscribes passed listener on range bars feed notification by passed instrument, offer side and price range

Parameters:
instrument - Instrument of bars to listen
offerSide - OfferSide of bars to listen
priceRange - PriceRange of bars to listen
listener - IRangeBarFeedListener listener

unsubscribeFromRangeBarFeed

void unsubscribeFromRangeBarFeed(IRangeBarFeedListener listener)
Unsubscribes passed listener from range bars feed notification

Parameters:
listener -

subscribeToPointAndFigureFeed

void subscribeToPointAndFigureFeed(Instrument instrument,
                                   OfferSide offerSide,
                                   PriceRange priceRange,
                                   ReversalAmount reversalAmount,
                                   IPointAndFigureFeedListener listener)
Subscribes passed listener on point and figure feed notification by passed instrument, offer side, price range and reversal amount

Parameters:
instrument - Instrument of P&Fs to listen
offerSide - OfferSide of P&Fs to listen
priceRange - PriceRange of P&Fs to listen
reversalAmount - ReversalAmount of P&Fs to listen
listener - IPointAndFigureFeedListener listener

unsubscribeFromPointAndFigureFeed

void unsubscribeFromPointAndFigureFeed(IPointAndFigureFeedListener listener)
Unsubscribes passed listener from point and figure feed notification

Parameters:
listener -

subscribeToTickBarFeed

void subscribeToTickBarFeed(Instrument instrument,
                            OfferSide offerSide,
                            TickBarSize tickBarSize,
                            ITickBarFeedListener listener)
Subscribes passed listener on tick bar feed notification by passed instrument, offer side and tick bar size

Parameters:
instrument - Instrument of tick bars to listen
offerSide - OfferSide of tick bars to listen
tickBarSize - TickBarSize of tick bars to listen
listener - ITickBarFeedListener listener

unsubscribeFromTickBarFeed

void unsubscribeFromTickBarFeed(ITickBarFeedListener listener)
Unsubscribes passed listener from tick bar feed notification

Parameters:
listener -

subscribeToRenkoBarFeed

void subscribeToRenkoBarFeed(Instrument instrument,
                             OfferSide offerSide,
                             PriceRange brickSize,
                             IRenkoBarFeedListener listener)
Subscribes passed listener on renko bars feed notification by passed instrument, offer side and brick size

Parameters:
instrument - Instrument of renko bars to listen
offerSide - OfferSide of renko bars to listen
brickSize - brick size of renko bars to listen
listener - IRenkoBarFeedListener listener

unsubscribeFromRenkoBarFeed

void unsubscribeFromRenkoBarFeed(IRenkoBarFeedListener listener)
Unsubscribes passed listener from renko bars feed notification

Parameters:
listener -

addConfigurationChangeListener

void addConfigurationChangeListener(java.lang.String parameter,
                                    java.beans.PropertyChangeListener listener)
Register a listener for a strategy configuration parameter which is preceded by a Configurable annotation. Listener will listen changes of specified property for running strategy.

Parameters:
parameter - either the name of strategy field which is preceded by a Configurable annotation or Configurable.value() - the assigned configurable parameter name that appears besides its value in GUI.
listener - Listener which will get PropertyChangeEvents

removeConfigurationChangeListener

void removeConfigurationChangeListener(java.lang.String parameter,
                                       java.beans.PropertyChangeListener listener)
Unregister a listener for a certain configuration parameter which is preceded by a Configurable annotation.

Parameters:
parameter - either the name of strategy field which is preceded by a Configurable annotation or Configurable.value() - the assigned configurable parameter name that appears besides its value in GUI.
listener - Listener which will get PropertyChangeEvents

subscribeToFeed

void subscribeToFeed(IFeedDescriptor feedDescriptor,
                     IFeedListener feedListener)
Subscribes passed listener on feed notification by passed feed descriptor

Parameters:
feedDescriptor - IFeedDescriptor
feedListener - IFeedListener

unsubscribeFromFeed

void unsubscribeFromFeed(IFeedListener feedListener)
Unsubscribes passed listener from feed notification

Parameters:
feedListener - IFeedListener

subscribeToTicksFeed

void subscribeToTicksFeed(Instrument instrument,
                          ITickFeedListener listener)
Subscribes passed listener on ticks feed notification by passed instrument.

Parameters:
instrument - Instrument of ticks to listen
listener - ITickFeedListener listener

unsubscribeFromTicksFeed

void unsubscribeFromTicksFeed(ITickFeedListener listener)
Unsubscribes passed listener from ticks feed notification

Parameters:
listener -