Compare commits
2 Commits
9c93dc1e10
...
27dc183f8e
Author | SHA1 | Date |
---|---|---|
|
27dc183f8e | |
|
6e5a63784f |
|
@ -65,8 +65,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -307,4 +307,22 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||||
return DateUtils.parseDate(format);
|
return DateUtils.parseDate(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当天零点零时零分 时间
|
||||||
|
* @return Date
|
||||||
|
*/
|
||||||
|
public static Date getZeroTimeOfToday() {
|
||||||
|
// 获取 Calendar 实例
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
// 将小时、分钟、秒和毫秒都设置为 0
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
|
// 返回 Date 对象
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -123,8 +123,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -67,8 +67,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -145,8 +145,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -20,8 +20,11 @@ import java.math.BigDecimal;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static com.jxy.common.core.utils.DateUtils.getZeroTimeOfToday;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description 稳定币流通量
|
* @Description 稳定币流通量
|
||||||
|
@ -105,20 +108,23 @@ public class CSupplyTask {
|
||||||
JSONObject jsonObject = JSONObject.parseObject(s);
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
||||||
//币种流通量字段
|
//币种流通量字段
|
||||||
JSONObject marketData = jsonObject.getJSONObject("market_data");
|
JSONObject marketData = jsonObject.getJSONObject("market_data");
|
||||||
Date date;
|
//String dateString;
|
||||||
try {
|
//try {
|
||||||
//币种流通量最后更新时间
|
// //币种流通量最后更新时间
|
||||||
date = (Date) marketData.get("last_updated");
|
// dateString = (String) marketData.get("last_updated");
|
||||||
}catch (Exception e){
|
//}catch (Exception e){
|
||||||
return null;
|
// return null;
|
||||||
}
|
//}
|
||||||
|
//Instant instant = Instant.parse(dateString);
|
||||||
|
//Date date = Date.from(instant);
|
||||||
|
Date zeroTimeOfToday = getZeroTimeOfToday();
|
||||||
double doubleValue = marketData.getDoubleValue("circulating_supply");
|
double doubleValue = marketData.getDoubleValue("circulating_supply");
|
||||||
List<CirculatingSupplyDataDto> circulatingSupplyDataDtos = new ArrayList<>();
|
List<CirculatingSupplyDataDto> circulatingSupplyDataDtos = new ArrayList<>();
|
||||||
CirculatingSupplyDataDto circulatingSupplyDataDto = new CirculatingSupplyDataDto();
|
CirculatingSupplyDataDto circulatingSupplyDataDto = new CirculatingSupplyDataDto();
|
||||||
circulatingSupplyDataDto.setValue(BigDecimal.valueOf(doubleValue));
|
circulatingSupplyDataDto.setValue(BigDecimal.valueOf(doubleValue));
|
||||||
circulatingSupplyDataDto.setDate(date);
|
circulatingSupplyDataDto.setDate(zeroTimeOfToday);
|
||||||
circulatingSupplyDataDtos.add(circulatingSupplyDataDto);
|
circulatingSupplyDataDtos.add(circulatingSupplyDataDto);
|
||||||
log.info("获取{}币流通量数据成功,最新时间{},流通量{}", coinId, date, doubleValue);
|
log.info("获取{}币流通量数据成功,最新时间{},流通量{}", coinId, zeroTimeOfToday, doubleValue);
|
||||||
return circulatingSupplyDataDtos;
|
return circulatingSupplyDataDtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
package com.jxy.marketall.utils;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.jxy.common.core.utils.DateUtils;
|
||||||
|
import com.jxy.marketall.dto.CirculatingSupplyDataDto;
|
||||||
|
import com.jxy.marketall.task.CSupplyTask;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpEntity;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.jxy.common.core.utils.DateUtils.getZeroTimeOfToday;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description TODO
|
||||||
|
* @Date 2025/5/16 09:42
|
||||||
|
* @Author yyb
|
||||||
|
*/
|
||||||
|
public class TestCoingckoApi {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CSupplyTask.class);
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//String id = "binance-usd";
|
||||||
|
//HttpHeaders headers = new HttpHeaders();
|
||||||
|
//headers.add("Content-Type","application/json");
|
||||||
|
//headers.add("x-cg-demo-api-key","CG-kNuNBTKBcQREBSQKqgj2uua4");
|
||||||
|
//headers.add("User-Agent", "Mozilla/5.0");
|
||||||
|
//HttpEntity<String> httpEntity = new HttpEntity<String>(null, headers);
|
||||||
|
//StringBuffer paramsURL = new StringBuffer(API_URL+id);
|
||||||
|
//String s = HttpUtil.get(paramsURL.toString());
|
||||||
|
//
|
||||||
|
//JSONObject jsonObject = JSONObject.parseObject(s);
|
||||||
|
////币种流通量字段
|
||||||
|
//JSONObject marketData = jsonObject.getJSONObject("market_data");
|
||||||
|
//Date date = null;
|
||||||
|
//try {
|
||||||
|
// //币种流通量最后更新时间
|
||||||
|
// date = (Date) marketData.get("last_updated");
|
||||||
|
//}catch (Exception e){
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//double doubleValue = marketData.getDoubleValue("circulating_supply");
|
||||||
|
//List<CirculatingSupplyDataDto> circulatingSupplyDataDtos = new ArrayList<>();
|
||||||
|
//CirculatingSupplyDataDto circulatingSupplyDataDto = new CirculatingSupplyDataDto();
|
||||||
|
//circulatingSupplyDataDto.setValue(BigDecimal.valueOf(doubleValue));
|
||||||
|
//circulatingSupplyDataDto.setDate(date);
|
||||||
|
//circulatingSupplyDataDtos.add(circulatingSupplyDataDto);
|
||||||
|
//log.info("获取{}币流通量数据成功,最新时间{},流通量{}", id, date, doubleValue);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 配置 HTTP 代理
|
||||||
|
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7897));
|
||||||
|
|
||||||
|
// 创建 URL 对象
|
||||||
|
URL url = new URL("https://api.coingecko.com/api/v3/coins/binance-usd");
|
||||||
|
|
||||||
|
// 打开连接并设置代理
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
|
||||||
|
|
||||||
|
// 设置请求方法
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
|
||||||
|
// 获取响应码
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
System.out.println("Response Code: " + responseCode);
|
||||||
|
|
||||||
|
// 读取响应内容
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
String line;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(response.toString());
|
||||||
|
JSONObject marketData = jsonObject.getJSONObject("market_data");
|
||||||
|
double doubleValue = marketData.getDoubleValue("circulating_supply");
|
||||||
|
//String dateString = (String) marketData.get("last_updated");
|
||||||
|
// 输出响应内容
|
||||||
|
System.out.println("doubleValue: " + doubleValue + "date:"+getZeroTimeOfToday());
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String[] COINS = {"tether", "usd-coin", "binance-usd"};
|
||||||
|
private static final String[] SYMBOLS = {"USDT", "USDC", "BUSD"};
|
||||||
|
private static final String API_URL = "https://api.coingecko.com/api/v3/coins/";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -129,8 +129,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -93,8 +93,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -93,8 +93,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
|
@ -94,8 +94,9 @@
|
||||||
<finalName>${project.artifactId}</finalName>
|
<finalName>${project.artifactId}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
|
Loading…
Reference in New Issue