:feat: 行情

main
luochuan 12 months ago
parent b4b09fd2bb
commit 2a9e71b5b5

@ -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");
}

@ -3,6 +3,7 @@ package org.alis.blackchain.service;
import cn.hutool.core.lang.Pair; import cn.hutool.core.lang.Pair;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.alis.blackchain.constanst.InstType;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -25,15 +26,17 @@ public class BinanceService implements CommandLineRunner {
public void run(String... args) { public void run(String... args) {
String symbol = "BTC-USDT"; String symbol = "BTC-USDT";
// String symbol = "BTC-USD-200329"; // String symbol = "BTC-USD-200329";
List<Pair<String, BigDecimal>> balance = exchange.getBalance(); // List<Pair<String, BigDecimal>> balance = exchange.getBalance();
log.info("查询到账户到余额:{}", balance); // log.info("查询到账户到余额:{}", balance);
// String order = exchange.order(symbol, BigDecimal.ONE); // String order = exchange.order(symbol, BigDecimal.ONE);
// System.out.println(order); // log.info("订单交易:{}",order);
// CL1727961946902888448 自定义orderId // CL1727961946902888448 自定义orderId
String detail = exchange.orderDetail("648192883505352706", symbol); // String detail = exchange.orderDetail("648192883505352706", symbol);
log.info("交易订单信息:{}",detail); // log.info("交易订单信息:{}",detail);
String pendOrder = exchange.getPendOrder(); // String pendOrder = exchange.getPendOrder();
log.info("正在交易信息{}", pendOrder); // log.info("正在交易信息{}", pendOrder);
List<Pair<String, Pair<String, String>>> market = exchange.getMarket(InstType.SPOT.getType());
market.forEach(pa-> log.info("{}",pa));
} }

@ -24,5 +24,7 @@ public interface Exchange {
String orderDetail(String orderId, String symbol); String orderDetail(String orderId, String symbol);
List<Pair<String,Pair<String, String>>> getMarket(String type);
String getPendOrder(); String getPendOrder();
} }

@ -30,6 +30,7 @@ import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* okr * okr
@ -139,6 +140,22 @@ public class OkxExchangeAdapter implements Exchange {
return request.execute().body(); return request.execute().body();
} }
@Override
public List<Pair<String, Pair<String, String>>> getMarket(String type) {
Map<String, Object> 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 @Override
public String getPendOrder() { public String getPendOrder() {
HttpRequest request = buildBaseRequest(Method.GET, "/api/v5/trade/orders-pending", Collections.emptyMap(), ""); HttpRequest request = buildBaseRequest(Method.GET, "/api/v5/trade/orders-pending", Collections.emptyMap(), "");

Loading…
Cancel
Save