public class MetaApiWebsocketClient extends Object
| Constructor and Description |
|---|
MetaApiWebsocketClient(String token)
Constructs MetaApi websocket API client instance.
|
MetaApiWebsocketClient(String token,
String domain,
long requestTimeout,
long connectTimeout)
Constructs MetaApi websocket API client instance
|
| Modifier and Type | Method and Description |
|---|---|
void |
addReconnectListener(ReconnectListener listener)
Adds reconnect listener
|
void |
addSynchronizationListener(String accountId,
SynchronizationListener listener)
Adds synchronization listener for specific account
|
void |
close()
Closes connection to MetaApi server
|
CompletableFuture<Void> |
connect()
Connects to MetaApi server via socket.io protocol
|
CompletableFuture<MetatraderAccountInformation> |
getAccountInformation(String accountId)
Returns account information for a specified MetaTrader account (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readAccountInformation/).
|
CompletableFuture<MetatraderDeals> |
getDealsByPosition(String accountId,
String positionId)
Returns history deals for a specific position id (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readDealsByPosition/).
|
CompletableFuture<MetatraderDeals> |
getDealsByTicket(String accountId,
String ticket)
Returns history deals with a specific ticket number (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readDealsByTicket/).
|
CompletableFuture<MetatraderDeals> |
getDealsByTimeRange(String accountId,
IsoTime startTime,
IsoTime endTime,
int offset,
int limit)
Returns history deals with for a specific time range (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readDealsByTimeRange/).
|
CompletableFuture<MetatraderHistoryOrders> |
getHistoryOrdersByPosition(String accountId,
String positionId)
Returns the history of completed orders for a specific position id (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readHistoryOrdersByPosition/)
|
CompletableFuture<MetatraderHistoryOrders> |
getHistoryOrdersByTicket(String accountId,
String ticket)
Returns the history of completed orders for a specific ticket number (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readHistoryOrdersByTicket/).
|
CompletableFuture<MetatraderHistoryOrders> |
getHistoryOrdersByTimeRange(String accountId,
IsoTime startTime,
IsoTime endTime,
int offset,
int limit)
Returns the history of completed orders for a specific time range (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readHistoryOrdersByTimeRange/).
|
CompletableFuture<MetatraderOrder> |
getOrder(String accountId,
String orderId)
Returns specific open order for a MetaTrader account (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readOrder/).
|
CompletableFuture<List<MetatraderOrder>> |
getOrders(String accountId)
Returns open orders for a specified MetaTrader account (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readOrders/).
|
CompletableFuture<MetatraderPosition> |
getPosition(String accountId,
String positionId)
Returns specific position for a MetaTrader account (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readPosition/).
|
CompletableFuture<List<MetatraderPosition>> |
getPositions(String accountId)
Returns positions for a specified MetaTrader account (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readPositions/).
|
CompletableFuture<MetatraderSymbolPrice> |
getSymbolPrice(String accountId,
String symbol)
Retrieves price for a symbol (see
https://metaapi.cloud/docs/client/websocket/api/retrieveMarketData/getSymbolPrice/).
|
CompletableFuture<MetatraderSymbolSpecification> |
getSymbolSpecification(String accountId,
String symbol)
Retrieves specification for a symbol (see
https://metaapi.cloud/docs/client/websocket/api/retrieveMarketData/getSymbolSpecification/).
|
CompletableFuture<Void> |
reconnect(String accountId)
Reconnects to the Metatrader terminal (see https://metaapi.cloud/docs/client/websocket/api/reconnect/).
|
void |
removeAllListeners()
Removes all listeners.
|
CompletableFuture<Void> |
removeHistory(String accountId)
Clears the order and transaction history of a specified account so that it can be synchronized from scratch (see
https://metaapi.cloud/docs/client/websocket/api/removeHistory/).
|
void |
removeReconnectListener(ReconnectListener listener)
Removes reconnect listener
|
void |
removeSynchronizationListener(String accountId,
SynchronizationListener listener)
Removes synchronization listener for specific account
|
void |
setUrl(String url)
Patch server URL for use in unit tests
|
CompletableFuture<Void> |
subscribe(String accountId)
Subscribes to the Metatrader terminal events (see https://metaapi.cloud/docs/client/websocket/api/subscribe/).
|
CompletableFuture<Void> |
subscribeToMarketData(String accountId,
String symbol)
Subscribes on market data of specified symbol (see
https://metaapi.cloud/docs/client/websocket/marketDataStreaming/subscribeToMarketData/).
|
CompletableFuture<Void> |
synchronize(String accountId,
String synchronizationId,
IsoTime startingHistoryOrderTime,
IsoTime startingDealTime)
Requests the terminal to start synchronization process
(see https://metaapi.cloud/docs/client/websocket/synchronizing/synchronize/).
|
CompletableFuture<MetatraderTradeResponse> |
trade(String accountId,
MetatraderTrade trade)
Execute a trade on a connected MetaTrader account (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
public MetaApiWebsocketClient(String token)
agiliumtrade.agiliumtrade.ai,
timeout for socket requests is 1 minute, timeout for connecting to server is 1 minute.token - authorization tokenpublic MetaApiWebsocketClient(String token, String domain, long requestTimeout, long connectTimeout)
token - authorization tokendomain - domain to connect torequestTimeout - timeout for socket requests in millisecondsconnectTimeout - timeout for connecting to server in millisecondspublic void setUrl(String url)
url - patched server URLpublic CompletableFuture<Void> connect()
public void close()
public CompletableFuture<MetatraderAccountInformation> getAccountInformation(String accountId)
accountId - id of the MetaTrader account to return information forpublic CompletableFuture<List<MetatraderPosition>> getPositions(String accountId)
accountId - id of the MetaTrader account to return information forpublic CompletableFuture<MetatraderPosition> getPosition(String accountId, String positionId)
accountId - id of the MetaTrader account to return information forpositionId - position idpublic CompletableFuture<List<MetatraderOrder>> getOrders(String accountId)
accountId - id of the MetaTrader account to return information forpublic CompletableFuture<MetatraderOrder> getOrder(String accountId, String orderId)
accountId - id of the MetaTrader account to return information fororderId - order id (ticket number)public CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByTicket(String accountId, String ticket)
accountId - id of the MetaTrader account to return information forticket - ticket number (order id)public CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByPosition(String accountId, String positionId)
accountId - id of the MetaTrader account to return information forpositionId - position idpublic CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByTimeRange(String accountId, IsoTime startTime, IsoTime endTime, int offset, int limit)
accountId - id of the MetaTrader account to return information forstartTime - start of time range, inclusiveendTime - end of time range, exclusiveoffset - pagination offsetlimit - pagination limitpublic CompletableFuture<MetatraderDeals> getDealsByTicket(String accountId, String ticket)
accountId - id of the MetaTrader account to return information forticket - ticket number (deal id for MT5 or order id for MT4)public CompletableFuture<MetatraderDeals> getDealsByPosition(String accountId, String positionId)
accountId - id of the MetaTrader account to return information forpositionId - position idpublic CompletableFuture<MetatraderDeals> getDealsByTimeRange(String accountId, IsoTime startTime, IsoTime endTime, int offset, int limit)
accountId - id of the MetaTrader account to return information forstartTime - start of time range, inclusiveendTime - end of time range, exclusiveoffset - pagination offsetlimit - pagination limitpublic CompletableFuture<Void> removeHistory(String accountId)
accountId - id of the MetaTrader account to remove history forpublic CompletableFuture<MetatraderTradeResponse> trade(String accountId, MetatraderTrade trade)
accountId - id of the MetaTrader account to execute trade fortrade - trade to execute (see docs for possible trade types)TradeException, check error properties for error code detailspublic CompletableFuture<Void> subscribe(String accountId)
accountId - id of the MetaTrader account to subscribe topublic CompletableFuture<Void> reconnect(String accountId)
accountId - id of the MetaTrader account to reconnectpublic CompletableFuture<Void> synchronize(String accountId, String synchronizationId, IsoTime startingHistoryOrderTime, IsoTime startingDealTime)
accountId - id of the MetaTrader account to synchronizesynchronizationId - synchronization request idstartingHistoryOrderTime - from what date to start synchronizing history orders from. If not specified,
the entire order history will be downloaded.startingDealTime - from what date to start deal synchronization from. If not specified, then all
history deals will be downloaded.public CompletableFuture<Void> subscribeToMarketData(String accountId, String symbol)
accountId - id of the MetaTrader accountsymbol - symbol (e.g. currency pair or an index)public CompletableFuture<MetatraderSymbolSpecification> getSymbolSpecification(String accountId, String symbol)
accountId - id of the MetaTrader account to retrieve symbol specification forsymbol - symbol to retrieve specification forpublic CompletableFuture<MetatraderSymbolPrice> getSymbolPrice(String accountId, String symbol)
accountId - id of the MetaTrader account to retrieve symbol price forsymbol - symbol to retrieve price forpublic void addSynchronizationListener(String accountId, SynchronizationListener listener)
accountId - account idlistener - synchronization listener to addpublic void removeSynchronizationListener(String accountId, SynchronizationListener listener)
accountId - account idlistener - synchronization listener to removepublic void addReconnectListener(ReconnectListener listener)
listener - reconnect listener to addpublic void removeReconnectListener(ReconnectListener listener)
listener - listener to removepublic void removeAllListeners()
Copyright © 2020. All rights reserved.