Merge remote-tracking branch 'origin/master'

master
yz 6 months ago
commit 2d940bde48

@ -1,147 +1,161 @@
package com.tz.platform.juejin;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.netflix.ribbon.proxy.annotation.Http;
import com.tz.platform.common.core.base.BaseException;
import com.tz.platform.common.core.tools.DateUtil;
import com.tz.platform.common.core.tools.HttpUtil;
import com.tz.platform.entity.Ranking;
import com.tz.platform.entity.CompetitionMember;
import com.tz.platform.juejin.bo.AccountInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class JueJinApi {
private String token = "157e2484a38880effebe57c4ee95d6c29984e2f8";
private String baseUrl = "https://sim.sztzjy.com";
private Map<String,String> headers = new HashMap<>();
private static Map<String, String> headers = new HashMap<>();
private static Logger logger = LoggerFactory.getLogger(JueJinApi.class);
public JueJinApi(){
headers.put("Authorization","bearer "+token);
public JueJinApi() {
headers.put("Authorization", "bearer " + token);
}
public JueJinApi(String token){
public JueJinApi(String token) {
this.token = token;
headers.put("Authorization","bearer "+token);
headers.put("Authorization", "bearer " + token);
}
/**
*
* @param accountName
* @param initCash
* @param secType 1 = 4 =
* @return
*/
public AccountInfo createAccount(String accountName,Long initCash,Integer secType){
if(StringUtils.isEmpty(accountName)){
* @return //1310 10000000 type=4 1309 1000000 tpye= 1
*/ //(member.getName(),competitionTask.getInitCapital(),tradeType)
public AccountInfo createAccount(String accountName, Long initCash, Integer secType) {
if (StringUtils.isEmpty(accountName)) {
throw new BaseException("账号名称不能为空");
}
if(secType!=1&&secType!=4){
if (secType != 1 && secType != 4) {
throw new BaseException("交易类型错误");
}
if(initCash<0){
if (initCash < 0) {
throw new BaseException("初始资金不能为负");
}
String url = baseUrl +"/broker-rpcgw/v3/accounts";
String param = "{\"account\": {\"title\": \""+accountName+"\", \"sec_types\": ["+secType+"], \"info\": {\"appid\": \"[GMBROKER]\"} }, \"init_cash\": "+initCash+", \"engine_id\": \"simulate\"}";
String content = HttpUtil.postWithHeader( url,param,headers);
String url = baseUrl + "/broker-rpcgw/v3/accounts";
String param = "{\"account\": {\"title\": \"" + accountName + "\", \"sec_types\": [" + secType + "], \"info\": {\"appid\": \"[GMBROKER]\"} }, \"init_cash\": " + initCash + ", \"engine_id\": \"simulate\"}";
String content = HttpUtil.postWithHeader(url, param, headers);
logger.info(content);
return JSONUtil.toBean(content,AccountInfo.class);
return JSONUtil.toBean(content, AccountInfo.class);
}
public static void main(String[] args) {
String token = "157e2484a38880effebe57c4ee95d6c29984e2f8";
Map<String, String> headers = new HashMap<>();
String url = "https://sim.sztzjy.com/broker-rpcgw/v3/accounts";
headers.put("Authorization", "bearer " + token);
String a = "{\"account\": {\"title\": \"" + "费无法" + "\", \"sec_types\": [" + 4 + "], \"info\": {\"appid\": \"[GMBROKER]\"} }, \"init_cash\": " + 10000000L + ", \"engine_id\": \"simulate\"}";
String param = "{\"account\": {\"title\": \"" + "费无法" + "\", \"sec_types\": [" + 1 + "], \"info\": {\"appid\": \"[GMBROKER]\"} }, \"init_cash\": " + 1000000L + ", \"engine_id\": \"simulate\"}";
String contenta = HttpUtil.postWithHeader(url, param, headers);
String contentb = HttpUtil.postWithHeader(url, param, headers);
System.out.println("1310大赛=======" + contenta);
System.out.println("1309大赛=======" + contentb);
}
/**
*
*
* @param accountId ID
*/
public void deleteAccount(String accountId){
String url = baseUrl+"/broker-rpcgw/v3/accounts?account_ids="+accountId;
String content = HttpUtil.delete(url,headers);
logger.info("{} 删除信息,{}",accountId,content);
public void deleteAccount(String accountId) {
String url = baseUrl + "/broker-rpcgw/v3/accounts?account_ids=" + accountId;
String content = HttpUtil.delete(url, headers);
logger.info("{} 删除信息,{}", accountId, content);
}
public String getCashInfo(String accountId){
String url = baseUrl+"/broker-rpcgw/v3/account-trade/cash/"+accountId;
String content = HttpUtil.get(url,headers);
logger.info("{} 账户资金信息:{},",accountId,content);
public String getCashInfo(String accountId) {
String url = baseUrl + "/broker-rpcgw/v3/account-trade/cash/" + accountId;
String content = HttpUtil.get(url, headers);
logger.info("{} 账户资金信息:{},", accountId, content);
return content;
}
public String cashInOut(String accountId){
String url =baseUrl+ "/broker-rpcgw/v3/accounts/"+accountId+"/cash-inout";
String content = HttpUtil.get(url,headers);
logger.info("{} 出入资金明细:{},",accountId,content);
public String cashInOut(String accountId) {
String url = baseUrl + "/broker-rpcgw/v3/accounts/" + accountId + "/cash-inout";
String content = HttpUtil.get(url, headers);
logger.info("{} 出入资金明细:{},", accountId, content);
return content;
}
/**
*
*
* @param accountId
* @param title
* @return
*/
public String createReport(String accountId,String title){
String url = baseUrl+ "/perfweb-rpcgw/api/v1/sim/detail/"+accountId+"?title="+title;
String content = HttpUtil.get(url,headers);
logger.info("报告生成请求: {}",accountId+"\t"+content);
public String createReport(String accountId, String title) {
String url = baseUrl + "/perfweb-rpcgw/api/v1/sim/detail/" + accountId + "?title=" + title;
String content = HttpUtil.get(url, headers);
logger.info("报告生成请求: {}", accountId + "\t" + content);
return content;
}
/**
*
*
* @param reportId
* @return
*/
public String getReport(String reportId){
String url = baseUrl +"/perfweb-rpcgw/api/v1/report/summaries?report_ids="+reportId;
String content = HttpUtil.get(url,headers);
logger.info("报告获取:{}",content);
public String getReport(String reportId) {
String url = baseUrl + "/perfweb-rpcgw/api/v1/report/summaries?report_ids=" + reportId;
String content = HttpUtil.get(url, headers);
logger.info("报告获取:{}", content);
return content;
}
public String createReport2(String accountId,String title){
String url = baseUrl+ "/perfweb-rpcgw/api/v1/report/analyse-simulation-account";
String postData = "{\"account_id\":\""+accountId+"\",\"title\":\""+title+"\"}";
String content = HttpUtil.postWithHeader(url,postData,headers);
public String createReport2(String accountId, String title) {
String url = baseUrl + "/perfweb-rpcgw/api/v1/report/analyse-simulation-account";
String postData = "{\"account_id\":\"" + accountId + "\",\"title\":\"" + title + "\"}";
String content = HttpUtil.postWithHeader(url, postData, headers);
return content;
}
public String listReport(Integer pageNo,Integer pageSize){
String url = baseUrl +"/api/v1/reports?page="+pageNo+"&size="+pageSize;
String content = HttpUtil.get(url,headers);
public String listReport(Integer pageNo, Integer pageSize) {
String url = baseUrl + "/api/v1/reports?page=" + pageNo + "&size=" + pageSize;
String content = HttpUtil.get(url, headers);
return content;
}
public String listAccountHaveTrade(Integer pageNo,Integer pageSize){
String url = baseUrl+ "/api/v1/accounts?page="+pageNo+"&size="+pageSize;
String content = HttpUtil.get(url,headers);
logger.info("有交易账号信息:{}",content);
public String listAccountHaveTrade(Integer pageNo, Integer pageSize) {
String url = baseUrl + "/api/v1/accounts?page=" + pageNo + "&size=" + pageSize;
String content = HttpUtil.get(url, headers);
logger.info("有交易账号信息:{}", content);
return content;
}
/**
*
*
* @return
*/
public Double getBaseRatio(String start,String end){
String url = baseUrl +"/ds-history-rpcgw/v3/data-history/benchmark-return?symbol=SHSE.000300&frequency=1d&start_time="+start+"&end_time="+end+"&adjust=0";
String content = HttpUtil.get(url,headers);
logger.info("基准收益率:{}",content);
public Double getBaseRatio(String start, String end) {
String url = baseUrl + "/ds-history-rpcgw/v3/data-history/benchmark-return?symbol=SHSE.000300&frequency=1d&start_time=" + start + "&end_time=" + end + "&adjust=0";
String content = HttpUtil.get(url, headers);
logger.info("基准收益率:{}", content);
JSONObject jsonObject = JSONUtil.parseObj(content);
if(jsonObject.containsKey("data")){
if (jsonObject.containsKey("data")) {
JSONArray jsonArray = jsonObject.getJSONArray("data");
JSONObject ratioObj = (JSONObject) jsonArray.get(jsonArray.size()-1);
logger.info("基准收益率:{}",ratioObj.get("ratio").toString());
JSONObject ratioObj = (JSONObject) jsonArray.get(jsonArray.size() - 1);
logger.info("基准收益率:{}", ratioObj.get("ratio").toString());
BigDecimal ratioDec = new BigDecimal(ratioObj.get("ratio").toString());
return ratioDec.doubleValue();
@ -152,116 +166,120 @@ public class JueJinApi {
/**
*
*
* @param accountId
* @return
*/
public String getTenPosition(String accountId){
String url = baseUrl + "/broker-rpcgw/v3/account-trade/positions/"+accountId;
String content = HttpUtil.get(url,headers);
logger.info("持仓数据:{}",content);
public String getTenPosition(String accountId) {
String url = baseUrl + "/broker-rpcgw/v3/account-trade/positions/" + accountId;
String content = HttpUtil.get(url, headers);
logger.info("持仓数据:{}", content);
return content;
}
public String getStockInfo(String symbols){
String url =baseUrl+"/ds-core-rpcgw/v3/data-fundamental/instrument-infos?symbols="+symbols;
String content = HttpUtil.get(url,headers);
logger.info("股票信息:{}",content);
public String getStockInfo(String symbols) {
String url = baseUrl + "/ds-core-rpcgw/v3/data-fundamental/instrument-infos?symbols=" + symbols;
String content = HttpUtil.get(url, headers);
logger.info("股票信息:{}", content);
return content;
}
/**
*
*
* @param startTime
* @param endTime
* @return
*/
public String getProfit(String startTime,String endTime){
String url = baseUrl +"/ds-history-rpcgw/v3/data-history/benchmark-return" +
"?symbol=SHSE.000300&frequency=1d&start_time="+startTime+"&end_time="+endTime+"&adjust=0";
String content = HttpUtil.get(url,headers);
logger.info("收益走势: {}",content);
public String getProfit(String startTime, String endTime) {
String url = baseUrl + "/ds-history-rpcgw/v3/data-history/benchmark-return" +
"?symbol=SHSE.000300&frequency=1d&start_time=" + startTime + "&end_time=" + endTime + "&adjust=0";
String content = HttpUtil.get(url, headers);
logger.info("收益走势: {}", content);
return content;
}
/**
*
*
* @param accountId ID
* @param start
* @param end
* @return
*/
public String getHeavy(String accountId,String start,String end){
String url =baseUrl + "/broker-rpcgw/v3/account-trade/execrpts/"+accountId +
"?filter.fromdate="+start+"&filter.todate="+end+"&filter.page=0&filter.pagesize=40";
String content = HttpUtil.get(url,headers);
logger.info("重仓: {}",content);
public String getHeavy(String accountId, String start, String end) {
String url = baseUrl + "/broker-rpcgw/v3/account-trade/execrpts/" + accountId +
"?filter.fromdate=" + start + "&filter.todate=" + end + "&filter.page=0&filter.pagesize=40";
String content = HttpUtil.get(url, headers);
logger.info("重仓: {}", content);
return content;
}
/**
*
*
* @return
*/
public String listReport(int pageNo,int pageSize){
String url =baseUrl+ "/api/v1/reports?page="+pageNo+"&size="+pageSize;
String content = HttpUtil.get(url,headers);
public String listReport(int pageNo, int pageSize) {
String url = baseUrl + "/api/v1/reports?page=" + pageNo + "&size=" + pageSize;
String content = HttpUtil.get(url, headers);
return content;
}
public String reportSumary(String reportIds){
String url= "https://sim.sztzjy.com/perfweb-gw/api/v1/report/summaries?report_ids="+reportIds;
String content = HttpUtil.get(url,headers);
public String reportSumary(String reportIds) {
String url = "https://sim.sztzjy.com/perfweb-gw/api/v1/report/summaries?report_ids=" + reportIds;
String content = HttpUtil.get(url, headers);
return content;
}
public String reportDetail(String reportId){
String url = baseUrl+"/perfweb-gw/api/v1/report/detail/"+reportId;
String content = HttpUtil.get(url,headers);
public String reportDetail(String reportId) {
String url = baseUrl + "/perfweb-gw/api/v1/report/detail/" + reportId;
String content = HttpUtil.get(url, headers);
return content;
}
public <T> T getOV(JSONObject jsonObject,String key,T dv){
if(jsonObject.containsKey(key)){
public <T> T getOV(JSONObject jsonObject, String key, T dv) {
if (jsonObject.containsKey(key)) {
Object v = jsonObject.get(key);
if(dv instanceof Integer){
if (dv instanceof Integer) {
v = Integer.parseInt(v.toString());
}else if(dv instanceof Double){
v =Double.parseDouble(v.toString());
} else if (dv instanceof Double) {
v = Double.parseDouble(v.toString());
}
T rs = (T)v;
T rs = (T) v;
return rs;
}
return dv;
}
public static void main(String[] args) {
JueJinApi api = new JueJinApi();
String accountId = "2e41a913-9dc1-11ec-89b3-00163e0e6ad0";
String zhangSan1Qihuo = "0cfc7894-9f4e-11ec-bf20-00163e0e6ad0";
String zhangSan1GuPiao = "";
String start = "2022-04-01";
String end = "2022-05-05";
String content = api.getTenPosition("1664a38b-3fc7-11ed-8b9c-00163e0e6ad0");
System.out.println(content);
// api.deleteAccount("4811913f-9dba-11ec-89b3-00163e0e6ad0");
// api.getCashInfo("d91c3a8f-cba8-11ec-a483-00163e0e6ad0");
// api.test();
// String testAccount = "dc226d8a-cc14-11ec-9cd0-00163e0e6ad0";
// api.createReport(accountId,"report"+ System.currentTimeMillis());
// String content = api.createReport2(accountId,"report"+System.currentTimeMillis());
// api.getTenPosition("9d7f4856-cc11-11ec-9cd0-00163e0e6ad0");
// api.getCashInfo("cbee8129-cae7-11ec-a4f7-00163e0e6ad0");
// api.cashInOut("481c4bbd-cc20-11ec-b818-00163e0e6ad0");
// String content = api.getReport("57509895");
// public static void main(String[] args) {
// JueJinApi api = new JueJinApi();
// String accountId = "2e41a913-9dc1-11ec-89b3-00163e0e6ad0";
// String zhangSan1Qihuo = "0cfc7894-9f4e-11ec-bf20-00163e0e6ad0";
// String zhangSan1GuPiao = "";
// String start = "2022-04-01";
// String end = "2022-05-05";
//
// String content = api.getTenPosition("1664a38b-3fc7-11ed-8b9c-00163e0e6ad0");
// System.out.println(content);
// String reportDetail = api.reportSumary("55122910");
// System.out.println(reportDetail);
// api.getStockInfo("SHSE.600547,SHSE.603160");
// api.getProfit("2022-03-11","2022-03-15");
// api.getHeavy(accountId,start,end);
// api.getBaseRatio(start,end);
}
//// api.deleteAccount("4811913f-9dba-11ec-89b3-00163e0e6ad0");
//// api.getCashInfo("d91c3a8f-cba8-11ec-a483-00163e0e6ad0");
//// api.test();
//// String testAccount = "dc226d8a-cc14-11ec-9cd0-00163e0e6ad0";
//// api.createReport(accountId,"report"+ System.currentTimeMillis());
//
//// String content = api.createReport2(accountId,"report"+System.currentTimeMillis());
//// api.getTenPosition("9d7f4856-cc11-11ec-9cd0-00163e0e6ad0");
//// api.getCashInfo("cbee8129-cae7-11ec-a4f7-00163e0e6ad0");
//// api.cashInOut("481c4bbd-cc20-11ec-b818-00163e0e6ad0");
//// String content = api.getReport("57509895");
//// System.out.println(content);
//// String reportDetail = api.reportSumary("55122910");
//// System.out.println(reportDetail);
//// api.getStockInfo("SHSE.600547,SHSE.603160");
//// api.getProfit("2022-03-11","2022-03-15");
//// api.getHeavy(accountId,start,end);
//// api.getBaseRatio(start,end);
//
// }
}

Loading…
Cancel
Save