Official Java client for the Metals-API.
- Add the JitPack repository:
// build.gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}- Add dependency:
dependencies {
implementation 'com.github.Zyla-Labs:metals-api-java-client:0.1.0'
}- Add the JitPack repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>- Add dependency:
<dependency>
<groupId>com.github.Zyla-Labs</groupId>
<artifactId>metals-api-java-client</artifactId>
<version>0.1.0</version>
</dependency>Nota: Reemplaza Zyla-Labs con tu usuario/organización de GitHub y metals-api-java-client con el nombre de tu repositorio.
Para publicar este SDK en JitPack:
-
Sube el código a GitHub:
git init git add . git commit -m "Initial commit" git remote add origin https://github.com/TU-USUARIO/metals-api-java-client.git git push -u origin main
-
Crea un tag de versión:
git tag 0.1.0 git push origin 0.1.0
-
JitPack construirá automáticamente el proyecto. Puedes verificar el build en:
https://jitpack.io/#TU-USUARIO/metals-api-java-client/0.1.0 -
Usa la dependencia con el formato:
com.github.TU-USUARIO:metals-api-java-client:0.1.0
import com.metals.api.MetalsClient;
public class Example {
public static void main(String[] args) {
MetalsClient client = new MetalsClient("YOUR_ACCESS_KEY");
var latest = client.getLatest("USD", "RICE,WHEAT,SUGAR");
System.out.println(latest);
var historical = client.getHistorical("2024-05-15", "USD", "WTIOIL,GOLD");
System.out.println(historical);
}
}getLatest(base, symbols)getHistorical(date, base, symbols)getTimeSeries(startDate, endDate, base, symbols)getFluctuation(startDate, endDate, base, symbols)convert(from, to, amount, date)getSymbols()getSeasonality(symbol, groupBy, years)(cuando el endpoint exista)
import com.metals.api.MetalsClient;
import com.metals.api.MetalsApiException;
try {
var client = new MetalsClient("YOUR_ACCESS_KEY");
var latest = client.getLatest("USD", "WTIOIL,GOLD");
} catch (MetalsApiException e) {
System.err.println(e.getMessage());
System.err.println("Status: " + e.getStatusCode());
System.err.println("Code: " + e.getErrorCode());
}