Helius
2021-06-03 0916da53ef71cf6b415ca289791b82bf5a7e6e01
modify
2 files modified
36 ■■■■■ changed files
src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java 27 ●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/XchTest.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/quartz/job/XchBaseDataUpdateJob.java
@@ -36,40 +36,23 @@
    @Autowired
    private XchProfitService xchProfitService;
    //    @Scheduled(cron = "0 0 0/10 * * ? ")
//        @Scheduled(cron = "0/1 * * * * ? ")
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void baseDataUpdate() {
        log.info("基础数据更新任务");
        // 请求价格等数据 "https://api2.chiaexplorer.com/blockchainSummary"
        String result = pyExec();
//        log.info("result======>>{}", result);
        // 每t预计收益
//        String profitPerT = execCurl("https://api2.chiaexplorer.com/chart/xchTibDay?period=2w");
//
//        String xchPrice24HStr = execCurl("https://api2.chiaexplorer.com/chart/xchPriceChart?period=24h");
//        JSONObject jsonObject = (JSONObject) JSONObject.parse(result);
//        JSONObject perTObject = (JSONObject) JSONObject.parse(profitPerT);
        log.info("====>{}",result);
        JSONObject xchPrice24HObj = (JSONObject) JSONObject.parse(result);
        List<YdBasicSettingEntity> list = ydBasicSettingDao.selectList(null);
        if (CollUtil.isNotEmpty(list)) {
            YdBasicSettingEntity settingEntity = list.get(0);
//            String netspaceStr = jsonObject.getString("netspace");
//            BigDecimal baseUnit = BigDecimal.valueOf(1024);
//            BigDecimal netspace = new BigDecimal(netspaceStr).divide(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit.multiply(baseUnit)))), 2, BigDecimal.ROUND_DOWN);
//            settingEntity.setAllPower(netspace);
            List<String> xchPrice24H = JSONObject.parseArray(xchPrice24HObj.getString("data"), String.class);
            BigDecimal newestPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1));
            redisUtils.set("XCH_NEW_PRICE", newestPrice);
            settingEntity.setCurrentPrice(newestPrice);
//            BigDecimal lastPrice = new BigDecimal(xchPrice24H.get(xchPrice24H.size() - 1 -24));
//            BigDecimal upOrDown = newestPrice.subtract(lastPrice).multiply(BigDecimal.valueOf(100)).divide(lastPrice, 2, BigDecimal.ROUND_HALF_UP);
//            redisUtils.set("XCH_UP_DOWN", upOrDown);
//            List<String> data = JSONObject.parseArray(perTObject.getString("data"), String.class);
//            settingEntity.setPrifitT(new BigDecimal(data.get(0)));
//            settingEntity.setProfitDay(new BigDecimal(data.get(0)).multiply(BigDecimal.valueOf(1024)));
            ydBasicSettingDao.updateById(settingEntity);
        }
    }
@@ -154,8 +137,10 @@
    public String pyExec() {
        String result = "";
        String cmd = "python2.7 /home/javaweb/yunding/xch.py";
//        String cmd = "python /Users/helius/Desktop/xch.py";
        try {
            Process process = Runtime.getRuntime().exec("python2.7 /home/javaweb/yunding/xch.py");
            Process process = Runtime.getRuntime().exec(cmd);
            process.waitFor();
            InputStreamReader ir = new InputStreamReader(process.getInputStream());
            LineNumberReader input = new LineNumberReader(ir);
src/test/java/com/xcong/excoin/XchTest.java
@@ -12,6 +12,7 @@
import com.xcong.excoin.modules.yunding.dao.YdOrderDao;
import com.xcong.excoin.modules.yunding.entity.YdOrderEntity;
import com.xcong.excoin.modules.yunding.service.XchProfitService;
import com.xcong.excoin.quartz.job.XchBaseDataUpdateJob;
import com.xcong.excoin.quartz.job.YdPowerJob;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -166,4 +167,12 @@
        }
        System.out.println(result);
    }
    @Autowired
    private XchBaseDataUpdateJob xchBaseDataUpdateJob;
    @Test
    public void baseDataTest() {
        xchBaseDataUpdateJob.baseDataUpdate();
    }
}