com.oanda.fxtrade.api
Interface FXClient


public interface FXClient

An FXClient object facilitates communication with OANDA's servers. Once connected the FXClient object provides access to two root objects; User and RateTable.


Nested Class Summary
static class FXClient.FXNotify
           
 
Field Summary
static java.lang.String CONNECTED
          Used when notifying Observers of a connection to the server
static java.lang.String DISCONNECTED
          Used when notifying Observers of a disconnection to the server
static java.lang.String FATAL_ERROR
          Used when notifying Observers of fatal errors
static long INTERVAL_1_DAY
           
static long INTERVAL_1_HOUR
           
static long INTERVAL_1_MIN
           
static long INTERVAL_10_SEC
           
static long INTERVAL_15_MIN
           
static long INTERVAL_3_HOUR
           
static long INTERVAL_30_MIN
           
static long INTERVAL_30_SEC
           
static long INTERVAL_5_MIN
           
static long INTERVAL_5_SEC
          The INTERVAL_ constants are useful when calling getHistory()
static java.lang.String NEW_SESSION_TOKEN
          Used when notifying Observers of new session token
static java.lang.String SESSION_INVALID
          Used when notifying Observers of invalid/expired session token
static java.lang.String STREAM_CONNECTED
           
static java.lang.String STREAM_DISCONNECTED
           
static java.lang.String UPDATE
          Used when notifying Observers of asynchronous updates
static java.lang.String UPDATE_ORDERS
          Used when notifying Observers of asynchronous updates
static java.lang.String UPDATE_TRADES
          Used when notifying Observers of asynchronous updates
static java.lang.String UPDATE_TRANSACTIONS
          Used when notifying Observers of asynchronous updates
 
Method Summary
 void addObserver(java.util.Observer observer)
          Compensates Observable methods
 boolean createEventManagerThread(boolean force)
          This method is used to create a new instance of the event dispatch thread.
 boolean createKeepAliveThread(boolean force)
          This method is used to create a new instance of the keepalive thread.
 boolean createRateThread(boolean force)
          Deprecated. 
 void deleteObserver(java.util.Observer observer)
           
 long getFXServerTime()
          Deprecated.  
 java.util.Vector<? extends FXHistoryPoint> getHistory(FXPair pair, long interval, int numTicks)
          Deprecated. Use getHistory from the RateTable instead
 RateTable getRateTable()
          Returns the RateTable object
 long getServerTime()
          Returns the current time held by the OANDA server expressed as a unix timestamp.
 java.lang.String getSessionKey()
          Returns the current session key.
 User getUser()
          Returns the User object currently connected to the OANDA server
 boolean getWithKeepAliveThread()
          Deprecated.  
 boolean getWithRateThread()
          Deprecated.  
 boolean isLoggedIn()
          Returns true if a connection exists with the server, false otherwise.
 void login(java.lang.String username, java.lang.String password)
          Attempts to establish a connection to OANDA's servers.
 void login(java.lang.String username, java.lang.String password, java.lang.String reason)
          Attempts to establish a connection to OANDA's servers.
 void login(java.lang.String username, java.lang.String password, java.lang.String sessionKey, java.lang.String reason, java.lang.String partnerName)
          Attempts to establish a connection to OANDA's servers.
 void logout()
          Disconnects from the server.
 void setProxy(boolean state)
          Sets the proxy status for future connections to the server.
 void setRateTimeout(int timeout)
          Set the socket timeout for the rate thread.
 void setTimeout(int timeout)
          Sets the timeout for server response in seconds.
 void setWithKeepAliveThread(boolean wt)
           When the keep alive thread flag is set to true, a new thread is created which will periodically send requests to the server in order to keep this connection alive.
 void setWithRateThread(boolean wt)
           When the rate thread flag is set to true, a new thread is created which will keep receive rates from the server.
 void setWithTrailingStopMonitor(boolean wtsm)
          Enabling this feature allows the API to actively track the current value of a trailing stop for your trades.
 

Field Detail

CONNECTED

static final java.lang.String CONNECTED
Used when notifying Observers of a connection to the server

See Also:
Constant Field Values

DISCONNECTED

static final java.lang.String DISCONNECTED
Used when notifying Observers of a disconnection to the server

See Also:
Constant Field Values

FATAL_ERROR

static final java.lang.String FATAL_ERROR
Used when notifying Observers of fatal errors

See Also:
Constant Field Values

UPDATE

static final java.lang.String UPDATE
Used when notifying Observers of asynchronous updates

See Also:
Constant Field Values

UPDATE_ORDERS

static final java.lang.String UPDATE_ORDERS
Used when notifying Observers of asynchronous updates

