Package cloud.metaapi.sdk.meta_api
Class MetatraderAccount
- java.lang.Object
-
- cloud.metaapi.sdk.meta_api.MetatraderAccount
-
public class MetatraderAccount extends Object
Implements a MetaTrader account entity
-
-
Constructor Summary
Constructors Constructor Description MetatraderAccount(MetatraderAccountDto data, MetatraderAccountClient metatraderAccountClient, MetaApiWebsocketClient metaApiWebsocketClient, ConnectionRegistry connectionRegistry)Constructs a MetaTrader account entity
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<MetaApiConnection>connect()Connects to MetaApi with default history storage.CompletableFuture<MetaApiConnection>connect(HistoryStorage historyStorage)Connects to MetaApi.CompletableFuture<Void>deploy()Schedules account for deployment.StringgetAccessToken()Returns authorization access token to be used for accessing single account data.StringgetApplication()Returns application name to connect the account to.MetatraderAccountDto.ConnectionStatusgetConnectionStatus()Returns terminal & broker connection statusStringgetId()Returns account idStringgetLogin()Returns account loginintgetMagic()Returns MetaTrader magic to place trades usingStringgetName()Returns account nameStringgetProvisioningProfileId()Returns id of the account's provisioning profileStringgetServer()Returns MetaTrader server which hosts the accountMetatraderAccountDto.DeploymentStategetState()Returns account deployment stateStringgetTimeConverter()Returns algorithm used to parse your broker timezone.StringgetType()Returns account type.booleanisManualTrades()Returns flag indicating if trades should be placed as manual trades on this accountCompletableFuture<Void>redeploy()Schedules account for redeployment.CompletableFuture<Void>reload()Reloads MetaTrader account from APICompletableFuture<Void>remove()Removes MetaTrader account.CompletableFuture<Void>undeploy()Schedules account for undeployment.CompletableFuture<Void>update(MetatraderAccountUpdateDto account)Updates MetaTrader account dataCompletableFuture<Void>waitConnected()Waits until API server has connected to the terminal and terminal has connected to the broker.CompletableFuture<Void>waitConnected(Integer timeoutInSeconds, Integer intervalInMilliseconds)Waits until API server has connected to the terminal and terminal has connected to the broker.CompletableFuture<Void>waitDeployed(Integer timeoutInSeconds, Integer intervalInMilliseconds)Waits until API server has finished deployment and account reached the DEPLOYED state.CompletableFuture<Void>waitRemoved(Integer timeoutInSeconds, Integer intervalInMilliseconds)Waits until account has been deleted.CompletableFuture<Void>waitUndeployed(Integer timeoutInSeconds, Integer intervalInMilliseconds)Waits until API server has finished undeployment and account reached the UNDEPLOYED state.
-
-
-
Constructor Detail
-
MetatraderAccount
public MetatraderAccount(MetatraderAccountDto data, MetatraderAccountClient metatraderAccountClient, MetaApiWebsocketClient metaApiWebsocketClient, ConnectionRegistry connectionRegistry)
Constructs a MetaTrader account entity- Parameters:
data- MetaTrader account datametatraderAccountClient- MetaTrader account REST API clientmetaApiWebsocketClient- MetaApi websocket clientconnectionRegistry- metatrader account connection registry
-
-
Method Detail
-
getId
public String getId()
Returns account id- Returns:
- account id
-
getName
public String getName()
Returns account name- Returns:
- account name
-
getType
public String getType()
Returns account type. Possible values are cloud and self-hosted.- Returns:
- account type
-
getLogin
public String getLogin()
Returns account login- Returns:
- account login
-
getServer
public String getServer()
Returns MetaTrader server which hosts the account- Returns:
- MetaTrader server which hosts the account
-
getProvisioningProfileId
public String getProvisioningProfileId()
Returns id of the account's provisioning profile- Returns:
- id of the account's provisioning profile
-
getTimeConverter
public String getTimeConverter()
Returns algorithm used to parse your broker timezone. Supported values are icmarkets for America/New_York DST switch and roboforex for EET DST switch (the values will be changed soon)- Returns:
- algorithm used to parse your broker timezone
-
getApplication
public String getApplication()
Returns application name to connect the account to. Currently allowed values are MetaApi and AgiliumTrade- Returns:
- application name to connect the account to
-
getMagic
public int getMagic()
Returns MetaTrader magic to place trades using- Returns:
- MetaTrader magic to place trades using
-
getState
public MetatraderAccountDto.DeploymentState getState()
Returns account deployment state- Returns:
- account deployment state
-
getConnectionStatus
public MetatraderAccountDto.ConnectionStatus getConnectionStatus()
Returns terminal & broker connection status- Returns:
- terminal & broker connection status
-
getAccessToken
public String getAccessToken()
Returns authorization access token to be used for accessing single account data. Intended to be used in browser API.- Returns:
- authorization token
-
isManualTrades
public boolean isManualTrades()
Returns flag indicating if trades should be placed as manual trades on this account- Returns:
- flag indicating if trades should be placed as manual trades on this account
-
reload
public CompletableFuture<Void> reload()
Reloads MetaTrader account from API- Returns:
- completable future resolving when MetaTrader account is updated
-
remove
public CompletableFuture<Void> remove()
Removes MetaTrader account. Cloud account transitions to DELETING state. It takes some time for an account to be eventually deleted. Self-hosted account is deleted immediately.- Returns:
- completable future resolving when account is scheduled for deletion
-
deploy
public CompletableFuture<Void> deploy()
Schedules account for deployment. It takes some time for API server to be started and account to reach the DEPLOYED state
-
undeploy
public CompletableFuture<Void> undeploy()
Schedules account for undeployment. It takes some time for API server to be stopped and account to reach the UNDEPLOYED state
-
redeploy
public CompletableFuture<Void> redeploy()
Schedules account for redeployment. It takes some time for API server to be restarted and account to reach the DEPLOYED state
-
waitDeployed
public CompletableFuture<Void> waitDeployed(Integer timeoutInSeconds, Integer intervalInMilliseconds)
Waits until API server has finished deployment and account reached the DEPLOYED state. Completes exceptionally withTimeoutExceptionif account have not reached the DEPLOYED state withing timeout allowed.- Parameters:
timeoutInSeconds- optional wait timeout in seconds, default is 5mintervalInMilliseconds- optional interval between account reloads while waiting for a change, default is 1s- Returns:
- completable future which resolves when account is deployed
-
waitUndeployed
public CompletableFuture<Void> waitUndeployed(Integer timeoutInSeconds, Integer intervalInMilliseconds)
Waits until API server has finished undeployment and account reached the UNDEPLOYED state. Completes exceptionally withTimeoutExceptionif account have not reached the UNDEPLOYED state withing timeout allowed.- Parameters:
timeoutInSeconds- optional wait timeout in seconds, default is 5mintervalInMilliseconds- optional interval between account reloads while waiting for a change, default is 1s- Returns:
- completable future which resolves when account is undeployed
-
waitRemoved
public CompletableFuture<Void> waitRemoved(Integer timeoutInSeconds, Integer intervalInMilliseconds)
Waits until account has been deleted. Completes exceptionally withTimeoutExceptionif account was not deleted withing timeout allowed.- Parameters:
timeoutInSeconds- optional wait timeout in seconds, default is 5mintervalInMilliseconds- optional interval between account reloads while waiting for a change, default is 1s- Returns:
- completable future which resolves when account is deleted
-
waitConnected
public CompletableFuture<Void> waitConnected()
Waits until API server has connected to the terminal and terminal has connected to the broker. Completes exceptionally withTimeoutExceptionif account have not connected to the broker withing timeout allowed. Wait timeout in seconds is 5m and interval between account reloads while waiting for a change is 1s.- Returns:
- completable future which resolves when API server is connected to the broker
-
waitConnected
public CompletableFuture<Void> waitConnected(Integer timeoutInSeconds, Integer intervalInMilliseconds)
Waits until API server has connected to the terminal and terminal has connected to the broker. Completes exceptionally withTimeoutExceptionif account have not connected to the broker withing timeout allowed.- Parameters:
timeoutInSeconds- optional wait timeout in seconds, default is 5mintervalInMilliseconds- optional interval between account reloads while waiting for a change, default is 1s- Returns:
- completable future which resolves when API server is connected to the broker
-
connect
public CompletableFuture<MetaApiConnection> connect()
Connects to MetaApi with default history storage. There is only one connection per account. Subsequent calls to this method will return the same connection.
-
connect
public CompletableFuture<MetaApiConnection> connect(HistoryStorage historyStorage)
Connects to MetaApi. There is only one connection per account. Subsequent calls to this method will return the same connection.- Parameters:
historyStorage- optional history storage
-
update
public CompletableFuture<Void> update(MetatraderAccountUpdateDto account)
Updates MetaTrader account data- Parameters:
account- MetaTrader account update- Returns:
- completable future resolving when account is updated
-
-