Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[coinex] Extend functionality #4884

Merged
merged 14 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,12 @@
<version>${version.qos.logback}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>

<!-- jwt for auth -->
<dependency>
<groupId>com.auth0</groupId>
Expand Down Expand Up @@ -388,7 +394,6 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slf4j should be in dependencies, not in dependency management. That way it's in all submodules without needed to explicitly add it in each child module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right, but it has to be in both sections:
in dependencyManagement we define the version without declaring the factual dependency
in dependencies we declare the factual dependency and the version is taken the one that is declared in dependencyManagement

The advantage of that approach is that we avoid compiling against one version and using another in the runtime.

Now it looks like that: we compile against slf4j-api 2.0.13, but effectively getting 2.0.6 via transitive dependency:

[INFO] +- org.knowm.xchange:xchange-core:jar:5.1.2-SNAPSHOT:compile
[INFO] |  +- com.github.mmazi:rescu:jar:3.0:compile (version managed from 3.0)
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:2.0.6:compile - omitted for conflict with 2.0.13)

Once we declare the version in dependencyManagement the dependency tree looks way better - we compile against 2.0.13 and get 2.0.13:

[INFO] +- org.knowm.xchange:xchange-core:jar:5.1.2-SNAPSHOT:compile
[INFO] |  +- com.github.mmazi:rescu:jar:3.0:compile (version managed from 3.0)
[INFO] |  |  +- (org.slf4j:slf4j-api:jar:2.0.13:compile - version managed from 2.0.6; omitted for duplicate)

That is a well known problem caled dependency hell and there is a maven-enforcer-plugin that helps against such problems.
If we agree on that I'll do the analysis for all modules and can prepare the PR afterwards.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. I didn't even know this issue existed at all.

</dependency>

<!-- javax APIs -->
Expand Down
2 changes: 2 additions & 0 deletions xchange-coinex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
http-client.private.env.json
integration-test.env.properties
21 changes: 21 additions & 0 deletions xchange-coinex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Using IntelliJ Idea HTTP client

There are *.http files stored in `src/test/resources/rest` that can be used with IntelliJ Idea HTTP Client.

Some requests need authorization, so the api credentials have to be stored in `http-client.private.env.json` in module's root. Sample content can be found in `example.http-client.private.env.json`

> [!CAUTION]
> Never commit your api credentials to the repository!


[HTTP Client documentation](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html)

## Running integration tests that require API keys

Integration tests that require API keys read them from environment variables. They can be defined in `integration-test.env.properties`. Sample content can be found in `example.integration-test.env.properties`.

If no keys are provided the integration tests that need them are skipped.

> [!CAUTION]
> Never commit your api credentials to the repository!

6 changes: 6 additions & 0 deletions xchange-coinex/example.http-client.private.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"default": {
"api_key": "replace_me",
"api_secret": "replace_me"
}
}
2 changes: 2 additions & 0 deletions xchange-coinex/example.integration-test.env.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
apiKey=change_me
secretKey=change_me
5 changes: 5 additions & 0 deletions xchange-coinex/http-client.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"default": {
"api_host": "https://api.coinex.com",
}
}
2 changes: 2 additions & 0 deletions xchange-coinex/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lombok.equalsAndHashCode.callSuper = call
lombok.tostring.callsuper = call
90 changes: 87 additions & 3 deletions xchange-coinex/pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>xchange-parent</artifactId>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-parent</artifactId>
<version>5.1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>xchange-coinex</artifactId>

Expand All @@ -20,14 +20,98 @@
<url>http://knowm.org/open-source/xchange/</url>
</organization>

<properties>
<version.maven-enforcer-plugin>3.2.1</version.maven-enforcer-plugin>
<version.sortpom-maven-plugin>3.2.0</version.sortpom-maven-plugin>
</properties>

<dependencies>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${version.fasterxml}</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertiesFile>integration-test.env.properties</systemPropertiesFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
<version>${version.sortpom-maven-plugin}</version>
<configuration>
<sortProperties>true</sortProperties>
<createBackupFile>false</createBackupFile>
<sortDependencies>groupId,artifactId</sortDependencies>
<sortModules>true</sortModules>
<nrOfIndentSpace>4</nrOfIndentSpace>
<sortPlugins>groupId,artifactId</sortPlugins>
<expandEmptyElements>false</expandEmptyElements>
</configuration>
<executions>
<execution>
<goals>
<goal>sort</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${version.maven-enforcer-plugin}</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<dependencyConvergence/>
<banDuplicatePomDependencyVersions/>
<reactorModuleConvergence/>
</rules>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
</project>
54 changes: 54 additions & 0 deletions xchange-coinex/src/main/java/org/knowm/xchange/coinex/Coinex.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.knowm.xchange.coinex;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import org.knowm.xchange.coinex.dto.CoinexException;
import org.knowm.xchange.coinex.dto.CoinexResponse;
import org.knowm.xchange.coinex.dto.marketdata.CoinexAllMarketStatisticsV1;
import org.knowm.xchange.coinex.dto.marketdata.CoinexChainInfo;
import org.knowm.xchange.coinex.dto.marketdata.CoinexCurrencyPairInfo;
import org.knowm.xchange.coinex.dto.marketdata.CoinexMarketDepth;
import org.knowm.xchange.coinex.dto.marketdata.CoinexSingleMarketStatisticsV1;

@Path("")
@Produces(MediaType.APPLICATION_JSON)
public interface Coinex {

@GET
@Path("v1/common/asset/config")
CoinexResponse<Map<String, CoinexChainInfo>> allChainInfos()
throws IOException, CoinexException;


@GET
@Path("v1/market/ticker/all")
CoinexResponse<CoinexAllMarketStatisticsV1> allMarketStatistics()
throws IOException, CoinexException;


@GET
@Path("v1/market/ticker")
CoinexResponse<CoinexSingleMarketStatisticsV1> singleMarketStatistics(@QueryParam("market") String market)
throws IOException, CoinexException;


@GET
@Path("v2/spot/market")
CoinexResponse<List<CoinexCurrencyPairInfo>> marketStatus(@QueryParam("market") String markets)
throws IOException, CoinexException;


@GET
@Path("v2/spot/depth")
CoinexResponse<CoinexMarketDepth> marketDepth(@QueryParam("market") String market,
@QueryParam("limit") Integer limit, @QueryParam("interval") Integer interval)
throws IOException, CoinexException;


}
Loading
Loading