com.dukascopy.api.system
Interface IClient

All Known Subinterfaces:
ITesterClient

public interface IClient

Main entry point for the connection to the server


Method Summary
 void addClientGUIListener(IClientGUIListener clientGuiListener)
          Register a IClientGUIListener which is "interested" in open / close charts from strategy
 void addNewsFilter(INewsFilter newsFilter)
          Adds news filter
 void closeChart(IChart chart)
          Close specified chart.
 void compileStrategy(java.lang.String srcJavaFile, boolean obfuscate)
          Compile .java strategy file to .jfx file.
 void connect(java.lang.String jnlp, java.lang.String username, java.lang.String password)
          Authenticates and connects to dukascopy servers
 void connect(java.lang.String jnlp, java.lang.String username, java.lang.String password, java.lang.String pin)
          Authenticates and connects to dukascopy servers
 void disconnect()
          Stops all running strategies and disconnect from dukascopy server.
 java.util.Set<Instrument> getAvailableInstruments()
          Returns a set of operable for the current user instruments.
 java.awt.image.BufferedImage getCaptchaImage(java.lang.String jnlp)
          Returns the image that can be provided to the user to generate correct pin code
 IClientGUI getClientGUI(IChart chart)
          Returns IClientGUI for specified IChart.
 INewsFilter getNewsFilter(INewsFilter.NewsSource newsSource)
          Returns news filter for the source
 java.util.Map<java.lang.Long,IStrategy> getStartedStrategies()
          Returns map with ids mapped to associated strategies
 java.util.Set<Instrument> getSubscribedInstruments()
          Returns subscribed instruments
 boolean isConnected()
          Returns true if client is authenticated authorized and transport is in connected state
 IStrategy loadStrategy(java.io.File strategyBinaryFile)
          Loads strategy from jfx file
 IChart openChart(IFeedDescriptor feedDescriptor)
          Opens new chart with specified in IFeedDescriptor parameters.
 void reconnect()
          Tries to reconnect transport without reauthenticating.
 void removeClientGUIListener(IClientGUIListener clientGuiListener)
          Unregister a IClientGUIListener
 INewsFilter removeNewsFilter(INewsFilter.NewsSource newsSource)
          Removes news filter, resetting it to the default value
 void setCacheDirectory(java.io.File cacheDirectory)
          Sets the location of the cache files.
 void setErr(java.io.PrintStream err)
          Sets stream that will be passed to the strategy through IConsole.
 void setOut(java.io.PrintStream out)
          Sets stream that will be passed to the strategy through IConsole.
 void setSystemListener(ISystemListener systemListener)
          Sets the listener, that will receive notifications about connects disconnects and strategies starts and stops
 void setSubscribedInstruments(java.util.Set<Instrument> instruments)
          Subscribes to the specified instruments set.
 long startStrategy(IStrategy strategy)
          Starts the strategy with default exception handler that will stop strategy if it trows exception
 long startStrategy(IStrategy strategy, IStrategyExceptionHandler exceptionHandler)
          Starts the strategy
 void stopStrategy(long processId)
          Stops the strategy with the specified id
 

Method Detail

connect

void connect(java.lang.String jnlp,
             java.lang.String username,
             java.lang.String password)
             throws JFAuthenticationException,
                    JFVersionException,
                    java.lang.Exception
Authenticates and connects to dukascopy servers

Parameters:
jnlp - address of jnlp file, that is used to launch platform
username - user name
password - password
Throws:
JFAuthenticationException - authentication error, incorrect username or password, IP address unrecognized in case of LIVE systems
JFVersionException - version is blocked on the server, update your libraries
java.lang.Exception - all kinds of errors that resulted in exception

connect

void connect(java.lang.String jnlp,
             java.lang.String username,
             java.lang.String password,
             java.lang.String pin)
             throws JFAuthenticationException,
                    JFVersionException,
                    java.lang.Exception
Authenticates and connects to dukascopy servers

Parameters:
jnlp - address of jnlp file, that is used to launch platform
username - user name
password - password
pin - pin code generated with the captcha from the last getCaptchaImage(java.lang.String) call
Throws:
JFAuthenticationException - authentication error, incorrect username or password, IP address unrecognized in case of LIVE systems
JFVersionException - version is blocked on the server, update your libraries
java.lang.Exception - all kinds of errors that resulted in exception

getCaptchaImage

java.awt.image.BufferedImage getCaptchaImage(java.lang.String jnlp)
                                             throws java.lang.Exception
Returns the image that can be provided to the user to generate correct pin code

Parameters:
jnlp - address of jnlp file, that is used to launch platform
Returns:
captha image
Throws:
java.lang.Exception - if request for captcha failed

reconnect

void reconnect()
Tries to reconnect transport without reauthenticating. Method is asynchronous, meaning it will exit immidiately after sending connection request without waiting for the response. Caller will receive notification through ISystemListener interface