See Also:
Constant Field Values

UPDATE_TRADES

static final java.lang.String UPDATE_TRADES
Used when notifying Observers of asynchronous updates

See Also:
Constant Field Values

UPDATE_TRANSACTIONS

static final java.lang.String UPDATE_TRANSACTIONS
Used when notifying Observers of asynchronous updates

See Also:
Constant Field Values

SESSION_INVALID

static final java.lang.String SESSION_INVALID
Used when notifying Observers of invalid/expired session token

See Also:
Constant Field Values

NEW_SESSION_TOKEN

static final java.lang.String NEW_SESSION_TOKEN
Used when notifying Observers of new session token

See Also:
Constant Field Values

STREAM_CONNECTED

static final java.lang.String STREAM_CONNECTED
See Also:
Constant Field Values

STREAM_DISCONNECTED

static final java.lang.String STREAM_DISCONNECTED
See Also:
Constant Field Values

INTERVAL_5_SEC

static final long INTERVAL_5_SEC
The INTERVAL_ constants are useful when calling getHistory()

See Also:
Constant Field Values

INTERVAL_10_SEC

static final long INTERVAL_10_SEC
See Also:
Constant Field Values

INTERVAL_30_SEC

static final long INTERVAL_30_SEC
See Also:
Constant Field Values

INTERVAL_1_MIN

static final long INTERVAL_1_MIN
See Also:
Constant Field Values

INTERVAL_5_MIN

static final long INTERVAL_5_MIN
See Also:
Constant Field Values

INTERVAL_15_MIN

static final long INTERVAL_15_MIN
See Also:
Constant Field Values

INTERVAL_30_MIN

static final long INTERVAL_30_MIN
See Also:
Constant Field Values

INTERVAL_1_HOUR

static final long INTERVAL_1_HOUR
See Also:
Constant Field Values

INTERVAL_3_HOUR

static final long INTERVAL_3_HOUR
See Also:
Constant Field Values

INTERVAL_1_DAY

static final long INTERVAL_1_DAY
See Also:
Constant Field Values
Method Detail

getHistory

java.util.Vector<? extends FXHistoryPoint> getHistory(FXPair pair,
                                                      long interval,
                                                      int numTicks)
                                                      throws OAException
Deprecated. Use getHistory from the RateTable instead

Returns a Vector of up to 500 FXHistoryPoint objects for the given FXPair and time interval.

Parameters:
pair - the desired FXPair
interval - The time interval in milliseconds. For your convenience, the following following constants have been provided for you:
  • INTERVAL_5_SEC
  • INTERVAL_10_SEC
  • INTERVAL_30_SEC
  • INTERVAL_1_MIN
  • INTERVAL_5_MIN
  • INTERVAL_30_MIN
  • INTERVAL_1_HOUR
  • INTERVAL_3_HOUR
  • INTERVAL_1_DAY
numTicks - the number of ticks to retrieve (maximum 500)
Throws:
OAException
See Also:
FXPair, FXHistoryPoint, RateTable

getRateTable

RateTable getRateTable()
                       throws SessionDisconnectedException
Returns the RateTable object

Returns:
the RateTable object
Throws:
SessionDisconnectedException
See Also:
RateTable

getServerTime

long getServerTime()
Returns the current time held by the OANDA server expressed as a unix timestamp.

Returns:
server time as a unix timestamp.

getFXServerTime

long getFXServerTime()
                     throws OAException
Deprecated. 

Returns the current time held by the OANDA server expressed as a unix timestamp.

Returns:
the current time held by the OANDA server expressed as a unix timestamp.
Throws:
OAException - may throw out when the return data is broken

getUser

User getUser()
             throws SessionException
Returns the User object currently connected to the OANDA server

Returns:
the User object currently connected to the OANDA server
Throws:
SessionException
See Also:
User

getWithRateThread

boolean getWithRateThread()
Deprecated. 


getWithKeepAliveThread

boolean getWithKeepAliveThread()
Deprecated. 


isLoggedIn

boolean isLoggedIn()
Returns true if a connection exists with the server, false otherwise.

Returns:
true if a connection exists with the server, false otherwise.

login

void login(java.lang.String username,
           java.lang.String password)
           throws InvalidUserException,
                  InvalidPasswordException,
                  SessionException,
                  MultiFactorAuthenticationException
Attempts to establish a connection to OANDA's servers.

This is equivalent to calling:

FXClient.login(username, password, null);

Parameters:
password - the password for the user associated with this API
Throws:
MultiFactorAuthenticationException
InvalidUserException
InvalidPasswordException
SessionException

login

