public class Client extends Object implements AutoCloseable
Encapsulates ASTS connection, provides methods to load tables and execute transactions.
The class is not thread safe and makes no assumptions about threading issues.
| Modifier and Type | Class and Description |
|---|---|
static class |
Client.ExtendedReport |
static class |
Client.Options
Options to customize the Client.
|
static class |
Client.Report
Transaction execution result.
|
static interface |
Client.Request |
static class |
Client.SnapshotEntry |
| Constructor and Description |
|---|
Client()
Creates a client with default options and empty scale container.
|
Client(Client.Options options)
Creates a client with specific options and empty scale container.
|
Client(Client.Options options,
Meta.Tickers tickers)
Creates a client with specific options and provided scale container.
|
Client(Meta.Tickers tickers)
Creates a client with default options and provided scale container.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
active()
Checks whether this instance was connected to ASTS or not.
|
void |
close()
Closes ASTS connection.
|
Map<String,String> |
connect(Map<String,String> params)
Shorthand for
connect(params, new DefaultFactory());. |
Map<String,String> |
connect(Map<String,String> params,
Meta.Factory factory)
Similar to start(java.util.Map, com.micex.client.Meta.Factory)
extended with additional connection result response.
|
Client.Report |
execute(String command,
Map<String,Object> params)
Executes ASTS transaction.
|
String |
getFirmID()
Gets ASTS firm ID.
|
String |
getLanguage()
Gets current client two-letter language code.
|
Meta.Market |
getMarket()
Deprecated.
Use
getMarketInfo(). |
Meta.Market |
getMarketInfo()
Gets market structure description.
|
static int |
getResponseCode(String message)
Extracts ASTS response code from the message.
|
API.ServerInfo |
getServerInfo()
Gets server connection information.
|
byte[] |
getSnapshot()
Retrieves a snapshot of currently opened requests.
|
List<Client.SnapshotEntry> |
getSnapshotInfo(byte[] snapshot)
Retrieves information about requests which were opened at snapshot.
|
String |
getUserID()
Gets ASTS user ID.
|
int |
handle()
Gets raw API connection handle.
|
Parser |
load(String table,
Map<String,Object> params)
Completely loads the table.
|
Parser |
open(String table,
Map<String,Object> params,
boolean complete)
Opens the table: loads current data and adds the table to an internal
list of requests to be queried during refresh().
|
Parser |
open(String table,
Map<String,Object> params,
byte[] snapshot)
Opens the table at the state captured by snapshot and adds the table to
an internal list of requests to be queried during refresh().
|
Parser |
open(String table,
String filter,
byte[] snapshot)
An overloaded version of open(.., byte[] snapshot).
|
Client.ExtendedReport |
perform(String command,
Map<String,Object> params)
Executes ASTS transaction and returns extended report.
|
Parser |
refresh()
Refreshes previously opened tables.
|
Parser |
refresh(Sorter sorter)
Refreshes previously opened tables.
|
void |
selectBoards(Set<String> boards)
Narrows information flow to specified boards.
|
void |
setSnapshot(byte[] buffer)
Restores all opened requests to the snapshot state.
|
void |
start(Map<String,String> params)
Shorthand for
start(params, new DefaultFactory());. |
void |
start(Map<String,String> params,
Meta.Factory factory)
Establishes connection to ASTS, retrieves server
information and market structure description.
|
int |
status()
Gets connection status as returned by
MTEConnectionStatus. |
Meta.Tickers |
tickers()
Get scale container of this client.
|
public Client()
public Client(Client.Options options)
options - client customization options.public Client(Meta.Tickers tickers)
tickers - scale container. Can be shared between clients connecting
to the same ASTS instance.Meta.Tickerspublic Client(Client.Options options, Meta.Tickers tickers)
options - client customization options.tickers - scale container. Can be shared between clients connecting
to the same ASTS instance.Meta.Tickerspublic final boolean active()
true if this instance is connected.start(java.util.Map<java.lang.String, java.lang.String>, com.micex.client.Meta.Factory),
close()public final Meta.Tickers tickers()
Client instance when you are pretty sure to connect to
the same ASTS instance.public String getLanguage()
Locale.getDefault().getLanguage()).public void start(Map<String,String> params, Meta.Factory factory) throws ClientException
Check MTEConnect() ASTS API documentation for the description of connection parameters.
params - connection parameters.factory - market structure elements factory.ClientException - if connection attempt failed.public void start(Map<String,String> params) throws ClientException
start(params, new DefaultFactory());.params - connection parameters.ClientException - if connection attempt failed.public Map<String,String> connect(Map<String,String> params, Meta.Factory factory) throws ClientException
params - connection parameters.factory - market structure elements factory.MTETransExecEx
in "ASTS Connectivity Guide" for more information on parameters returned.ClientException - if connection attempt failed.start(java.util.Map, com.micex.client.Meta.Factory)public Map<String,String> connect(Map<String,String> params) throws ClientException
connect(params, new DefaultFactory());.params - connection parameters.MTETransExecEx
in "ASTS Connectivity Guide" for more information on parameters returned.ClientException - if connection attempt failed.public void close()
close in interface AutoCloseablepublic void selectBoards(Set<String> boards) throws ClientException
Check MTESelectBoards() ASTS API documentation for details.
boards - set of boards to be seen by this client.ClientException - in case of ASTS remote call failure.IllegalStateException - if not connected.public final API.ServerInfo getServerInfo()
IllegalStateException - if not connected.@Deprecated public final Meta.Market getMarket()
getMarketInfo().IllegalStateException - if not connected.public final Meta.Market getMarketInfo()
IllegalStateException - if not connected.public final String getUserID()
IllegalStateException - if not connected.public final String getFirmID()
IllegalStateException - if not connected.public final int handle()
IllegalStateException - if not connected.public final int status()
MTEConnectionStatus.IllegalStateException - if not connected.public Parser load(String table, Map<String,Object> params) throws ClientException
MTEOpenTable(table, params, true)/MTECloseTable() from the main
ASTS API.
Note: if the table contains price fields and this client has yet no scale information this method will try to load SECURITIES behind the scenes (this operation may be time-intensive).
table - table name to be loaded.params - mapping of parameter names to theirs values or
Collections.emptyMap() if no
parameters are specified. Value types expected are exactly the same as
decoded by Filler.setFieldValue(com.micex.client.Meta.Field, java.lang.Object).IllegalStateException - if not connected.ClientException - if table is not listed or an API error occurs.public Parser open(String table, Map<String,Object> params, boolean complete) throws ClientException
Note: if the table contains price fields and this client has yet no scale information this method will load SECURITIES behind the scenes (this operation may be time-intensive).
table - table to be loaded.params - mapping of parameter names to theirs values or
Collections.emptyMap() if no
parameters are specified. Value types expected are exactly the same as
decoded by Filler.setFieldValue(com.micex.client.Meta.Field, java.lang.Object).complete - set true to request complete current data.
Should be avoided tables with a probably large amount
of data (like ORDERS, TRADES, ALL_TRADES). Forces all
the current data to be loaded at once. If set to false
the data of large tables will be fetched partially and
successive parts will be available from refresh() call.IllegalStateException - if not connected.ClientException - if table is not listed or an API error occurs.public Parser open(String table, Map<String,Object> params, byte[] snapshot) throws ClientException
Note: if the table contains price fields and this client has yet no scale information this method will load SECURITIES behind the scenes (this operation may be time-intensive).
table - table to be loaded.params - mapping of parameter names to theirs values or
Collections.emptyMap() if no
parameters are specified. Value types expected are exactly the same as
decoded by Filler.setFieldValue(com.micex.client.Meta.Field, java.lang.Object).snapshot - previous snapshot.IllegalStateException - if not connected.NullPointerException - if snapshot is null.ClientException - if table is not listed or an API error occurs.public Parser open(String table, String filter, byte[] snapshot) throws ClientException
table - table to be loaded.filter - request parameters encoded according to internal API rules.snapshot - previous snapshot.IllegalStateException - if not connected.NullPointerException - if snapshot is null.ClientException - if table is not listed or an API error occurs.public Parser refresh(Sorter sorter) throws ClientException
sorter - an optional customizer of the request list.IllegalStateException - if not connected.ClientException - if an API error occurs.public Parser refresh() throws ClientException
IllegalStateException - if not connected.ClientException - if an API error occurs.public byte[] getSnapshot()
throws ClientException
IllegalStateException - if not connected.ClientException - if an API error occurs.public void setSnapshot(byte[] buffer)
throws ClientException
Since v.1.2 completely restores an internal list of requests which are updated during refresh(). To restore selected requests only consider using getSnapshotInfo(byte[]) and open(java.lang.String, java.lang.String, byte[]).
buffer - previous snapshot.IllegalStateException - if not connected.NullPointerException - if buffer is null.ClientException - if an API error occurs.public List<Client.SnapshotEntry> getSnapshotInfo(byte[] snapshot) throws ClientException
snapshot - previous snapshot.IllegalStateException - if not connected.NullPointerException - if snapshot is null.ClientException - if an API error occurs.public Client.Report execute(String command, Map<String,Object> params) throws ClientException
Note: if transaction contains price fields and this client has yet no scale information this method will load SECURITIES behind the scenes (may take significant time to load and parse).
command - transaction name to execute.params - mapping of parameter names to theirs values. Passing null
means no parameters are specified. Value types expected are exactly the same as
decoded by Filler.setFieldValue(com.micex.client.Meta.Field, java.lang.Object).IllegalStateException - if not connected.ClientException - if transaction is not listed or an API error
occurs.perform(String, Map)public Client.ExtendedReport perform(String command, Map<String,Object> params) throws ClientException
command - transaction name to execute.params - mapping of parameter names to theirs values. Passing null
means no parameters are specified. Value types expected are exactly the same as
decoded by Filler.setFieldValue(com.micex.client.Meta.Field, java.lang.Object).IllegalStateException - if not connected.ClientException - if transaction is not listed or an API error
occurs.execute(String, Map)public static int getResponseCode(String message)
"(xxx) description",
this method extracts xxx.message - trading system response message.0 when no response code if found in message.