public class MetaApiConnection extends SynchronizationListener implements ReconnectListener
SynchronizationListener.HealthStatus| Constructor and Description |
|---|
MetaApiConnection(MetaApiWebsocketClient websocketClient,
MetatraderAccount account,
HistoryStorage historyStorage,
ConnectionRegistry connectionRegistry)
Constructs MetaApi MetaTrader Api connection
|
MetaApiConnection(MetaApiWebsocketClient websocketClient,
MetatraderAccount account,
HistoryStorage historyStorage,
ConnectionRegistry connectionRegistry,
IsoTime historyStartTime)
Constructs MetaApi MetaTrader Api connection
|
| Modifier and Type | Method and Description |
|---|---|
void |
addSynchronizationListener(SynchronizationListener listener)
Adds synchronization listener
|
CompletableFuture<MetatraderTradeResponse> |
cancelOrder(String orderId)
Cancels order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<Void> |
close()
Closes the connection.
|
CompletableFuture<MetatraderTradeResponse> |
closeBy(String positionId,
String oppositePositionId,
MarketTradeOptions options)
Fully closes a position (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
closePosition(String positionId,
MarketTradeOptions options)
Fully closes a position (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
closePositionPartially(String positionId,
double volume,
MarketTradeOptions options)
Partially closes a position (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
closePositionsBySymbol(String symbol,
MarketTradeOptions options)
Closes position by a symbol (see https://metaapi.cloud/docs/client/websocket/api/trade/)
|
CompletableFuture<MetatraderTradeResponse> |
createLimitBuyOrder(String symbol,
double volume,
double openPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a limit buy order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createLimitSellOrder(String symbol,
double volume,
double openPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a limit sell order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createMarketBuyOrder(String symbol,
double volume,
Double stopLoss,
Double takeProfit,
MarketTradeOptions options)
Creates a market buy order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createMarketSellOrder(String symbol,
double volume,
Double stopLoss,
Double takeProfit,
MarketTradeOptions options)
Creates a market sell order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createStopBuyOrder(String symbol,
double volume,
double openPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a stop buy order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createStopLimitBuyOrder(String symbol,
double volume,
double openPrice,
double stopLimitPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a stop limit buy order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createStopLimitSellOrder(String symbol,
double volume,
double openPrice,
double stopLimitPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a stop limit sell order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
createStopSellOrder(String symbol,
double volume,
double openPrice,
Double stopLoss,
Double takeProfit,
PendingTradeOptions options)
Creates a stop sell order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
MetatraderAccount |
getAccount()
Returns MetaApi account
|
CompletableFuture<MetatraderAccountInformation> |
getAccountInformation()
Returns account information (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readAccountInformation/).
|
CompletableFuture<MetatraderDeals> |
getDealsByPosition(String positionId)
Returns history deals for a specific position id (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readDealsByPosition/).
|
CompletableFuture<MetatraderDeals> |
getDealsByTicket(String ticket)
Returns history deals with a specific ticket number (see
https://metaapi.cloud/docs/client/websocket/api/retrieveHistoricalData/readDealsByTicket/).
|
CompletableFuture<MetatraderDeals> |
getDealsByTimeRange(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/).
|
ConnectionHealthMonitor |
getHealthMonitor()
Returns connection health monitor instance
|
CompletableFuture<MetatraderHistoryOrders> |
getHistoryOrdersByPosition(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 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(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/)
|
HistoryStorage |
getHistoryStorage()
Returns local history storage
|
CompletableFuture<MetatraderOrder> |
getOrder(String orderId)
Returns specific open order (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readOrder/).
|
CompletableFuture<List<MetatraderOrder>> |
getOrders()
Returns open orders (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readOrders/).
|
CompletableFuture<MetatraderPosition> |
getPosition(String positionId)
Returns specific position (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readPosition/).
|
CompletableFuture<List<MetatraderPosition>> |
getPositions()
Returns positions (see
https://metaapi.cloud/docs/client/websocket/api/readTradingTerminalState/readPositions/).
|
List<String> |
getSubscribedSymbols()
Returns list of the symbols connection is subscribed to
|
CompletableFuture<MetatraderSymbolPrice> |
getSymbolPrice(String symbol)
Retrieves specification for a symbol (see
https://metaapi.cloud/docs/client/websocket/api/retrieveMarketData/getSymbolPrice/).
|
CompletableFuture<MetatraderSymbolSpecification> |
getSymbolSpecification(String symbol)
Retrieves specification for a symbol (see
https://metaapi.cloud/docs/client/websocket/api/retrieveMarketData/getSymbolSpecification/).
|
TerminalState |
getTerminalState()
Returns local copy of terminal state
|
CompletableFuture<Void> |
initialize()
Initializes meta api connection
|
boolean |
isSynchronized()
Returns synchronization status
|
CompletableFuture<Boolean> |
isSynchronized(Integer instanceIndex,
String synchronizationId)
Returns flag indicating status of state synchronization with MetaTrader terminal
|
CompletableFuture<MetatraderTradeResponse> |
modifyOrder(String orderId,
double openPrice,
double stopLoss,
double takeProfit)
Modifies a pending order (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<MetatraderTradeResponse> |
modifyPosition(String positionId,
Double stopLoss,
Double takeProfit)
Modifies a position (see https://metaapi.cloud/docs/client/websocket/api/trade/).
|
CompletableFuture<Void> |
onConnected(int instanceIndex,
int replicas)
Invoked when connection to MetaTrader terminal established
|
CompletableFuture<Void> |
onDealSynchronizationFinished(int instanceIndex,
String synchronizationId)
Invoked when a synchronization of history deals on a MetaTrader account have finished
|
CompletableFuture<Void> |
onDisconnected(int instanceIndex)
Invoked when connection to MetaTrader terminal terminated
|
CompletableFuture<Void> |
onOrderSynchronizationFinished(int instanceIndex,
String synchronizationId)
Invoked when a synchronization of history orders on a MetaTrader account have finished
|
CompletableFuture<Void> |
onReconnected()
Invoked when connection to MetaTrader terminal re-established
|
CompletableFuture<Void> |
reconnect()
Reconnects to the Metatrader terminal (see https://metaapi.cloud/docs/client/websocket/api/reconnect/).
|
CompletableFuture<Void> |
removeApplication()
Clears the order and transaction history of a specified application and removes application (see
https://metaapi.cloud/docs/client/websocket/api/removeApplication/).
|
CompletableFuture<Void> |
removeHistory()
Clears the order and transaction history of a specified application so that it can be synchronized from scratch
(see https://metaapi.cloud/docs/client/websocket/api/removeHistory/).
|
CompletableFuture<Void> |
removeHistory(String application)
Clears the order and transaction history of a specified application so that it can be synchronized from scratch
(see https://metaapi.cloud/docs/client/websocket/api/removeHistory/).
|
void |
removeSynchronizationListener(SynchronizationListener listener)
Removes synchronization listener for specific account
|
CompletableFuture<Void> |
saveUptime(Map<String,Double> uptime)
Sends client uptime stats to the server.
|
CompletableFuture<Void> |
subscribe()
Initiates subscription to MetaTrader terminal
|
CompletableFuture<Void> |
subscribeToMarketData(String symbol,
int instanceIndex)
Subscribes on market data of specified symbol (see
https://metaapi.cloud/docs/client/websocket/marketDataStreaming/subscribeToMarketData/).
|
CompletableFuture<Void> |
synchronize(int instanceIndex)
Requests the terminal to start synchronization process
(see https://metaapi.cloud/docs/client/websocket/synchronizing/synchronize/)
|
CompletableFuture<Void> |
unsubscribeFromMarketData(String symbol,
int instanceIndex)
Unsubscribes from market data of specified symbol (see
https://metaapi.cloud/docs/client/websocket/marketDataStreaming/unsubscribeFromMarketData/).
|
CompletableFuture<Void> |
waitSynchronized()
Waits until synchronization to MetaTrader terminal is completed.
|
CompletableFuture<Void> |
waitSynchronized(SynchronizationOptions options)
Waits until synchronization to MetaTrader terminal is completed.
|
onAccountInformationUpdated, onBrokerConnectionStatusChanged, onDealAdded, onHealthStatus, onHistoryOrderAdded, onOrderCompleted, onOrdersReplaced, onOrderUpdated, onPositionRemoved, onPositionsReplaced, onPositionUpdated, onSymbolPricesUpdated, onSymbolPriceUpdated, onSymbolSpecificationUpdated, onSynchronizationStartedpublic MetaApiConnection(MetaApiWebsocketClient websocketClient, MetatraderAccount account, HistoryStorage historyStorage, ConnectionRegistry connectionRegistry)
websocketClient - MetaApi websocket clientaccount - MetaTrader account to connect tohistoryStorage - terminal history storage or null.
By default an instance of MemoryHistoryStorage will be used.connectionRegistry - metatrader account connection registrypublic MetaApiConnection(MetaApiWebsocketClient websocketClient, MetatraderAccount account, HistoryStorage historyStorage, ConnectionRegistry connectionRegistry, IsoTime historyStartTime)
websocketClient - MetaApi websocket clientaccount - MetaTrader account to connect tohistoryStorage - terminal history storage or null.
By default an instance of MemoryHistoryStorage will be used.connectionRegistry - metatrader account connection registryhistoryStartTime - history start sync time, or nullpublic CompletableFuture<MetatraderAccountInformation> getAccountInformation()
public CompletableFuture<List<MetatraderPosition>> getPositions()
public CompletableFuture<MetatraderPosition> getPosition(String positionId)
positionId - position idpublic CompletableFuture<List<MetatraderOrder>> getOrders()
public CompletableFuture<MetatraderOrder> getOrder(String orderId)
orderId - order id (ticket number)public CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByTicket(String ticket)
ticket - ticket number (order id)public CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByPosition(String positionId)
positionId - position idpublic CompletableFuture<MetatraderHistoryOrders> getHistoryOrdersByTimeRange(IsoTime startTime, IsoTime endTime, int offset, int limit)
startTime - start of time range, inclusiveendTime - end of time range, exclusiveoffset - pagination offsetlimit - pagination limitpublic CompletableFuture<MetatraderDeals> getDealsByTicket(String ticket)
ticket - ticket number (deal id for MT5 or order id for MT4)public CompletableFuture<MetatraderDeals> getDealsByPosition(String positionId)
positionId - position idpublic CompletableFuture<MetatraderDeals> getDealsByTimeRange(IsoTime startTime, IsoTime endTime, int offset, int limit)
startTime - start of time range, inclusiveendTime - end of time range, exclusiveoffset - pagination offsetlimit - pagination limitpublic CompletableFuture<Void> removeHistory()
public CompletableFuture<Void> removeHistory(String application)
application - application to remove history for, or nullpublic CompletableFuture<Void> removeApplication()
public CompletableFuture<MetatraderTradeResponse> createMarketBuyOrder(String symbol, double volume, Double stopLoss, Double takeProfit, MarketTradeOptions options)
symbol - symbol to tradevolume - order volumestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createMarketSellOrder(String symbol, double volume, Double stopLoss, Double takeProfit, MarketTradeOptions options)
symbol - symbol to tradevolume - order volumestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createLimitBuyOrder(String symbol, double volume, double openPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order limit pricestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createLimitSellOrder(String symbol, double volume, double openPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order limit pricestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createStopBuyOrder(String symbol, double volume, double openPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order stop pricestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createStopSellOrder(String symbol, double volume, double openPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order stop pricestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nulloptions - optional trade options or nullTradeException, check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createStopLimitBuyOrder(String symbol, double volume, double openPrice, double stopLimitPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order stop pricestopLimitPrice - the limit order price for the stop limit orderstopLoss - stop loss price, or nulltakeProfit - take profit price, or nulloptions - trade options, or nullTradeException, check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> createStopLimitSellOrder(String symbol, double volume, double openPrice, double stopLimitPrice, Double stopLoss, Double takeProfit, PendingTradeOptions options)
symbol - symbol to tradevolume - order volumeopenPrice - order stop pricestopLimitPrice - the limit order price for the stop limit orderstopLoss - stop loss price, or nulltakeProfit - take profit price, or nulloptions - trade options, or nullTradeException, check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> modifyPosition(String positionId, Double stopLoss, Double takeProfit)
positionId - position id to modifystopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> closePositionPartially(String positionId, double volume, MarketTradeOptions options)
positionId - position id to modifyvolume - volume to closeoptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> closePosition(String positionId, MarketTradeOptions options)
positionId - position id to modifyoptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> closeBy(String positionId, String oppositePositionId, MarketTradeOptions options)
positionId - position id to close by opposite positionoppositePositionId - opposite position id to closeoptions - optional trade options, or nullTradeException, check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> closePositionsBySymbol(String symbol, MarketTradeOptions options)
symbol - symbol to tradeoptions - optional trade options or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> modifyOrder(String orderId, double openPrice, double stopLoss, double takeProfit)
orderId - order id (ticket number)openPrice - order stop pricestopLoss - optional stop loss price or nulltakeProfit - optional take profit price or nullTradeException,
check error properties for error code detailspublic CompletableFuture<MetatraderTradeResponse> cancelOrder(String orderId)
orderId - order id (ticket number)TradeException,
check error properties for error code detailspublic CompletableFuture<Void> reconnect()
public CompletableFuture<Void> synchronize(int instanceIndex)
instanceIndex - instance indexpublic CompletableFuture<Void> initialize()
public CompletableFuture<Void> subscribe()
public CompletableFuture<Void> subscribeToMarketData(String symbol, int instanceIndex)
symbol - symbol (e.g. currency pair or an index)instanceIndex - instance indexpublic CompletableFuture<Void> unsubscribeFromMarketData(String symbol, int instanceIndex)
symbol - symbol (e.g. currency pair or an index)instanceIndex - instance indexpublic List<String> getSubscribedSymbols()
public CompletableFuture<MetatraderSymbolSpecification> getSymbolSpecification(String symbol)
symbol - symbol to retrieve specification forpublic CompletableFuture<MetatraderSymbolPrice> getSymbolPrice(String symbol)
symbol - symbol to retrieve price forpublic CompletableFuture<Void> saveUptime(Map<String,Double> uptime)
uptime - uptime statistics to send to the serverpublic TerminalState getTerminalState()
public HistoryStorage getHistoryStorage()
public void addSynchronizationListener(SynchronizationListener listener)
listener - synchronization listener to addpublic void removeSynchronizationListener(SynchronizationListener listener)
listener - synchronization listener to removepublic CompletableFuture<Void> onConnected(int instanceIndex, int replicas)
SynchronizationListeneronConnected in class SynchronizationListenerinstanceIndex - index of an account instance connectedreplicas - number of account replicas launchedpublic CompletableFuture<Void> onDisconnected(int instanceIndex)
SynchronizationListeneronDisconnected in class SynchronizationListenerinstanceIndex - index of an account instance connectedpublic CompletableFuture<Void> onDealSynchronizationFinished(int instanceIndex, String synchronizationId)
SynchronizationListeneronDealSynchronizationFinished in class SynchronizationListenerinstanceIndex - index of an account instance connectedsynchronizationId - synchronization request idpublic CompletableFuture<Void> onOrderSynchronizationFinished(int instanceIndex, String synchronizationId)
SynchronizationListeneronOrderSynchronizationFinished in class SynchronizationListenerinstanceIndex - index of an account instance connectedsynchronizationId - synchronization request idpublic CompletableFuture<Void> onReconnected()
ReconnectListeneronReconnected in interface ReconnectListenerpublic CompletableFuture<Boolean> isSynchronized(Integer instanceIndex, String synchronizationId)
instanceIndex - index of an account instance connectedsynchronizationId - optional synchronization request id, last synchronization
request id will be used by defaultpublic CompletableFuture<Void> waitSynchronized()
public CompletableFuture<Void> waitSynchronized(SynchronizationOptions options)
options - synchronization options, or nullpublic CompletableFuture<Void> close()
public boolean isSynchronized()
public MetatraderAccount getAccount()
public ConnectionHealthMonitor getHealthMonitor()
Copyright © 2021. All rights reserved.