void login(java.lang.String username,
           java.lang.String password,
           java.lang.String reason)
           throws InvalidUserException,
                  InvalidPasswordException,
                  SessionException,
                  MultiFactorAuthenticationException
Attempts to establish a connection to OANDA's servers.

If a valid session key is provided, this will be used to resume a previous session which avoids the key negotiation phase and prevents increasing the session count on OANDA's server.

If the session key has expired, a new session will be negotiated with the server during the login request.

Providing a null value for the key is the same as creating a new session.

Parameters:
username - the account username
password - the account password
reason - the reason for last disconnection.
Throws:
InvalidUserException
InvalidPasswordException
SessionException
MultiFactorAuthenticationException

login

void login(java.lang.String username,
           java.lang.String password,
           java.lang.String sessionKey,
           java.lang.String reason,
           java.lang.String partnerName)
           throws InvalidUserException,
                  InvalidPasswordException,
                  SessionException,
                  MultiFactorAuthenticationException
Attempts to establish a connection to OANDA's servers.

This is equivalent to calling:

FXClient.login(username, password, null);

Parameters:
username - the account username
password - the password for the user associated with this API
reason - the reason for last disconnection.
sessionKey - existing session key to be used if continueing a pre-existing session.
partnerName - the name of the partner for tracking
Throws:
MultiFactorAuthenticationException
InvalidUserException
InvalidPasswordException
SessionException

createKeepAliveThread

boolean createKeepAliveThread(boolean force)
This method is used to create a new instance of the keepalive thread. This method should be called when the keepalive thread dies unexpectedly.

Parameters:
force - attempt to force creation of the keepalive thread even if it's alive
Returns:
true if a new keepalive thread instance is created

createRateThread

@Deprecated
boolean createRateThread(boolean force)
Deprecated. 

This method is used to create a new instance of the rate table thread. This method should be called when the rate thread dies unexpectedly,

Parameters:
force - attemp to force creation of the rate thread even if it's alive
Returns:
true if a new rate thread instance is created

createEventManagerThread

boolean createEventManagerThread(boolean force)
This method is used to create a new instance of the event dispatch thread. This method should be called when the event thread dies unexpectedly,

Parameters:
force - attemp to force creation of the event thread even if it's alive
Returns:
true if a new event thread instance is created

getSessionKey

java.lang.String getSessionKey()
Returns the current session key. A null return value indicates that there is no active session on this instance of FXClient. The session key encodes both the current session identifier as well as last activity time.

The generated session key will be valid on OANDA's sever as long as there has been recent activity through the API (such as getting transaction history, retrieving the server time, etc). If there has been no communication with OANDA's server, the session may have been timed out (which is approximately 10 minutes). In this case, a valid but expired session key will be generated.

Returns:
the current session key

logout

void logout()
Disconnects from the server.


setProxy

void setProxy(boolean state)
Sets the proxy status for future connections to the server.

Proxy connections are made via port 443, whereas non-proxy connection are made through port 9700.

Parameters:
state - the boolean state for proxy connection.

setTimeout

void setTimeout(int timeout)
Sets the timeout for server response in seconds.

Parameters:
timeout - timeout for server response in seconds

setWithRateThread

void setWithRateThread(boolean wt)

When the rate thread flag is set to true, a new thread is created which will keep receive rates from the server. If this flag is not set, rates cannot be received. This also has the side effect not not being able to retrieve the history on instruments (via RateTable).

The rate thread also acts as a keep alive thread by periodically sending requests to the server in order to keep this connection alive. It is not necessary to run both the rate thread and the keep alive thread. On the other hand if both the rate thread and keep alive thread are enabled, the rate thread will delegate this task to the keep alive thread.

Parameters:
wt - for active or inactive

setWithKeepAliveThread

void setWithKeepAliveThread(boolean wt)

When the keep alive thread flag is set to true, a new thread is created which will periodically send requests to the server in order to keep this connection alive.

If this flag and the rate thread flag are set, only the keep alive thread will send keep alive requests to the server even though the rate thread has this capability.

Parameters:
wt - set KeepAliveThread active or not

setWithTrailingStopMonitor

void setWithTrailingStopMonitor(boolean wtsm)
Enabling this feature allows the API to actively track the current value of a trailing stop for your trades.

This property must be set before login.

Parameters:
wtsm -

addObserver

void addObserver(java.util.Observer observer)
Compensates Observable methods

Parameters:
observer - observer instance to be passed to implementation
See Also:
Observable

deleteObserver

void deleteObserver(java.util.Observer observer)

setRateTimeout

void setRateTimeout(int timeout)
Set the socket timeout for the rate thread.

Parameters:
timeout - timeout for the rate thread in seconds


Copyright © 2005 OANDA Corporation. All Rights Reserved.