disconnect

void disconnect()
Stops all running strategies and disconnect from dukascopy server.


isConnected

boolean isConnected()
Returns true if client is authenticated authorized and transport is in connected state

Returns:
true if there is open and working connection to the server

startStrategy

long startStrategy(IStrategy strategy)
                   throws java.lang.IllegalStateException,
                          java.lang.NullPointerException
Starts the strategy with default exception handler that will stop strategy if it trows exception

Parameters:
strategy - strategy to run
Returns:
returns id assigned to the strategy
Throws:
java.lang.IllegalStateException - if not connected
java.lang.NullPointerException - if one of the parameters is null

startStrategy

long startStrategy(IStrategy strategy,
                   IStrategyExceptionHandler exceptionHandler)
                   throws java.lang.IllegalStateException,
                          java.lang.NullPointerException
Starts the strategy

Parameters:
strategy - strategy to run
exceptionHandler - if not null then passed exception handler will be called when strategy throws exception
Returns:
returns id assigned to the strategy
Throws:
java.lang.IllegalStateException - if not connected
java.lang.NullPointerException - if one of the parameters is null

loadStrategy

IStrategy loadStrategy(java.io.File strategyBinaryFile)
                       throws java.lang.Exception
Loads strategy from jfx file

Parameters:
strategyBinaryFile - jfx file
Returns:
loaded strategy
Throws:
java.lang.Exception - if loading failed

stopStrategy

void stopStrategy(long processId)
Stops the strategy with the specified id

Parameters:
processId - id of the strategy

getStartedStrategies

java.util.Map<java.lang.Long,IStrategy> getStartedStrategies()
Returns map with ids mapped to associated strategies

Returns:
started strategies

setSystemListener

void setSystemListener(ISystemListener systemListener)
Sets the listener, that will receive notifications about connects disconnects and strategies starts and stops

Parameters:
systemListener - listener

addNewsFilter

void addNewsFilter(INewsFilter newsFilter)
Adds news filter

Parameters:
newsFilter - news filter

getNewsFilter

INewsFilter getNewsFilter(INewsFilter.NewsSource newsSource)
Returns news filter for the source

Parameters:
newsSource - news source
Returns:
news filter

removeNewsFilter

INewsFilter removeNewsFilter(INewsFilter.NewsSource newsSource)
Removes news filter, resetting it to the default value

Parameters:
newsSource - news source
Returns:
news filter removed

setSubscribedInstruments

void setSubscribedInstruments(java.util.Set<Instrument> instruments)
Subscribes to the specified instruments set. 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 the instruments

getSubscribedInstruments

java.util.Set<Instrument> getSubscribedInstruments()
Returns subscribed instruments

Returns:
set of the subscribed instruments

setOut

void setOut(java.io.PrintStream out)
Sets stream that will be passed to the strategy through IConsole. Default out is System.out

Parameters:
out - stream

setErr

void setErr(java.io.PrintStream err)
Sets stream that will be passed to the strategy through IConsole. Default err is System.err

Parameters:
err - stream

setCacheDirectory

void setCacheDirectory(java.io.File cacheDirectory)
Sets the location of the cache files. Default is System.getProperty("java.io.tmpdir") + "/.cache" WARNING: JForex might delete all folder's content if folder already existed AND was not created by this method call.

Parameters:
cacheDirectory - directory where cache files should be saved

compileStrategy

void compileStrategy(java.lang.String srcJavaFile,
                     boolean obfuscate)
Compile .java strategy file to .jfx file. Destination .jfx file will be located in the same directory as the source.

Parameters:
srcJavaFile - .java source file to be compiled
obfuscate - if true, the strategy will be obfuscated
Throws:
java.lang.IllegalStateException - if not connected

addClientGUIListener

void addClientGUIListener(IClientGUIListener clientGuiListener)
Register a IClientGUIListener which is "interested" in open / close charts from strategy

Parameters:
clientGuiListener - IClientGUIListener

removeClientGUIListener

void removeClientGUIListener(IClientGUIListener clientGuiListener)
Unregister a IClientGUIListener

Parameters:
clientGuiListener - IClientGUIListener

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 -

getClientGUI

IClientGUI getClientGUI(IChart chart)
Returns IClientGUI for specified IChart.
NOTE: Can be used only by Standalone JForex API. There is no access to embedded chart's panels from JForex Platform.

Parameters:
chart - IChart
Returns:
IClientGUI for specified IChart, or null if it's not Standalone JForex API environment.

getAvailableInstruments

java.util.Set<Instrument> getAvailableInstruments()
Returns a set of operable for the current user instruments. Use this method to get all available instruments. If there is no instruments available, the method return empty set.

Returns:
Set of available instruments