Metatrader 5 api java

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Java SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4)

License

agiliumtrade-ai/copyfactory-java-sdk

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

readme.md

CopyFactory trade copying API for Java (a member of metaapi.cloud project)

Note: The Java SDK was updated long time ago and lacks important bugfixes and updates. We plan to update the java SDK soon. Meanwhile we recommend you to use javascript or python SDK instead.

CopyFactory is a powerful copy trading API which makes developing forex trade copying applications as easy as writing few lines of code.

CopyFactory API is a member of MetaApi project (https://metaapi.cloud), a powerful cloud forex trading API which supports both MetaTrader 4 and MetaTrader 5 platforms.

MetaApi is a paid service, however API access to one MetaTrader account is free of charge.

The MetaApi pricing was developed with the intent to make your charges less or equal to what you would have to pay for hosting your own infrastructure. This is possible because over time we managed to heavily optimize our MetaTrader infrastructure. And with MetaApi you can save significantly on application development and maintenance costs and time thanks to high-quality API, open-source SDKs and convenience of a cloud service.

Читайте также:  Java crash log file

Why do we offer CopyFactory trade copying API

We found that developing reliable and flexible trade copier is a task which requires lots of effort, because developers have to solve a series of complex technical tasks to create a product.

We decided to share our product as it allows developers to start with a powerful solution in almost no time, saving on development and infrastructure maintenance costs.

Frequently asked questions (FAQ)

CopyFactory copy tradging API features

  • low latency trade copying API
  • reliable trade copying API
  • suitable for large-scale deployments
  • suitable for large number of subscribers
  • connect arbitrary number of strategy providers and subscribers
  • subscribe accounts to multiple strategies at once
  • select arbitrary copy ratio for each subscription
  • configure symbol mapping between strategy providers and subscribers
  • apply advanced risk filters on strategy provider side
  • override risk filters on subscriber side
  • provide multiple strategies from a single account based on magic or symbol filters
  • supports manual trading on subscriber accounts while copying trades
  • synchronize subscriber account with strategy providers
  • monitor trading history
  • calculate trade copying commissions for account managers
  • support portfolio strategies as trading signal source, i.e. the strategies which include signals of several other strategies (also known as combos on some platforms)

Please note that trade copying to MT5 netting accounts is not supported in the current API version

Please check Features section of the https://metaapi.cloud/docs/copyfactory/ documentation for detailed description of all settings you can make

CopyFactory SDK is built on top of CopyFactory REST API.

CopyFactory REST API docs are available at https://metaapi.cloud/docs/copyfactory/

If you use Apache Maven, add this to in your pom.xml :

dependency> groupId>cloud.metaapi.sdkgroupId> artifactId>metaapi-java-sdkartifactId> version>14.0.0version> dependency>

Other options can be found on this page.

We published some code examples in our github repository, namely:

Running Java SDK examples

In order to run Java SDK examples, follow these steps:

  1. Make sure that you have installed Maven and its command mvn is accessible.
  2. Navigate to the root folder of the example project (where its pom.xml is located).
  3. Build the project with mvn package .
  4. Run mvn exec:java@ ExampleClassName where ExampleClassName is the example to execute, e.g. mvn exec:java@CopyFactoryExample .

Example parameters such as token or account id can be passed via environment variables, or set directly in the example source code. In the last case you need to rebuild the example with mvn package .

Читайте также:  Logging java in docker

Please visit https://app.metaapi.cloud/token web UI to obtain your API token.

Configuring trade copying

In order to configure trade copying you need to:

  • add MetaApi MetaTrader accounts with CopyFactory as application field value (see above)
  • create CopyFactory master and slave accounts and connect them to MetaApi accounts via connectionId field
  • create a strategy being copied
  • subscribe slave CopyFactory accounts to the strategy
import cloud.metaapi.sdk.meta_api.MetaApi; import cloud.metaapi.sdk.copy_factory.CopyFactory; String token = ". "; MetaApi metaapi = new MetaApi(token); CopyFactory copyFactory = new CopyFactory(token); // retrieve MetaApi MetaTrader accounts with CopyFactory as application field value MetatraderAccount masterMetaapiAccount = metaapi.getMetatraderAccountApi().getAccount("masterMetaapiAccountId").get(); if (!masterMetaapiAccount.getApplication().equals("CopyFactory")) < throw new Exception("Please specify CopyFactory application field value in your MetaApi account in order to use it in CopyFactory API"); > MetatraderAccount slaveMetaapiAccount = metaapi.getMetatraderAccountApi().getAccount("slaveMetaapiAccountId").get(); if (!slaveMetaapiAccount.getApplication().equals("CopyFactory")) < throw new Exception("Please specify CopyFactory application field value in your MetaApi account in order to use it in CopyFactory API"); > // create CopyFactory master and slave accounts and connect them to MetaApi accounts via connectionId field ConfigurationClient configurationApi = copyFactory.getConfigurationApi(); String masterAccountId = configurationApi.generateAccountId(); String slaveAccountId = configurationApi.generateAccountId(); configurationApi.updateAccount(masterAccountId, new CopyFactoryAccountUpdate() name = "Demo account"; connectionId = masterMetaapiAccount.getId(); subscriptions = List.of(); >>).get(); // create a strategy being copied StrategyId strategyId = configurationApi.generateStrategyId().get(); configurationApi.updateStrategy(strategyId.id, new CopyFactoryStrategyUpdate() name = "Test strategy"; description = "Some useful description about your strategy"; positionLifecycle = "hedging"; connectionId = masterMetaapiAccount.getId(); maxTradeRisk = 0.1; stopOutRisk = new CopyFactoryStrategyStopOutRisk() value = 0.4; startTime = new IsoTime("2020-08-24T00:00:00.000Z"); >>, timeSettings = new CopyFactoryStrategyTimeSettings() lifetimeInHours = 192; openingIntervalInMinutes = 5; >> >>).get(); // subscribe slave CopyFactory accounts to the strategy configurationApi.updateAccount(slaveAccountId, new CopyFactoryAccountUpdate() name = "Demo account"; connectionId = slaveMetaapiAccount.getId(); subscriptions: List.of(new CopyFactoryStrategySubscription() strategyId = strategyId.id; multiplier = 1; >>) >>).get();

See jsdoc in-code documentation for full definition of possible configuration options.

Retrieving trade copying history

CopyFactory allows you to monitor transactions conducted on trading accounts in real time.

Retrieving trading history on provider side

HistoryClient historyApi = copyFactory.getHistoryApi(); // retrieve list of subscribers System.out.println(historyApi.getSubscribers().get()); // retrieve list of strategies provided System.out.println(historyApi.getProvidedStrategies().get()); // retrieve trading history, please note that this method support pagination and limits number of records System.out.println(historyApi.getProvidedStrategiesTransactions(new IsoTime("2020-08-01T00:00:00.000Z"), new IsoTime("2020-09-01T00:00:00.000Z")).get());

Retrieving trading history on subscriber side

Читайте также:  Python pytelegrambotapi callback кнопки

HistoryApi historyApi = copyFactory.getHistoryApi(); // retrieve list of providers System.out.println(historyApi.getProviders().get()); // retrieve list of strategies subscribed to System.out.println(historyApi.getStrategiesSubscribed().get()); // retrieve trading history, please note that this method support pagination and limits number of records System.out.println(historyApi.getStrategiesSubscribedTransactions(new IsoTime("2020-08-01T00:00:00.000Z"), new IsoTime("2020-09-01T00:00:00.000Z")).get());

Resynchronizing slave accounts to masters

There is a configurable time limit during which the trades can be opened. Sometimes trades can not open in time due to broker errors or trading session time discrepancy. You can resynchronize a slave account to place such late trades. Please note that positions which were closed manually on a slave account will also be reopened during resynchronization.

String accountId = ". "; // CopyFactory account id // resynchronize all strategies copyFactory.getTradingApi().resynchronize(accountId).get(); // resynchronize specific strategy copyFactory.tradingApi.resynchronize(accountId, List.of("ABCD")).get();

A subscription to a strategy can be stopped if the strategy have exceeded allowed risk limit.

TradingClient tradingApi = copyFactory.getTradingApi(); String accountId = ". "; // CopyFactory account id String strategyId = ". "; // CopyFactory strategy id // retrieve list of strategy stopouts System.out.println(tradingApi.getStopouts(accountId).get()); // reset a stopout so that subscription can continue tradingApi.resetStopout(accountId, strategyId, "daily-equity").get();

Retrieving slave trading logs

TradingClient tradingApi = copyFactory.getTradingApi(); String accountId = ". "; // CopyFactory account id // retrieve slave trading log System.out.println(tradingApi.getUserLog(accountId).get()); // retrieve paginated slave trading log by time range IsoTime from = new IsoTime(Date.from(Instant.now().minusSeconds(24 * 60 * 60))); System.out.println(tradingApi.getUserLog(accountId, from, null, 20, 10).get()); System.out.println(tradingApi.getUserLog(accountId, from, null, 20, 10).get());

Take a look at our website for the full list of APIs and features supported https://metaapi.cloud/#features

Some of the APIs you might decide to use together with MetaStats API are:

  1. MetaApi cloud forex API https://metaapi.cloud/docs/client/
  2. MetaTrader account management API https://metaapi.cloud/docs/provisioning/
  3. MetaStats forex trading metrics API https://metaapi.cloud/docs/metastats/

About

Java SDK for CopyFactory trade copying API. Can copy trades both between MetaTrader 5 (MT5) and MetaTrader 4 (MT4)

Источник

Оцените статью