Skip to content

Commit

Permalink
Synchronize with node.js sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanKisilenko committed Mar 22, 2021
2 parents f5b0f79 + 835bbfd commit 22ee6da
Show file tree
Hide file tree
Showing 8 changed files with 1,286 additions and 1,093 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ If you use Apache Maven, add this to `<dependencies>` in your `pom.xml`:
<dependency>
<groupId>cloud.metaapi.sdk</groupId>
<artifactId>copyfactory-java-sdk</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</dependency>
```

Expand All @@ -67,7 +67,7 @@ We published some code examples in our github repository, namely:

- Java: [https://github.com/agiliumtrade-ai/copyfactory-java-sdk/tree/master/examples](https://github.com/agiliumtrade-ai/copyfactory-java-sdk/tree/master/examples)

Other options can be found on [this page](https://search.maven.org/artifact/cloud.metaapi.sdk/copyfactory-java-sdk/1.0.0/jar).
Other options can be found on [this page](https://search.maven.org/artifact/cloud.metaapi.sdk/copyfactory-java-sdk/1.1.0/jar).

### Running Java SDK examples
In order to run Java SDK examples, follow these steps:
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
1.1.0
- Added API to retrieve account / strategy / portfolio strategy by id

1.0.0
- CopyFactory SDK is now a separate repository/module, migrated from metaapi.cloud javascript SDK
2 changes: 1 addition & 1 deletion examples/copytrade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<dependency>
<groupId>cloud.metaapi.sdk</groupId>
<artifactId>copyfactory-java-sdk</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

<groupId>cloud.metaapi.sdk</groupId>
<artifactId>copyfactory-java-sdk</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
<description>Java SDK for SDK for CopyFactory trade copying API. Can copy trades both
beetween MetaTrader 5 (MT5) and MetaTrader 4 (MT4). (https://metaapi.cloud)</description>
between MetaTrader 5 (MT5) and MetaTrader 4 (MT4). (https://metaapi.cloud)</description>
<url>https://metaapi.cloud</url>

<licenses>
Expand Down

Large diffs are not rendered by default.

382 changes: 191 additions & 191 deletions src/main/java/cloud/metaapi/sdk/clients/copy_factory/HistoryClient.java

Large diffs are not rendered by default.

231 changes: 115 additions & 116 deletions src/main/java/cloud/metaapi/sdk/clients/copy_factory/TradingClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,124 +13,123 @@

/**
* metaapi.cloud CopyFactory trading API (trade copying trading API) client (see
* https://trading-api-v1.project-stock.agiliumlabs.cloud/swagger/#/)
* https://metaapi.cloud/docs/copyfactory/)
*/
public class TradingClient extends MetaApiClient {

/**
* Constructs CopyFactory trading API client instance. Domain is set to {@code agiliumtrade.agiliumtrade.ai}
* @param httpClient HTTP client
* @param token authorization token
*/
public TradingClient(HttpClient httpClient, String token) {
this(httpClient, token, "agiliumtrade.agiliumtrade.ai");
}
/**
* Constructs CopyFactory trading API client instance. Domain is set to {@code agiliumtrade.agiliumtrade.ai}
* @param httpClient HTTP client
* @param token authorization token
*/
public TradingClient(HttpClient httpClient, String token) {
this(httpClient, token, "agiliumtrade.agiliumtrade.ai");
}

/**
* Constructs CopyFactory trading API client instance
* @param httpClient HTTP client
* @param token authorization token
* @param domain domain to connect to
*/
public TradingClient(HttpClient httpClient, String token, String domain) {
super(httpClient, token, domain);
this.host = "https://trading-api-v1." + domain;
}

/**
* Resynchronizes the account. See
* https://trading-api-v1.agiliumtrade.agiliumtrade.ai/swagger/#!/default/post_users_current_accounts_accountId_resynchronize
* @param accountId account id
* @param strategyIds optional array of strategy ids to recynchronize, or {@code null}.
* Default is to synchronize all strategies
* @return completable future which resolves when resynchronization is scheduled
*/
public CompletableFuture<Void> resynchronize(String accountId, List<String> strategyIds) {
if (isNotJwtToken()) return handleNoAccessError("resynchronize");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/resynchronize", Method.POST);
opts.getHeaders().put("auth-token", token);
if (strategyIds != null && !strategyIds.isEmpty()) opts.getQueryParameters().put("strategyId", strategyIds);
return httpClient.request(opts).thenApply(response -> null);
}

/**
* Returns subscriber account stopouts. See
* https://trading-api-v1.agiliumtrade.agiliumtrade.ai/swagger/#!/default/get_users_current_accounts_accountId_stopouts
* @param accountId account id
* @return completable future which resolves with stopouts found
*/
public CompletableFuture<List<CopyFactoryStrategyStopout>> getStopouts(String accountId) {
if (isNotJwtToken()) return handleNoAccessError("getStopouts");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/stopouts", Method.GET);
opts.getHeaders().put("auth-token", token);
return httpClient.requestJson(opts, CopyFactoryStrategyStopout[].class)
.thenApply((array) -> Arrays.asList(array));
}

/**
* Resets strategy stopouts. See
* https://trading-api-v1.agiliumtrade.agiliumtrade.ai/swagger/#!/default/post_users_current_accounts_accountId_
* strategies_subscribed_strategyId_stopouts_reason_reset
* @param accountId account id
* @param strategyId strategy id
* @param reason stopout reason to reset. One of yearly-balance, monthly-balance, daily-balance,
* yearly-equity, monthly-equity, daily-equity, max-drawdown
* @return completable future which resolves when the stopouts are reset
*/
public CompletableFuture<Void> resetStopouts(String accountId, String strategyId, String reason) {
if (isNotJwtToken()) return handleNoAccessError("resetStopouts");
HttpRequestOptions opts = new HttpRequestOptions(host + "/users/current/accounts/" + accountId
+ "/strategies-subscribed/" + strategyId + "/stopouts/" + reason + "/reset", Method.POST);
opts.getHeaders().put("auth-token", token);
return httpClient.request(opts).thenApply(response -> null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://trading-api-v1.project-stock.v2.agiliumlabs.cloud/swagger/#!/default/get_users_current_accounts_accountId_user_log
* @param accountId account id
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId) {
return getUserLog(accountId, null, null, null, null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://trading-api-v1.project-stock.v2.agiliumlabs.cloud/swagger/#!/default/get_users_current_accounts_accountId_user_log
* @param accountId account id
* @param startTime time to start loading data from, or {@code null}
* @param endTime time to stop loading data at, or {@code null}
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId,
IsoTime startTime, IsoTime endTime) {
return getUserLog(accountId, startTime, endTime, null, null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://trading-api-v1.agiliumtrade.agiliumtrade.ai/swagger/#!/default/get_users_current_accounts_accountId_user_log
* @param accountId account id
* @param startTime time to start loading data from, or {@code null}
* @param endTime time to stop loading data at, or {@code null}
* @param offset pagination offset, or {@code null}. Default is 0
* @param limit pagination limit, or {@code null}. Default is 1000
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId,
IsoTime startTime, IsoTime endTime, Integer offset, Integer limit) {
if (isNotJwtToken()) return handleNoAccessError("getUserLog");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/user-log", Method.GET);
opts.getHeaders().put("auth-token", token);
if (startTime != null) opts.getQueryParameters().put("startTime", startTime);
if (endTime != null) opts.getQueryParameters().put("endTime", endTime);
if (offset != null) opts.getQueryParameters().put("offset", offset);
if (limit != null) opts.getQueryParameters().put("limit", limit);
return httpClient.requestJson(opts, CopyFactoryUserLogRecord[].class)
.thenApply((array) -> Arrays.asList(array));
}
/**
* Constructs CopyFactory trading API client instance
* @param httpClient HTTP client
* @param token authorization token
* @param domain domain to connect to
*/
public TradingClient(HttpClient httpClient, String token, String domain) {
super(httpClient, token, domain);
this.host = "https://trading-api-v1." + domain;
}

/**
* Resynchronizes the account. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/resynchronize/
* @param accountId account id
* @param strategyIds optional array of strategy ids to recynchronize, or {@code null}.
* Default is to synchronize all strategies
* @return completable future which resolves when resynchronization is scheduled
*/
public CompletableFuture<Void> resynchronize(String accountId, List<String> strategyIds) {
if (isNotJwtToken()) return handleNoAccessError("resynchronize");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/resynchronize", Method.POST);
opts.getHeaders().put("auth-token", token);
if (strategyIds != null && !strategyIds.isEmpty()) opts.getQueryParameters().put("strategyId", strategyIds);
return httpClient.request(opts).thenApply(response -> null);
}

/**
* Returns subscriber account stopouts. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/getStopOuts/
* @param accountId account id
* @return completable future which resolves with stopouts found
*/
public CompletableFuture<List<CopyFactoryStrategyStopout>> getStopouts(String accountId) {
if (isNotJwtToken()) return handleNoAccessError("getStopouts");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/stopouts", Method.GET);
opts.getHeaders().put("auth-token", token);
return httpClient.requestJson(opts, CopyFactoryStrategyStopout[].class)
.thenApply((array) -> Arrays.asList(array));
}

/**
* Resets strategy stopouts. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/resetStopOuts/
* @param accountId account id
* @param strategyId strategy id
* @param reason stopout reason to reset. One of yearly-balance, monthly-balance, daily-balance,
* yearly-equity, monthly-equity, daily-equity, max-drawdown
* @return completable future which resolves when the stopouts are reset
*/
public CompletableFuture<Void> resetStopouts(String accountId, String strategyId, String reason) {
if (isNotJwtToken()) return handleNoAccessError("resetStopouts");
HttpRequestOptions opts = new HttpRequestOptions(host + "/users/current/accounts/" + accountId
+ "/strategies-subscribed/" + strategyId + "/stopouts/" + reason + "/reset", Method.POST);
opts.getHeaders().put("auth-token", token);
return httpClient.request(opts).thenApply(response -> null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/getUserLog/
* @param accountId account id
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId) {
return getUserLog(accountId, null, null, null, null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/getUserLog/
* @param accountId account id
* @param startTime time to start loading data from, or {@code null}
* @param endTime time to stop loading data at, or {@code null}
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId,
IsoTime startTime, IsoTime endTime) {
return getUserLog(accountId, startTime, endTime, null, null);
}

/**
* Returns copy trading user log for an account and time range. See
* https://metaapi.cloud/docs/copyfactory/restApi/api/trading/getUserLog/
* @param accountId account id
* @param startTime time to start loading data from, or {@code null}
* @param endTime time to stop loading data at, or {@code null}
* @param offset pagination offset, or {@code null}. Default is 0
* @param limit pagination limit, or {@code null}. Default is 1000
* @return completable future which resolves with log records found
*/
public CompletableFuture<List<CopyFactoryUserLogRecord>> getUserLog(String accountId,
IsoTime startTime, IsoTime endTime, Integer offset, Integer limit) {
if (isNotJwtToken()) return handleNoAccessError("getUserLog");
HttpRequestOptions opts = new HttpRequestOptions(
host + "/users/current/accounts/" + accountId + "/user-log", Method.GET);
opts.getHeaders().put("auth-token", token);
if (startTime != null) opts.getQueryParameters().put("startTime", startTime);
if (endTime != null) opts.getQueryParameters().put("endTime", endTime);
if (offset != null) opts.getQueryParameters().put("offset", offset);
if (limit != null) opts.getQueryParameters().put("limit", limit);
return httpClient.requestJson(opts, CopyFactoryUserLogRecord[].class)
.thenApply((array) -> Arrays.asList(array));
}
}
Loading

0 comments on commit 22ee6da

Please sign in to comment.