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

Added symbols response parsing to SymbolResponse POJO #129

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.binance</groupId>
<artifactId>binance-connector-java</artifactId>
<version>3.4.0</version>
<version>3.4.1-wwcdfork</version>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<description>lightweight connector to API</description>
Expand Down Expand Up @@ -145,6 +145,14 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -174,6 +182,11 @@
<artifactId>json</artifactId>
<version>20231013</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.binance.connector.client.enums;

public enum OrderType {

LIMIT, LIMIT_MAKER, MARKET, STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.binance.connector.client.enums;

public enum TradingStatus {

TRADING, HALT, BREAK

}
35 changes: 35 additions & 0 deletions src/main/java/com/binance/connector/client/impl/spot/Market.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;

import com.binance.connector.client.enums.HttpMethod;
import com.binance.connector.client.exceptions.BinanceConnectorException;
import com.binance.connector.client.impl.spot.data.SymbolResponse;
import com.binance.connector.client.utils.JSONParser;
import com.binance.connector.client.utils.ParameterChecker;
import com.binance.connector.client.utils.ProxyAuth;
import com.binance.connector.client.utils.RequestHandler;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;

/**
* <h2>Market Endpoints</h2>
Expand Down Expand Up @@ -94,6 +98,37 @@ public String exchangeInfo(Map<String, Object> parameters) {
return requestHandler.sendPublicRequest(baseUrl, EXCHANGE_INFO, parameters, HttpMethod.GET, showLimitUsage);
}

/**
* Symbol information as a set of POJOs
* <br><br>
* GET /api/v3/exchangeinfo
* <br>
* @param
* parameters Map of String,Object pair
* where String is the name of the parameter and Object is the value of the parameter
* <br><br>
* symbol -- optional/string <br>
* symbols -- optional/ArrayList <br>
* permissions -- optional/ArrayList -- support single or multiple values (e.g. "SPOT", ["MARGIN","LEVERAGED"]) <br>
* @return A {@link Set} of {@link SymbolResponse} objects representing the parsed symbols data.
* @see <a href="https://developers.binance.com/docs/binance-spot-api-docs/rest-api#exchange-information">
* https://developers.binance.com/docs/binance-spot-api-docs/rest-api#exchange-information</a>
*/
public Set<SymbolResponse> getSymbols(Map<String, Object> parameters) {
String exchangeInfoResponse = exchangeInfo(parameters);
ObjectMapper mapper = new ObjectMapper();
try {
Map<String, Object> map = mapper.readValue(exchangeInfoResponse, Map.class);
Set<SymbolResponse> symbols = mapper.convertValue(
map.get("symbols"),
TypeFactory.defaultInstance().constructCollectionType(Set.class, SymbolResponse.class)
);
return symbols;
} catch (Exception e) {
throw new RuntimeException("Error parsing JSON", e);
}
}

private final String DEPTH = "/api/v3/depth";
/**
* GET /api/v3/depth
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.binance.connector.client.impl.spot.data;

import com.binance.connector.client.enums.OrderType;
import com.binance.connector.client.enums.TradingStatus;

import java.math.BigDecimal;
import java.util.Set;

public record SymbolResponse(

String symbol,
TradingStatus status,
String baseAsset,
BigDecimal baseAssetPrecision,
String quoteAsset,
BigDecimal quoteAssetPrecision,

Set<OrderType> orderTypes,

Boolean icebergAllowed,
Boolean ocoAllowed,
Boolean otoAllowed,
Boolean quoteOrderQtyMarketAllowed,
Boolean allowTrailingStop,
Boolean cancelReplaceAllowed,
Boolean isSpotTradingAllowed,
Boolean isMarginTradingAllowed
) {

}