diff --git a/src/main/java/org/alis/blackchain/constanst/InstType.java b/src/main/java/org/alis/blackchain/constanst/InstType.java new file mode 100644 index 0000000..56d8395 --- /dev/null +++ b/src/main/java/org/alis/blackchain/constanst/InstType.java @@ -0,0 +1,43 @@ +package org.alis.blackchain.constanst; + +/** + * @author lc + * @date 2023/11/24 17:14 + **/ +public final class InstType { + private final String type; + + private InstType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + private static InstType of(String type) { + return new InstType(type); + } + + /** + * 币币 + */ + public static final InstType SPOT = InstType.of("SPOT"); + /** + * 币币杠杆 + */ + public static final InstType MARGIN = InstType.of("MARGIN"); + /** + * 永续合约 + */ + public static final InstType SWAP = InstType.of("SWAP"); + /** + * 交割合约 + */ + public static final InstType FUTURES = InstType.of("FUTURES"); + + /** + * 期权 + */ + public static final InstType OPTION = InstType.of("OPTION"); +} diff --git a/src/main/java/org/alis/blackchain/service/BinanceService.java b/src/main/java/org/alis/blackchain/service/BinanceService.java index 71d03ce..76b99c7 100644 --- a/src/main/java/org/alis/blackchain/service/BinanceService.java +++ b/src/main/java/org/alis/blackchain/service/BinanceService.java @@ -3,6 +3,7 @@ package org.alis.blackchain.service; import cn.hutool.core.lang.Pair; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.alis.blackchain.constanst.InstType; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Service; @@ -25,15 +26,17 @@ public class BinanceService implements CommandLineRunner { public void run(String... args) { String symbol = "BTC-USDT"; // String symbol = "BTC-USD-200329"; - List> balance = exchange.getBalance(); - log.info("查询到账户到余额:{}", balance); +// List> balance = exchange.getBalance(); +// log.info("查询到账户到余额:{}", balance); // String order = exchange.order(symbol, BigDecimal.ONE); -// System.out.println(order); + // log.info("订单交易:{}",order); // CL1727961946902888448 自定义orderId - String detail = exchange.orderDetail("648192883505352706", symbol); - log.info("交易订单信息:{}",detail); - String pendOrder = exchange.getPendOrder(); - log.info("正在交易信息{}", pendOrder); +// String detail = exchange.orderDetail("648192883505352706", symbol); +// log.info("交易订单信息:{}",detail); +// String pendOrder = exchange.getPendOrder(); +// log.info("正在交易信息{}", pendOrder); + List>> market = exchange.getMarket(InstType.SPOT.getType()); + market.forEach(pa-> log.info("{}",pa)); } diff --git a/src/main/java/org/alis/blackchain/service/Exchange.java b/src/main/java/org/alis/blackchain/service/Exchange.java index 107aa1b..461d086 100644 --- a/src/main/java/org/alis/blackchain/service/Exchange.java +++ b/src/main/java/org/alis/blackchain/service/Exchange.java @@ -24,5 +24,7 @@ public interface Exchange { String orderDetail(String orderId, String symbol); + List>> getMarket(String type); + String getPendOrder(); } diff --git a/src/main/java/org/alis/blackchain/service/OkxExchangeAdapter.java b/src/main/java/org/alis/blackchain/service/OkxExchangeAdapter.java index e94c450..d7870d9 100644 --- a/src/main/java/org/alis/blackchain/service/OkxExchangeAdapter.java +++ b/src/main/java/org/alis/blackchain/service/OkxExchangeAdapter.java @@ -30,6 +30,7 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.stream.Collectors; /** * okr交易所 @@ -139,6 +140,22 @@ public class OkxExchangeAdapter implements Exchange { return request.execute().body(); } + @Override + public List>> getMarket(String type) { + Map paramMap = new HashMap<>(); + if (StringUtils.hasLength(type)) { + paramMap.put("instType", type); + } + HttpRequest request = buildBaseRequest(Method.GET, "/api/v5/public/instruments", paramMap, ""); + String body = request.execute().body(); + JSONObject jsonObj = JSONUtil.parseObj(body); + Object data = jsonObj.get("data"); + JSONArray array = JSONUtil.parseArray(data); + return array.stream().map(JSONUtil::parseObj) + .map(obj -> Pair.of(obj.getStr("instId"), Pair.of(obj.getStr("baseCcy"),obj.getStr("quoteCcy")))) + .collect(Collectors.toList()); + } + @Override public String getPendOrder() { HttpRequest request = buildBaseRequest(Method.GET, "/api/v5/trade/orders-pending", Collections.emptyMap(), "");