first commit
This commit is contained in:
10
comm/Contract/src/project/contract/AdminContractApplyOrderService.java
Executable file
10
comm/Contract/src/project/contract/AdminContractApplyOrderService.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package project.contract;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminContractApplyOrderService {
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String username,String orderNo);
|
||||
|
||||
public ContractApplyOrder get(String id);
|
||||
}
|
||||
10
comm/Contract/src/project/contract/AdminContractOrderService.java
Executable file
10
comm/Contract/src/project/contract/AdminContractOrderService.java
Executable file
@@ -0,0 +1,10 @@
|
||||
package project.contract;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminContractOrderService {
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String startTime,String endTime,String username,String orderNo);
|
||||
|
||||
public ContractOrder get(String id);
|
||||
}
|
||||
16
comm/Contract/src/project/contract/AdminMarketQuotationsService.java
Executable file
16
comm/Contract/src/project/contract/AdminMarketQuotationsService.java
Executable file
@@ -0,0 +1,16 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import kernel.web.Page;
|
||||
|
||||
public interface AdminMarketQuotationsService {
|
||||
|
||||
/**
|
||||
* 行情列表
|
||||
* @return
|
||||
*/
|
||||
public Page pageQuery(int pageNo,int pageSize);
|
||||
|
||||
}
|
||||
72
comm/Contract/src/project/contract/ContractApplyOrder.hbm.xml
Executable file
72
comm/Contract/src/project/contract/ContractApplyOrder.hbm.xml
Executable file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="project.contract.ContractApplyOrder" table="T_CONTRACT_APPLY_ORDER">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="partyId" type="java.lang.String">
|
||||
<column name="PARTY_ID" />
|
||||
</property>
|
||||
<property name="order_no" type="java.lang.String">
|
||||
<column name="ORDER_NO" />
|
||||
</property>
|
||||
<property name="symbol" type="java.lang.String">
|
||||
<column name="SYMBOL" />
|
||||
</property>
|
||||
<property name="direction" type="java.lang.String">
|
||||
<column name="DIRECTION" />
|
||||
</property>
|
||||
<property name="offset" type="java.lang.String">
|
||||
<column name="OFFSET" />
|
||||
</property>
|
||||
<property name="volume" type="double">
|
||||
<column name="VOLUME" />
|
||||
</property>
|
||||
<property name="volume_open" type="double">
|
||||
<column name="VOLUME_OPEN" />
|
||||
</property>
|
||||
<property name="lever_rate" type="double">
|
||||
<column name="LEVER_RATE" />
|
||||
</property>
|
||||
<property name="price" type="double">
|
||||
<column name="PRICE" />
|
||||
</property>
|
||||
<property name="stop_price_profit" type="double">
|
||||
<column name="STOP_PRICE_PROFIT" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_loss" type="double">
|
||||
<column name="STOP_PRICE_LOSS" />
|
||||
</property>
|
||||
|
||||
<property name="order_price_type" type="java.lang.String">
|
||||
<column name="ORDER_PRICE_TYPE" />
|
||||
</property>
|
||||
|
||||
<property name="state" type="java.lang.String">
|
||||
<column name="STATE" />
|
||||
</property>
|
||||
|
||||
<property name="create_time" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
|
||||
|
||||
|
||||
<property name="unit_amount" type="double">
|
||||
<column name="UNIT_AMOUNT" />
|
||||
</property>
|
||||
|
||||
<property name="fee" type="double">
|
||||
<column name="FEE" />
|
||||
</property>
|
||||
<property name="deposit" type="double">
|
||||
<column name="DEPOSIT" />
|
||||
</property>
|
||||
|
||||
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
253
comm/Contract/src/project/contract/ContractApplyOrder.java
Executable file
253
comm/Contract/src/project/contract/ContractApplyOrder.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.contract;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
|
||||
/**
|
||||
* 委托单
|
||||
*/
|
||||
public class ContractApplyOrder extends EntityObject {
|
||||
|
||||
public final static String STATE_SUBMITTED = "submitted";
|
||||
public final static String STATE_CANCELED = "canceled";
|
||||
public final static String STATE_CREATED = "created";
|
||||
/**
|
||||
* 多仓
|
||||
*/
|
||||
public final static String DIRECTION_BUY = "buy";
|
||||
/**
|
||||
* 空仓
|
||||
*/
|
||||
public final static String DIRECTION_SELL = "sell";
|
||||
/**
|
||||
* 开仓
|
||||
*/
|
||||
public final static String OFFSET_OPEN = "open";
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*/
|
||||
public final static String OFFSET_CLOSE = "close";
|
||||
|
||||
/**
|
||||
* 限价单
|
||||
*/
|
||||
public final static String ORDER_PRICE_TYPE_LIMIT = "limit";
|
||||
|
||||
/**
|
||||
* 对手价(市价)
|
||||
*/
|
||||
public final static String ORDER_PRICE_TYPE_OPPONENT = "opponent";
|
||||
|
||||
private static final long serialVersionUID = 3005514385287413248L;
|
||||
|
||||
private Serializable partyId;
|
||||
|
||||
/**
|
||||
* 订单 号
|
||||
*/
|
||||
private String order_no;
|
||||
|
||||
private String symbol;
|
||||
/**
|
||||
* "buy":多 "sell":空
|
||||
*/
|
||||
private String direction;
|
||||
|
||||
/**
|
||||
* "open":开 "close":平
|
||||
*/
|
||||
private String offset;
|
||||
/**
|
||||
* 委托数量(剩余)(张)
|
||||
*/
|
||||
private Double volume;
|
||||
/**
|
||||
* 委托数量(张)
|
||||
*/
|
||||
private Double volume_open;
|
||||
/**
|
||||
* 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单]
|
||||
*/
|
||||
private Double lever_rate;
|
||||
|
||||
/**
|
||||
* limit order的交易价格
|
||||
*/
|
||||
private Double price;
|
||||
/**
|
||||
* 止盈触发价格
|
||||
*/
|
||||
private Double stop_price_profit;
|
||||
/**
|
||||
* 止损触发价格
|
||||
*/
|
||||
private Double stop_price_loss;
|
||||
/**
|
||||
* 订单报价类型。 "limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
private String order_price_type;
|
||||
/**
|
||||
* 状态。submitted 已提交,canceled 已撤销, created 委托完成
|
||||
*/
|
||||
private String state = "submitted";
|
||||
|
||||
private Date create_time;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private double fee;
|
||||
|
||||
/**
|
||||
* 保证金
|
||||
*/
|
||||
private double deposit;
|
||||
|
||||
/**
|
||||
* 每手金额
|
||||
*/
|
||||
private double unit_amount;
|
||||
|
||||
public Serializable getPartyId() {
|
||||
return partyId;
|
||||
}
|
||||
|
||||
public void setPartyId(Serializable partyId) {
|
||||
this.partyId = partyId;
|
||||
}
|
||||
|
||||
public String getOrder_no() {
|
||||
return order_no;
|
||||
}
|
||||
|
||||
public void setOrder_no(String order_no) {
|
||||
this.order_no = order_no;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public String getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(String offset) {
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public Double getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(Double volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public Double getLever_rate() {
|
||||
return lever_rate;
|
||||
}
|
||||
|
||||
public void setLever_rate(Double lever_rate) {
|
||||
if (lever_rate != null && lever_rate == 1) {
|
||||
lever_rate = null;
|
||||
}
|
||||
this.lever_rate = lever_rate;
|
||||
}
|
||||
|
||||
public Double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(Double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public Double getStop_price_profit() {
|
||||
return stop_price_profit;
|
||||
}
|
||||
|
||||
public void setStop_price_profit(Double stop_price_profit) {
|
||||
this.stop_price_profit = stop_price_profit;
|
||||
}
|
||||
|
||||
public Double getStop_price_loss() {
|
||||
return stop_price_loss;
|
||||
}
|
||||
|
||||
public void setStop_price_loss(Double stop_price_loss) {
|
||||
this.stop_price_loss = stop_price_loss;
|
||||
}
|
||||
|
||||
public String getOrder_price_type() {
|
||||
return order_price_type;
|
||||
}
|
||||
|
||||
public void setOrder_price_type(String order_price_type) {
|
||||
this.order_price_type = order_price_type;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Date getCreate_time() {
|
||||
return create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(Date create_time) {
|
||||
this.create_time = create_time;
|
||||
}
|
||||
|
||||
public double getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(double fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public double getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(double deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public Double getVolume_open() {
|
||||
return volume_open;
|
||||
}
|
||||
|
||||
public void setVolume_open(Double volume_open) {
|
||||
this.volume_open = volume_open;
|
||||
}
|
||||
|
||||
public double getUnit_amount() {
|
||||
return unit_amount;
|
||||
}
|
||||
|
||||
public void setUnit_amount(double unit_amount) {
|
||||
this.unit_amount = unit_amount;
|
||||
}
|
||||
|
||||
}
|
||||
48
comm/Contract/src/project/contract/ContractApplyOrderService.java
Executable file
48
comm/Contract/src/project/contract/ContractApplyOrderService.java
Executable file
@@ -0,0 +1,48 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ContractApplyOrderService {
|
||||
/**
|
||||
* 创建委托单
|
||||
*/
|
||||
public void saveCreate(ContractApplyOrder order);
|
||||
|
||||
/**
|
||||
* 撤单
|
||||
*
|
||||
* @param order_no
|
||||
*/
|
||||
public void saveCancel(String partyId, String order_no);
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCancelAllByPartyId(String partyId);
|
||||
|
||||
public void update(ContractApplyOrder order);
|
||||
|
||||
public ContractApplyOrder findByOrderNo(String order_no);
|
||||
|
||||
/**
|
||||
* APP查询订单列表
|
||||
*
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param partyId
|
||||
* @param type orders 当前委托单 ,hisorders 历史委托单
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type);
|
||||
|
||||
/**
|
||||
* 所有未处理状态的委托单
|
||||
*/
|
||||
public List<ContractApplyOrder> findSubmitted();
|
||||
|
||||
public List<ContractApplyOrder> findSubmitted(String partyId, String symbol, String offset, String direction);
|
||||
|
||||
}
|
||||
22
comm/Contract/src/project/contract/ContractLock.java
Executable file
22
comm/Contract/src/project/contract/ContractLock.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ContractLock {
|
||||
private static final Set<String> filter = new HashSet<String>();
|
||||
|
||||
public static boolean add(String order_no) {
|
||||
if (!filter.add(order_no)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(String order_no) {
|
||||
filter.remove(order_no);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
82
comm/Contract/src/project/contract/ContractOrder.hbm.xml
Executable file
82
comm/Contract/src/project/contract/ContractOrder.hbm.xml
Executable file
@@ -0,0 +1,82 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
||||
<hibernate-mapping>
|
||||
<class name="project.contract.ContractOrder" table="T_CONTRACT_ORDER">
|
||||
<id name="id" type="java.lang.String">
|
||||
<column name="UUID" />
|
||||
<generator class="uuid.hex" />
|
||||
</id>
|
||||
<property name="partyId" type="java.lang.String">
|
||||
<column name="PARTY_ID" />
|
||||
</property>
|
||||
<property name="order_no" type="java.lang.String">
|
||||
<column name="ORDER_NO" />
|
||||
</property>
|
||||
<property name="symbol" type="java.lang.String">
|
||||
<column name="SYMBOL" />
|
||||
</property>
|
||||
<property name="direction" type="java.lang.String">
|
||||
<column name="DIRECTION" />
|
||||
</property>
|
||||
<property name="unit_amount" type="double">
|
||||
<column name="UNIT_AMOUNT" />
|
||||
</property>
|
||||
<property name="amount_close" type="double">
|
||||
<column name="AMOUNT_CLOSE" />
|
||||
</property>
|
||||
<property name="fee" type="double">
|
||||
<column name="FEE" />
|
||||
</property>
|
||||
<property name="deposit" type="double">
|
||||
<column name="DEPOSIT" />
|
||||
</property>
|
||||
<property name="deposit_open" type="double">
|
||||
<column name="DEPOSIT_OPEN" />
|
||||
</property>
|
||||
<property name="profit" type="double">
|
||||
<column name="PROFIT" />
|
||||
</property>
|
||||
<property name="trade_avg_price" type="double">
|
||||
<column name="TRADE_AVG_PRICE" />
|
||||
</property>
|
||||
<property name="close_avg_price" type="double">
|
||||
<column name="CLOSE_AVG_PRICE" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_profit" type="double">
|
||||
<column name="STOP_PRICE_PROFIT" />
|
||||
</property>
|
||||
|
||||
<property name="stop_price_loss" type="double">
|
||||
<column name="STOP_PRICE_LOSS" />
|
||||
</property>
|
||||
|
||||
<property name="pips" type="double">
|
||||
<column name="PIPS" />
|
||||
</property>
|
||||
|
||||
<property name="pips_amount" type="double">
|
||||
<column name="PIPS_AMOUNT" />
|
||||
</property>
|
||||
|
||||
<property name="state" type="java.lang.String">
|
||||
<column name="STATE" />
|
||||
</property>
|
||||
<property name="create_time" type="timestamp">
|
||||
<column name="CREATE_TIME" />
|
||||
</property>
|
||||
<property name="close_time" type="timestamp">
|
||||
<column name="CLOSE_TIME" />
|
||||
</property>
|
||||
<property name="lever_rate" type="double">
|
||||
<column name="LEVER_RATE" />
|
||||
</property>
|
||||
<property name="volume" type="double">
|
||||
<column name="VOLUME" />
|
||||
</property>
|
||||
<property name="volume_open" type="double">
|
||||
<column name="VOLUME_OPEN" />
|
||||
</property>
|
||||
</class>
|
||||
</hibernate-mapping>
|
||||
316
comm/Contract/src/project/contract/ContractOrder.java
Executable file
316
comm/Contract/src/project/contract/ContractOrder.java
Executable file
@@ -0,0 +1,316 @@
|
||||
package project.contract;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import kernel.bo.EntityObject;
|
||||
import kernel.util.Arith;
|
||||
|
||||
public class ContractOrder extends EntityObject {
|
||||
public final static String STATE_SUBMITTED = "submitted";
|
||||
public final static String STATE_CREATED = "created";
|
||||
/**
|
||||
* 多仓
|
||||
*/
|
||||
public final static String DIRECTION_BUY = "buy";
|
||||
/**
|
||||
* 空仓
|
||||
*/
|
||||
public final static String DIRECTION_SELL = "sell";
|
||||
private static final long serialVersionUID = 8847718625460348172L;
|
||||
|
||||
private Serializable partyId;
|
||||
private String symbol;
|
||||
/**
|
||||
* 订单 号
|
||||
*/
|
||||
private String order_no;
|
||||
/**
|
||||
* "buy":买(多) "sell":卖(空)
|
||||
*/
|
||||
private String direction;
|
||||
|
||||
/**
|
||||
* 每手金额
|
||||
*/
|
||||
private double unit_amount;
|
||||
|
||||
/**
|
||||
* 平仓退回金额
|
||||
*/
|
||||
private double amount_close;
|
||||
|
||||
/**
|
||||
* 手续费
|
||||
*/
|
||||
private double fee;
|
||||
|
||||
/**
|
||||
* 保证金(剩余)
|
||||
*/
|
||||
private double deposit;
|
||||
|
||||
/**
|
||||
* 保证金
|
||||
*/
|
||||
private double deposit_open;
|
||||
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
private double profit;
|
||||
|
||||
/**
|
||||
* 成交均价(成本)
|
||||
*/
|
||||
private Double trade_avg_price;
|
||||
|
||||
/**
|
||||
* 平仓均价
|
||||
*/
|
||||
private Double close_avg_price;
|
||||
|
||||
/**
|
||||
* 止盈触发价格
|
||||
*/
|
||||
private Double stop_price_profit;
|
||||
/**
|
||||
* 止损触发价格
|
||||
*/
|
||||
private Double stop_price_loss;
|
||||
|
||||
/**
|
||||
* 最小浮动
|
||||
*/
|
||||
private double pips;
|
||||
/**
|
||||
* 最小浮动金额(以交易金额计算)
|
||||
*/
|
||||
private double pips_amount;
|
||||
|
||||
/**
|
||||
* 状态。submitted 已提交(持仓), created 完成(平仓)
|
||||
*/
|
||||
private String state = "submitted";
|
||||
|
||||
private Date create_time;
|
||||
/**
|
||||
* 平仓时间
|
||||
*/
|
||||
private Date close_time;
|
||||
|
||||
/**
|
||||
* 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单]
|
||||
*/
|
||||
private Double lever_rate;
|
||||
|
||||
/**
|
||||
* 涨跌幅
|
||||
*/
|
||||
private double change_ratio;
|
||||
|
||||
/**
|
||||
* 委托数量(剩余)(张)
|
||||
*/
|
||||
private Double volume;
|
||||
/**
|
||||
* 委托数量(张)
|
||||
*/
|
||||
private Double volume_open;
|
||||
|
||||
public Double getChange_ratio() {
|
||||
if (STATE_SUBMITTED.equals(state)) {
|
||||
change_ratio = Arith.div(Arith.sub(Arith.add(Arith.add(amount_close, profit), deposit), deposit_open),
|
||||
deposit_open);
|
||||
} else {
|
||||
change_ratio = Arith.div(Arith.sub(Arith.add(amount_close, deposit), deposit_open), deposit_open);
|
||||
|
||||
}
|
||||
|
||||
change_ratio = Arith.mul(change_ratio, 100);
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return Double.valueOf(df.format(change_ratio));
|
||||
}
|
||||
|
||||
public Serializable getPartyId() {
|
||||
return partyId;
|
||||
}
|
||||
|
||||
public void setPartyId(Serializable partyId) {
|
||||
this.partyId = partyId;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public String getOrder_no() {
|
||||
return order_no;
|
||||
}
|
||||
|
||||
public void setOrder_no(String order_no) {
|
||||
this.order_no = order_no;
|
||||
}
|
||||
|
||||
public String getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(String direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public double getFee() {
|
||||
return fee;
|
||||
}
|
||||
|
||||
public void setFee(double fee) {
|
||||
this.fee = fee;
|
||||
}
|
||||
|
||||
public double getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(double deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public double getProfit() {
|
||||
return profit;
|
||||
}
|
||||
|
||||
public void setProfit(double profit) {
|
||||
this.profit = profit;
|
||||
}
|
||||
|
||||
public Double getTrade_avg_price() {
|
||||
return trade_avg_price;
|
||||
}
|
||||
|
||||
public void setTrade_avg_price(Double trade_avg_price) {
|
||||
this.trade_avg_price = trade_avg_price;
|
||||
}
|
||||
|
||||
public Double getStop_price_profit() {
|
||||
return stop_price_profit;
|
||||
}
|
||||
|
||||
public void setStop_price_profit(Double stop_price_profit) {
|
||||
this.stop_price_profit = stop_price_profit;
|
||||
}
|
||||
|
||||
public Double getStop_price_loss() {
|
||||
return stop_price_loss;
|
||||
}
|
||||
|
||||
public void setStop_price_loss(Double stop_price_loss) {
|
||||
this.stop_price_loss = stop_price_loss;
|
||||
}
|
||||
|
||||
public double getPips() {
|
||||
return pips;
|
||||
}
|
||||
|
||||
public void setPips(double pips) {
|
||||
this.pips = pips;
|
||||
}
|
||||
|
||||
public double getPips_amount() {
|
||||
return pips_amount;
|
||||
}
|
||||
|
||||
public void setPips_amount(double pips_amount) {
|
||||
this.pips_amount = pips_amount;
|
||||
}
|
||||
|
||||
public Date getCreate_time() {
|
||||
return create_time;
|
||||
}
|
||||
|
||||
public void setCreate_time(Date create_time) {
|
||||
this.create_time = create_time;
|
||||
}
|
||||
|
||||
public Double getLever_rate() {
|
||||
return lever_rate;
|
||||
}
|
||||
|
||||
public void setLever_rate(Double lever_rate) {
|
||||
this.lever_rate = lever_rate;
|
||||
}
|
||||
|
||||
public void setChange_ratio(double change_ratio) {
|
||||
this.change_ratio = change_ratio;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public double getAmount_close() {
|
||||
return amount_close;
|
||||
}
|
||||
|
||||
public void setAmount_close(double amount_close) {
|
||||
this.amount_close = amount_close;
|
||||
}
|
||||
|
||||
public double getDeposit_open() {
|
||||
return deposit_open;
|
||||
}
|
||||
|
||||
public void setDeposit_open(double deposit_open) {
|
||||
this.deposit_open = deposit_open;
|
||||
}
|
||||
|
||||
public double getUnit_amount() {
|
||||
return unit_amount;
|
||||
}
|
||||
|
||||
public void setUnit_amount(double unit_amount) {
|
||||
this.unit_amount = unit_amount;
|
||||
}
|
||||
|
||||
public Double getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(Double volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public Double getVolume_open() {
|
||||
return volume_open;
|
||||
}
|
||||
|
||||
public void setVolume_open(Double volume_open) {
|
||||
this.volume_open = volume_open;
|
||||
}
|
||||
|
||||
public Double getClose_avg_price() {
|
||||
return close_avg_price;
|
||||
}
|
||||
|
||||
public void setClose_avg_price(Double close_avg_price) {
|
||||
this.close_avg_price = close_avg_price;
|
||||
}
|
||||
|
||||
public Date getClose_time() {
|
||||
return close_time;
|
||||
}
|
||||
|
||||
public void setClose_time(Date close_time) {
|
||||
this.close_time = close_time;
|
||||
}
|
||||
|
||||
}
|
||||
67
comm/Contract/src/project/contract/ContractOrderService.java
Executable file
67
comm/Contract/src/project/contract/ContractOrderService.java
Executable file
@@ -0,0 +1,67 @@
|
||||
package project.contract;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import project.data.model.Realtime;
|
||||
|
||||
public interface ContractOrderService {
|
||||
|
||||
/**
|
||||
* 开仓
|
||||
*/
|
||||
public void saveOpen(ContractApplyOrder applyOrder, Realtime realtime);
|
||||
|
||||
/**
|
||||
* 平仓,按金额进行平仓
|
||||
*/
|
||||
public ContractApplyOrder saveClose(ContractApplyOrder applyOrder, Realtime realtime, String order_no);
|
||||
|
||||
/**
|
||||
* 平仓,按订单进行平仓
|
||||
*/
|
||||
public ContractOrder saveClose(String partyId, String order_no);
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCloseRemoveAllByPartyId(String partyId);
|
||||
|
||||
/**
|
||||
* 持仓单
|
||||
*/
|
||||
public List<ContractOrder> findSubmitted(String partyId, String symbol, String direction);
|
||||
|
||||
/**
|
||||
* 所有持仓单
|
||||
*/
|
||||
public List<ContractOrder> findSubmitted();
|
||||
|
||||
public ContractOrder findByOrderNo(String order_no);
|
||||
|
||||
public Map<String, Object> bulidOne(ContractOrder order);
|
||||
|
||||
/**
|
||||
* APP查询订单列表
|
||||
*
|
||||
* @param type orders 当前委托单 ,hisorders 历史委托单
|
||||
* @return
|
||||
*/
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type);
|
||||
|
||||
public void update(ContractOrder order);
|
||||
|
||||
public boolean lock(String order_no);
|
||||
|
||||
public void unlock(String order_no);
|
||||
|
||||
/**
|
||||
* 今日订单
|
||||
*
|
||||
* @param partyId
|
||||
* @return
|
||||
*/
|
||||
public List<ContractOrder> findByPartyIdAndToday(String partyId);
|
||||
}
|
||||
30
comm/Contract/src/project/contract/ContractRedisKeys.java
Executable file
30
comm/Contract/src/project/contract/ContractRedisKeys.java
Executable file
@@ -0,0 +1,30 @@
|
||||
package project.contract;
|
||||
|
||||
public class ContractRedisKeys {
|
||||
|
||||
/**
|
||||
* 永续合约,orderNo做key
|
||||
*/
|
||||
public final static String CONTRACT_ORDERNO = "CONTRACT_ORDERNO_";
|
||||
|
||||
/**
|
||||
* 永续合约,查询订单map,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_SUBMITTED_ORDER_PARTY_ID = "CONTRACT_SUBMITTED_ORDER_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总资产,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_PARTY_ID = "CONTRACT_ASSETS_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总保证金,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_DEPOSIT_PARTY_ID = "CONTRACT_ASSETS_DEPOSIT_PARTY_ID_";
|
||||
|
||||
/**
|
||||
* 永续合约,总未实现盈利,partyid做key
|
||||
*/
|
||||
public final static String CONTRACT_ASSETS_PROFIT_PARTY_ID = "CONTRACT_ASSETS_PROFIT_PARTY_ID_";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package project.contract.data.loadcache;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractRedisKeys;
|
||||
import project.redis.RedisHandler;
|
||||
import project.wallet.AssetService;
|
||||
|
||||
public class ContractLoadCacheService extends HibernateDaoSupport {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ContractLoadCacheService.class);
|
||||
|
||||
private RedisHandler redisHandler;
|
||||
private AssetService assetService;
|
||||
|
||||
public void loadcache() {
|
||||
load();
|
||||
logger.info("完成ContractOrder数据加载redis");
|
||||
}
|
||||
|
||||
public void load() {
|
||||
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder ");
|
||||
List<ContractOrder> list = (List<ContractOrder>) this.getHibernateTemplate().find(queryString.toString());
|
||||
|
||||
Map<String, Map<String, ContractOrder>> cacheMap = new ConcurrentHashMap<String, Map<String, ContractOrder>>();
|
||||
|
||||
// 永续合约:总资产、总保证金、总未实现盈利
|
||||
Map<String, Map<String, Double>> contractAssetsMap = new ConcurrentHashMap<String, Map<String, Double>>();
|
||||
|
||||
for (ContractOrder order : list) {
|
||||
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
|
||||
if (cacheMap.containsKey(order.getPartyId())) {
|
||||
Map<String, ContractOrder> map = cacheMap.get(order.getPartyId().toString());
|
||||
map.put(order.getOrder_no(), order);
|
||||
cacheMap.put(order.getPartyId().toString(), map);
|
||||
} else {
|
||||
Map<String, ContractOrder> map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
map.put(order.getOrder_no(), order);
|
||||
cacheMap.put(order.getPartyId().toString(), map);
|
||||
}
|
||||
|
||||
// 获取 单个订单 永续合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
|
||||
if (contractAssetsMap.containsKey(order.getPartyId())) {
|
||||
Map<String, Double> contractAssetsOld = contractAssetsMap.get(order.getPartyId().toString());
|
||||
if (null == contractAssetsOld) {
|
||||
contractAssetsOld = new HashMap<String, Double>();
|
||||
contractAssetsOld.put("money_contract", 0.000D);
|
||||
contractAssetsOld.put("money_contract_deposit", 0.000D);
|
||||
contractAssetsOld.put("money_contract_profit", 0.000D);
|
||||
}
|
||||
contractAssetsOld.put("money_contract", Arith.add(contractAssetsOld.get("money_contract"), contractAssetsOrder.get("money_contract")));
|
||||
contractAssetsOld.put("money_contract_deposit", Arith.add(contractAssetsOld.get("money_contract_deposit"), contractAssetsOrder.get("money_contract_deposit")));
|
||||
contractAssetsOld.put("money_contract_profit", Arith.add(contractAssetsOld.get("money_contract_profit"), contractAssetsOrder.get("money_contract_profit")));
|
||||
contractAssetsMap.put(order.getPartyId().toString(), contractAssetsOld);
|
||||
} else {
|
||||
contractAssetsMap.put(order.getPartyId().toString(), contractAssetsOrder);
|
||||
}
|
||||
}
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
}
|
||||
|
||||
for (Entry<String, Map<String, ContractOrder>> entry : cacheMap.entrySet()) {
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
for (Entry<String, Map<String, Double>> entry : contractAssetsMap.entrySet()) {
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract"));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract_deposit"));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + entry.getKey(), entry.getValue().get("money_contract_profit"));
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
public void setAssetService(AssetService assetService) {
|
||||
this.assetService = assetService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.contract.AdminContractApplyOrderService;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.party.recom.UserRecomService;
|
||||
|
||||
public class AdminContractApplyOrderServiceImpl extends HibernateDaoSupport implements AdminContractApplyOrderService {
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
private UserRecomService userRecomService;
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String state, String rolename, String loginPartyId,String username,String orderNo) {
|
||||
StringBuffer queryString = new StringBuffer(
|
||||
"SELECT orders.UUID id,orders.SYMBOL symbol,orders.ORDER_NO order_no,"
|
||||
+ "orders.DIRECTION direction,orders.OFFSET offset,"
|
||||
+ "orders.VOLUME_OPEN volume_open,orders.LEVER_RATE lever_rate,"
|
||||
+ "orders.STATE state,orders.ORDER_PRICE_TYPE order_price_type,"
|
||||
+ "orders.STOP_PRICE_LOSS stop_price_loss, orders.CREATE_TIME createTime,"
|
||||
+ "orders.STOP_PRICE_PROFIT stop_price_profit,"
|
||||
+ "orders.PRICE price,item.NAME itemname,");
|
||||
|
||||
queryString.append(
|
||||
" party.USERNAME username,party.USERCODE usercode,party.ROLENAME rolename ");
|
||||
|
||||
queryString.append(
|
||||
" FROM T_CONTRACT_APPLY_ORDER orders LEFT JOIN PAT_PARTY party ON orders.PARTY_ID = party.UUID LEFT JOIN T_ITEM item ON orders.SYMBOL=item.SYMBOL WHERE 1 = 1 ");
|
||||
|
||||
Map parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(loginPartyId)) {
|
||||
List children = this.userRecomService.findChildren(loginPartyId);
|
||||
if (children.size() == 0) {
|
||||
return Page.EMPTY_PAGE;
|
||||
}
|
||||
queryString.append(" and orders.PARTY_ID in (:children) ");
|
||||
parameters.put("children", children);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(state)) {
|
||||
queryString.append(" and orders.STATE = :state ");
|
||||
parameters.put("state", state);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(rolename)) {
|
||||
queryString.append(" and party.ROLENAME = :rolename ");
|
||||
parameters.put("rolename", rolename);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(orderNo)) {
|
||||
queryString.append(" and orders.ORDER_NO = :orderNo ");
|
||||
parameters.put("orderNo", orderNo);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(username)) {
|
||||
queryString.append("AND (party.USERNAME like:username OR party.USERCODE like:username ) ");
|
||||
parameters.put("username","%"+username+"%");
|
||||
}
|
||||
queryString.append(" order by orders.CREATE_TIME desc ");
|
||||
Page page = this.pagedQueryDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public ContractApplyOrder get(String id) {
|
||||
return getHibernateTemplate().get(ContractApplyOrder.class, id);
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setUserRecomService(UserRecomService userRecomService) {
|
||||
this.userRecomService = userRecomService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.party.recom.UserRecomService;
|
||||
|
||||
public class AdminContractOrderServiceImpl extends HibernateDaoSupport implements AdminContractOrderService {
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
private UserRecomService userRecomService;
|
||||
|
||||
public Page pagedQuery(int pageNo, int pageSize, String status, String rolename, String loginPartyId,String startTime,String endTime,String username,String orderNo) {
|
||||
StringBuffer queryString = new StringBuffer(
|
||||
"SELECT orders.UUID id,orders.SYMBOL symbol,orders.AMOUNT_CLOSE amount_close,"
|
||||
+ "orders.STOP_PRICE_PROFIT stop_price_profit,orders.STOP_PRICE_LOSS stop_price_loss,"
|
||||
+ "orders.ORDER_NO order_no,orders.TRADE_AVG_PRICE trade_avg_price,"
|
||||
+ "orders.DIRECTION direction,orders.UNIT_AMOUNT unit_amount,"
|
||||
+ "orders.STATE state,orders.FEE fee,orders.PROFIT profit,orders.CREATE_TIME createTime,"
|
||||
+ "orders.DEPOSIT deposit,orders.DEPOSIT_OPEN deposit_open,orders.CLOSE_TIME closeTime,"
|
||||
+ "orders.VOLUME_OPEN volume_open,orders.VOLUME volume,item.NAME itemname,");
|
||||
queryString.append(" wallet.MONEY money, ");
|
||||
queryString.append(" party.USERNAME username,party.USERCODE usercode,party.ROLENAME rolename ");
|
||||
|
||||
queryString.append(
|
||||
" FROM T_CONTRACT_ORDER orders LEFT JOIN PAT_PARTY party ON orders.PARTY_ID = party.UUID LEFT JOIN T_WALLET wallet ON wallet.PARTY_ID = party.UUID LEFT JOIN T_ITEM item ON orders.SYMBOL=item.SYMBOL WHERE 1 = 1 ");
|
||||
|
||||
Map parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(loginPartyId)) {
|
||||
List children = this.userRecomService.findChildren(loginPartyId);
|
||||
if (children.size() == 0) {
|
||||
return Page.EMPTY_PAGE;
|
||||
}
|
||||
queryString.append(" and orders.PARTY_ID in (:children) ");
|
||||
parameters.put("children", children);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(status)) {
|
||||
queryString.append(" and orders.STATE = :status ");
|
||||
parameters.put("status", status);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(rolename)) {
|
||||
queryString.append(" and party.ROLENAME = :rolename ");
|
||||
parameters.put("rolename", rolename);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(startTime)) {
|
||||
queryString.append(" and DATE(party.CREATE_TIME) >= DATE(:startTime) ");
|
||||
parameters.put("startTime", startTime);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(endTime)) {
|
||||
queryString.append(" and DATE(party.CREATE_TIME) <= DATE(:endTime) ");
|
||||
parameters.put("endTime", endTime);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(orderNo)) {
|
||||
queryString.append(" and orders.ORDER_NO = :orderNo ");
|
||||
parameters.put("orderNo", orderNo);
|
||||
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(username)) {
|
||||
queryString.append("AND (party.USERNAME like:username OR party.USERCODE like:username ) ");
|
||||
parameters.put("username","%"+username+"%");
|
||||
}
|
||||
queryString.append(" order by orders.CREATE_TIME desc ");
|
||||
Page page = this.pagedQueryDao.pagedQuerySQL(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public ContractOrder get(String id) {
|
||||
return getHibernateTemplate().get(ContractOrder.class, id);
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setUserRecomService(UserRecomService userRecomService) {
|
||||
this.userRecomService = userRecomService;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.AdminMarketQuotationsService;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataCache;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.AdminItemService;
|
||||
import project.item.model.Item;
|
||||
|
||||
public class AdminMarketQuotationsServiceImpl extends HibernateDaoSupport implements AdminMarketQuotationsService{
|
||||
|
||||
private AdminItemService adminItemService;
|
||||
private DataService dataService;
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
|
||||
public Page pageQuery(int pageNo,int pageSize) {
|
||||
Page page = adminItemService.pagedQuerySymbolsByMarket(pageNo, pageSize, null);
|
||||
// Page pagedQuery = adminItemService.pagedQuery(pageNo, pageSize);
|
||||
page.setElements(this.marketQuotationslist(page.getElements()));
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 行情列表
|
||||
* @param symbols
|
||||
* @return
|
||||
*/
|
||||
private List<Map<String,Object>> marketQuotationslist(List<String> symbols) {
|
||||
if(CollectionUtils.isEmpty(symbols)) return null;
|
||||
// List<String> symbols = new LinkedList<String>();
|
||||
// for(Item i:items) {
|
||||
// symbols.add(i.getSymbol());
|
||||
// }
|
||||
List<Map<String,Object>> resultList = new LinkedList<Map<String,Object>>();
|
||||
Map<String,Object> resultMap = new HashMap<String,Object>();
|
||||
List<Realtime> realtimes = this.dataService.realtime(StringUtils.join(symbols,","));
|
||||
Set<String> symbolKey =new HashSet<String>();
|
||||
for(Realtime realtime:realtimes) {
|
||||
if(symbolKey.contains(realtime.getSymbol())) continue;
|
||||
resultMap = new HashMap<String,Object>();
|
||||
resultMap.put("symbol", realtime.getSymbol());
|
||||
resultMap.put("name", realtime.getName());
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(realtime.getSymbol());
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", 0);
|
||||
resultMap.put("new_price", new BigDecimal(String.valueOf(realtime.getClose())).toPlainString());
|
||||
} else {
|
||||
resultMap.put("adjust_value", new BigDecimal(String.valueOf(currentValue)).toPlainString());
|
||||
resultMap.put("new_price", new BigDecimal(String.valueOf(Arith.sub(realtime.getClose(), currentValue))).toPlainString());
|
||||
}
|
||||
resultMap.put("after_value", new BigDecimal(String.valueOf(realtime.getClose())).toPlainString());
|
||||
// resultMap.put("url","http://192.168.43.170:8080/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// resultMap.put("url","http://172.20.10.2:8080/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// resultMap.put("url","http://45.76.212.230:8089/wap/#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
resultMap.put("url",Constants.WEB_URL+"#/pages/item/item_detail?symbol="+realtime.getSymbol());
|
||||
// if (currentValue == null) {
|
||||
// resultMap.put("new_price", realtime.getClose());
|
||||
// } else {
|
||||
// resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
// }
|
||||
resultList.add(resultMap);
|
||||
symbolKey.add(realtime.getSymbol());
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
|
||||
public void setAdminItemService(AdminItemService adminItemService) {
|
||||
this.adminItemService = adminItemService;
|
||||
}
|
||||
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
|
||||
public void setAdjustmentValueService(AdjustmentValueService adjustmentValueService) {
|
||||
this.adjustmentValueService = adjustmentValueService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
427
comm/Contract/src/project/contract/internal/ContractApplyOrderServiceImpl.java
Executable file
427
comm/Contract/src/project/contract/internal/ContractApplyOrderServiceImpl.java
Executable file
@@ -0,0 +1,427 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.item.model.ItemLever;
|
||||
import project.log.MoneyLog;
|
||||
import project.log.MoneyLogService;
|
||||
import project.party.PartyService;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
import util.DateUtil;
|
||||
import util.RandomUtil;
|
||||
|
||||
public class ContractApplyOrderServiceImpl extends HibernateDaoSupport implements ContractApplyOrderService {
|
||||
private SysparaService sysparaService;
|
||||
private PartyService partyService;
|
||||
private ItemService itemService;
|
||||
private MoneyLogService moneyLogService;
|
||||
private WalletService walletService;
|
||||
|
||||
private PagedQueryDao pagedQueryDao;
|
||||
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
@Override
|
||||
public void saveCreate(ContractApplyOrder order) {
|
||||
|
||||
if (order.getVolume_open() % 1 != 0) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
if (order.getVolume_open() <= 0) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
boolean order_open = this.sysparaService.find("order_open").getBoolean();
|
||||
if (!order_open) {
|
||||
throw new BusinessException("不在交易时段");
|
||||
}
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), true);
|
||||
if (item == null) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
|
||||
if (ContractApplyOrder.OFFSET_OPEN.equals(order.getOffset())) {
|
||||
this.open(order);
|
||||
} else if (ContractApplyOrder.OFFSET_CLOSE.equals(order.getOffset())) {
|
||||
this.close(order);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 开仓委托
|
||||
*/
|
||||
public void open(ContractApplyOrder order) {
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), false);
|
||||
List<ItemLever> levers = itemService.findLever(item.getId().toString());
|
||||
|
||||
if (order.getLever_rate() != null && order.getLever_rate() != 1) {
|
||||
boolean findlevers = false;
|
||||
/**
|
||||
* 杠杆有配置
|
||||
*/
|
||||
for (int i = 0; i < levers.size(); i++) {
|
||||
if (order.getLever_rate() == levers.get(i).getLever_rate()) {
|
||||
findlevers = true;
|
||||
}
|
||||
}
|
||||
if (!findlevers) {
|
||||
throw new BusinessException("参数错误");
|
||||
}
|
||||
}
|
||||
|
||||
List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), order.getDirection());
|
||||
for (int i = 0; i < order_state0_list.size(); i++) {
|
||||
Double source_lever_rate = order.getLever_rate();
|
||||
source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
|
||||
|
||||
Double target_lever_rate = order_state0_list.get(i).getLever_rate();
|
||||
target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
|
||||
if (source_lever_rate.compareTo(target_lever_rate) != 0) {
|
||||
throw new BusinessException("存在不同杠杆的持仓单");
|
||||
}
|
||||
// if (order.getLever_rate() != order_state0_list.get(i).getLever_rate()) {
|
||||
// throw new BusinessException("存在不同杠杆的持仓单");
|
||||
// }
|
||||
}
|
||||
List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), "open", order.getDirection());
|
||||
for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
|
||||
Double source_lever_rate = order.getLever_rate();
|
||||
source_lever_rate = source_lever_rate == null ? 0d : source_lever_rate;
|
||||
|
||||
Double target_lever_rate = applyOrder_submitted_list.get(i).getLever_rate();
|
||||
target_lever_rate = target_lever_rate == null ? 0d : target_lever_rate;
|
||||
if (source_lever_rate.compareTo(target_lever_rate) != 0) {
|
||||
throw new BusinessException("存在不同杠杆的持仓单");
|
||||
}
|
||||
// if (order.getLever_rate() != applyOrder_submitted_list.get(i).getLever_rate()) {
|
||||
// throw new BusinessException("存在不同杠杆的委托单");
|
||||
// }
|
||||
}
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
|
||||
order.setUnit_amount(item.getUnit_amount());
|
||||
|
||||
order.setFee(Arith.mul(item.getUnit_fee(), order.getVolume()));
|
||||
order.setDeposit(Arith.mul(item.getUnit_amount(), order.getVolume()));
|
||||
if (order.getLever_rate() != null) {
|
||||
/**
|
||||
* 加上杠杆
|
||||
*/
|
||||
order.setVolume(Arith.mul(order.getVolume(), order.getLever_rate()));
|
||||
order.setFee(Arith.mul(order.getFee(), order.getLever_rate()));
|
||||
}
|
||||
order.setVolume_open(order.getVolume());
|
||||
|
||||
order.setCreate_time(new Date());
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
if (wallet.getMoney() < Arith.add(order.getDeposit(), order.getFee())) {
|
||||
throw new BusinessException("余额不足");
|
||||
}
|
||||
|
||||
// wallet.setMoney(Arith.sub(wallet.getMoney(), order.getDeposit()));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.sub(0, order.getDeposit()));
|
||||
/*
|
||||
* 保存资金日志
|
||||
*/
|
||||
MoneyLog moneylog_deposit = new MoneyLog();
|
||||
moneylog_deposit.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog_deposit.setAmount_before(amount_before);
|
||||
moneylog_deposit.setAmount(Arith.sub(0, order.getDeposit()));
|
||||
moneylog_deposit.setAmount_after(Arith.sub(amount_before, order.getDeposit()));
|
||||
moneylog_deposit.setLog("委托单,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog_deposit.setPartyId(order.getPartyId());
|
||||
moneylog_deposit.setWallettype(Constants.WALLET);
|
||||
moneylog_deposit.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_OPEN);
|
||||
|
||||
moneyLogService.save(moneylog_deposit);
|
||||
|
||||
amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.sub(wallet.getMoney(), order.getFee()));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.sub(0, order.getFee()));
|
||||
|
||||
MoneyLog moneylog_fee = new MoneyLog();
|
||||
moneylog_fee.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog_fee.setAmount_before(amount_before);
|
||||
moneylog_fee.setAmount(Arith.sub(0, order.getFee()));
|
||||
moneylog_fee.setAmount_after(Arith.sub(amount_before, order.getFee()));
|
||||
moneylog_fee.setLog("手续费,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog_fee.setPartyId(order.getPartyId());
|
||||
moneylog_fee.setWallettype(Constants.WALLET);
|
||||
moneylog_fee.setContent_type(Constants.MONEYLOG_CONTENT_FEE);
|
||||
|
||||
moneyLogService.save(moneylog_fee);
|
||||
|
||||
getHibernateTemplate().save(order);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓委托
|
||||
*/
|
||||
public void close(ContractApplyOrder order) {
|
||||
Item item = this.itemService.cacheBySymbol(order.getSymbol(), false);
|
||||
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
order.setCreate_time(new Date());
|
||||
order.setUnit_amount(item.getUnit_amount());
|
||||
|
||||
double volume = 0;
|
||||
List<ContractOrder> order_state0_list = contractOrderService.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), order.getDirection());
|
||||
for (int i = 0; i < order_state0_list.size(); i++) {
|
||||
volume = Arith.add(volume, order_state0_list.get(i).getVolume());
|
||||
}
|
||||
List<ContractApplyOrder> applyOrder_submitted_list = this.findSubmitted(order.getPartyId().toString(),
|
||||
order.getSymbol(), ContractApplyOrder.OFFSET_CLOSE, order.getDirection());
|
||||
for (int i = 0; i < applyOrder_submitted_list.size(); i++) {
|
||||
volume = Arith.sub(volume, applyOrder_submitted_list.get(i).getVolume());
|
||||
}
|
||||
|
||||
if (order.getVolume() > volume) {
|
||||
throw new BusinessException("可平仓合约张数不足");
|
||||
// throw new BusinessException("可平仓合约数量不足");
|
||||
}
|
||||
|
||||
getHibernateTemplate().save(order);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCancelAllByPartyId(String partyId) {
|
||||
List<ContractApplyOrder> findSubmittedContractApplyOrders = findSubmitted(partyId, null, null, null);
|
||||
if (!CollectionUtils.isEmpty(findSubmittedContractApplyOrders)) {
|
||||
for (ContractApplyOrder applyOrder : findSubmittedContractApplyOrders) {
|
||||
saveCancel(applyOrder.getPartyId().toString(), applyOrder.getOrder_no());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveCancel(String partyId, String order_no) {
|
||||
|
||||
ContractApplyOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !"submitted".equals(order.getState()) || !partyId.equals(order.getPartyId().toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
order.setState("canceled");
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), Arith.add(order.getDeposit(), order.getFee())));
|
||||
// this.walletService.update(wallet);
|
||||
this.walletService.update(wallet.getPartyId().toString(), Arith.add(order.getDeposit(), order.getFee()));
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(Arith.add(order.getDeposit(), order.getFee()));
|
||||
moneylog.setAmount_after(Arith.add(amount_before, Arith.add(order.getDeposit(), order.getFee())));
|
||||
moneylog.setLog("撤单,订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CONCEL);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
update(order);
|
||||
}
|
||||
|
||||
public void update(ContractApplyOrder order) {
|
||||
this.getHibernateTemplate().update(order);
|
||||
|
||||
}
|
||||
|
||||
public ContractApplyOrder findByOrderNo(String order_no) {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractApplyOrder where order_no=?0");
|
||||
List<ContractApplyOrder> list = (List<ContractApplyOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
if (list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type) {
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractApplyOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
// Date date = DateUtils.addDay(new Date(), -1);
|
||||
|
||||
if ("orders".equals(type)) {
|
||||
// queryString.append(" and create_time >=:date");
|
||||
// parameters.put("date", date);
|
||||
queryString.append(" AND state =:state ");
|
||||
parameters.put("state", ContractApplyOrder.STATE_SUBMITTED);
|
||||
} else if ("hisorders".equals(type)) {
|
||||
// queryString.append(" and create_time <=:date");
|
||||
// parameters.put("date", date);
|
||||
queryString.append(" AND state in(:state) ");
|
||||
parameters.put("state",
|
||||
new String[] { ContractApplyOrder.STATE_CREATED, ContractApplyOrder.STATE_CANCELED });
|
||||
}
|
||||
|
||||
queryString.append(" order by create_time desc ");
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
List<Map<String, Object>> data = this.bulidData(page.getElements());
|
||||
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> bulidData(List<ContractApplyOrder> list) {
|
||||
List<Map<String, Object>> data = new ArrayList();
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractApplyOrder order = list.get(i);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("offset", order.getOffset());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("price", order.getPrice());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("order_price_type", order.getOrder_price_type());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
|
||||
data.add(map);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContractApplyOrder> findSubmitted() {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractApplyOrder where state=?0");
|
||||
return (List<ContractApplyOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { "submitted" });
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 未处理状态的委托单
|
||||
*/
|
||||
public List<ContractApplyOrder> findSubmitted(String partyId, String symbol, String offset, String direction) {
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractApplyOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(offset)) {
|
||||
queryString.append(" and offset =:offset ");
|
||||
parameters.put("offset", offset);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(direction)) {
|
||||
queryString.append(" and direction =:direction ");
|
||||
parameters.put("direction", direction);
|
||||
}
|
||||
|
||||
queryString.append(" and state =:state ");
|
||||
parameters.put("state", "submitted");
|
||||
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(0, Integer.MAX_VALUE, queryString.toString(), parameters);
|
||||
return page.getElements();
|
||||
|
||||
}
|
||||
|
||||
public void setSysparaService(SysparaService sysparaService) {
|
||||
this.sysparaService = sysparaService;
|
||||
}
|
||||
|
||||
public void setPartyService(PartyService partyService) {
|
||||
this.partyService = partyService;
|
||||
}
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public void setMoneyLogService(MoneyLogService moneyLogService) {
|
||||
this.moneyLogService = moneyLogService;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
}
|
||||
637
comm/Contract/src/project/contract/internal/ContractOrderServiceImpl.java
Executable file
637
comm/Contract/src/project/contract/internal/ContractOrderServiceImpl.java
Executable file
@@ -0,0 +1,637 @@
|
||||
package project.contract.internal;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.Page;
|
||||
import kernel.web.PagedQueryDao;
|
||||
import project.Constants;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.contract.ContractRedisKeys;
|
||||
import project.data.model.Realtime;
|
||||
import project.follow.Trader;
|
||||
import project.follow.TraderFollowUserOrder;
|
||||
import project.follow.TraderFollowUserOrderService;
|
||||
import project.follow.TraderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.MoneyLog;
|
||||
import project.log.MoneyLogService;
|
||||
import project.party.PartyService;
|
||||
import project.party.model.Party;
|
||||
import project.redis.RedisHandler;
|
||||
import project.tip.TipConstants;
|
||||
import project.tip.TipService;
|
||||
import project.user.UserDataService;
|
||||
import project.wallet.AssetService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
import util.DateUtil;
|
||||
import util.RandomUtil;
|
||||
|
||||
public class ContractOrderServiceImpl extends HibernateDaoSupport implements ContractOrderService {
|
||||
protected PagedQueryDao pagedQueryDao;
|
||||
protected WalletService walletService;
|
||||
protected UserDataService userDataService;
|
||||
|
||||
protected ItemService itemService;
|
||||
protected MoneyLogService moneyLogService;
|
||||
|
||||
protected ContractApplyOrderService contractApplyOrderService;
|
||||
|
||||
protected RedisHandler redisHandler;
|
||||
|
||||
protected TraderService traderService;
|
||||
protected TraderFollowUserOrderService traderFollowUserOrderService;
|
||||
|
||||
protected PartyService partyService;
|
||||
|
||||
protected TipService tipService;
|
||||
|
||||
protected AssetService assetService;
|
||||
|
||||
public void saveOpen(ContractApplyOrder applyOrder, Realtime realtime) {
|
||||
Item item = this.itemService.cacheBySymbol(applyOrder.getSymbol(), false);
|
||||
|
||||
ContractOrder order = new ContractOrder();
|
||||
order.setPartyId(applyOrder.getPartyId());
|
||||
order.setSymbol(applyOrder.getSymbol());
|
||||
order.setOrder_no(DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
|
||||
order.setDirection(applyOrder.getDirection());
|
||||
order.setLever_rate(applyOrder.getLever_rate());
|
||||
order.setVolume(applyOrder.getVolume());
|
||||
order.setVolume_open(applyOrder.getVolume_open());
|
||||
order.setUnit_amount(applyOrder.getUnit_amount());
|
||||
order.setFee(applyOrder.getFee());
|
||||
order.setDeposit(applyOrder.getDeposit());
|
||||
order.setDeposit_open(applyOrder.getDeposit());
|
||||
|
||||
order.setTrade_avg_price(realtime.getClose());
|
||||
order.setStop_price_profit(applyOrder.getStop_price_profit());
|
||||
order.setStop_price_loss(applyOrder.getStop_price_loss());
|
||||
|
||||
order.setPips(item.getPips());
|
||||
order.setPips_amount(item.getPips_amount());
|
||||
|
||||
order.setCreate_time(new Date());
|
||||
|
||||
this.getHibernateTemplate().save(order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
if (map == null) {
|
||||
map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
}
|
||||
map.put(order.getOrder_no(), order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, contractAssetsOrder.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, contractAssetsOrder.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, contractAssetsOrder.get("money_contract_profit")));
|
||||
|
||||
/**
|
||||
* 进入市场
|
||||
*/
|
||||
applyOrder.setVolume(0D);
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
|
||||
this.contractApplyOrderService.update(applyOrder);
|
||||
|
||||
/**
|
||||
* 如果是跟单订单,将持仓订单号也存入数据表
|
||||
*/
|
||||
/**
|
||||
* 交易员带单
|
||||
*/
|
||||
Trader trader = traderService.findByPartyId(applyOrder.getPartyId().toString());
|
||||
if (trader != null) {
|
||||
this.traderFollowUserOrderService.traderOpen(order);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否是跟单订单,如果是需要将TraderFollowUserOrder里的用户委托单号修改成用户持仓单号
|
||||
*
|
||||
*/
|
||||
TraderFollowUserOrder traderFollowUserOrder = this.traderFollowUserOrderService
|
||||
.findByPartyIdAndOrderNo(applyOrder.getPartyId().toString(), applyOrder.getOrder_no());
|
||||
if (traderFollowUserOrder != null) {
|
||||
traderFollowUserOrder.setUser_order_no(order.getOrder_no());
|
||||
this.traderFollowUserOrderService.update(traderFollowUserOrder);
|
||||
}
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRolename())) {
|
||||
tipService.saveTip(order.getId().toString(), TipConstants.CONTRACT_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
public ContractApplyOrder saveClose(ContractApplyOrder applyOrder, Realtime realtime, String order_no) {
|
||||
ContractOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState()) || order.getVolume() <= 0) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return applyOrder;
|
||||
}
|
||||
double volume;
|
||||
if (applyOrder.getVolume() > order.getVolume()) {
|
||||
volume = order.getVolume();
|
||||
} else {
|
||||
volume = applyOrder.getVolume();
|
||||
}
|
||||
/**
|
||||
* 平仓退回的金额
|
||||
*/
|
||||
double profit = this.settle(order, volume);
|
||||
update(order);
|
||||
// if (profit > 0) {
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), profit));/
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
|
||||
this.walletService.update(wallet.getPartyId().toString(), profit);
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(profit);
|
||||
moneylog.setAmount_after(Arith.add(amount_before, profit));
|
||||
moneylog.setLog("平仓,平仓合约数[" + volume + "],订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CLOSE);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
// }
|
||||
applyOrder.setVolume(Arith.sub(applyOrder.getVolume(), volume));
|
||||
if (applyOrder.getVolume() <= 0) {
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
}
|
||||
contractApplyOrderService.update(applyOrder);
|
||||
|
||||
/**
|
||||
* 交易员带单,用户跟单
|
||||
*/
|
||||
this.traderFollowUserOrderService.traderClose(order);
|
||||
|
||||
return applyOrder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户批量赎回订单
|
||||
*
|
||||
* @param partyId
|
||||
*/
|
||||
public void saveCloseRemoveAllByPartyId(String partyId) {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where partyId=?0");
|
||||
List<ContractOrder> orders = (List<ContractOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { partyId });
|
||||
List<ContractOrder> findSubmittedContractOrders = findSubmitted(partyId, null, null);
|
||||
if (!CollectionUtils.isEmpty(findSubmittedContractOrders)) {
|
||||
for (ContractOrder order : orders) {
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
}
|
||||
redisHandler.remove(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no());
|
||||
}
|
||||
redisHandler.remove(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + partyId);
|
||||
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + partyId);
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + partyId);
|
||||
this.redisHandler.remove(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + partyId);
|
||||
}
|
||||
}
|
||||
|
||||
public ContractOrder saveClose(String partyId, String order_no) {
|
||||
/*
|
||||
* 平仓
|
||||
*/
|
||||
ContractOrder order = this.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState())
|
||||
|| !partyId.equals(order.getPartyId().toString()) || order.getVolume() <= 0) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
double volume = order.getVolume();
|
||||
double profit = this.settle(order, order.getVolume());
|
||||
|
||||
// if (profit > 0) {
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
|
||||
double amount_before = wallet.getMoney();
|
||||
|
||||
// wallet.setMoney(Arith.add(wallet.getMoney(), profit));
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
|
||||
// this.walletService.update(wallet);
|
||||
if (Arith.add(wallet.getMoney(), profit) < 0) {
|
||||
profit = Arith.sub(0, wallet.getMoney());
|
||||
}
|
||||
this.walletService.update(wallet.getPartyId().toString(), profit);
|
||||
|
||||
MoneyLog moneylog = new MoneyLog();
|
||||
moneylog.setCategory(Constants.MONEYLOG_CATEGORY_CONTRACT);
|
||||
moneylog.setAmount_before(amount_before);
|
||||
moneylog.setAmount(profit);
|
||||
moneylog.setAmount_after(Arith.add(amount_before, profit));
|
||||
moneylog.setLog("平仓,平仓合约数[" + volume + "],订单号[" + order.getOrder_no() + "]");
|
||||
moneylog.setPartyId(order.getPartyId());
|
||||
moneylog.setWallettype(Constants.WALLET);
|
||||
moneylog.setContent_type(Constants.MONEYLOG_CONTENT_CONTRACT_CLOSE);
|
||||
|
||||
moneyLogService.save(moneylog);
|
||||
|
||||
// }
|
||||
|
||||
order.setState(ContractOrder.STATE_CREATED);
|
||||
order.setVolume(0D);
|
||||
order.setDeposit(0);
|
||||
order.setClose_time(new Date());
|
||||
update(order);
|
||||
|
||||
// this.userDataService.saveClose(order);
|
||||
|
||||
/**
|
||||
* 交易员带单,用户跟单
|
||||
*/
|
||||
this.traderFollowUserOrderService.traderClose(order);
|
||||
|
||||
/**
|
||||
* 合约产品平仓后添加当前流水
|
||||
*/
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
party.setWithdraw_limit_now_amount(Arith.add(party.getWithdraw_limit_now_amount(), order.getDeposit_open()));
|
||||
partyService.update(party);
|
||||
|
||||
return order;
|
||||
|
||||
}
|
||||
|
||||
public void update(ContractOrder order) {
|
||||
// this.getHibernateTemplate().update(order);
|
||||
this.getHibernateTemplate().merge(order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_ORDERNO + order.getOrder_no(), order);
|
||||
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
if (null == map) {
|
||||
map = new ConcurrentHashMap<String, ContractOrder>();
|
||||
}
|
||||
|
||||
ContractOrder orderOld = map.get(order.getOrder_no());
|
||||
|
||||
map.put(order.getOrder_no(), order);
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrder = this.assetService.getMoneyContractByOrder(order);
|
||||
Map<String, Double> contractAssetsOrderOld = this.assetService.getMoneyContractByOrder(orderOld);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, contractAssetsOrder.get("money_contract") - contractAssetsOrderOld.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, contractAssetsOrder.get("money_contract_deposit") - contractAssetsOrderOld.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, contractAssetsOrder.get("money_contract_profit") - contractAssetsOrderOld.get("money_contract_profit")));
|
||||
|
||||
} else if (ContractOrder.STATE_CREATED.equals(order.getState())) {
|
||||
// 平仓后,移除持仓列表
|
||||
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString());
|
||||
ContractOrder orderOld = null;
|
||||
if (map != null && !map.isEmpty()) {
|
||||
orderOld = map.get(order.getOrder_no());
|
||||
map.remove(order.getOrder_no());
|
||||
}
|
||||
redisHandler.setSync(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + order.getPartyId().toString(), map);
|
||||
|
||||
// 获取单个订单的合约总资产、总保证金、总未实现盈利
|
||||
Map<String, Double> contractAssetsOrderOld = this.assetService.getMoneyContractByOrder(orderOld);
|
||||
|
||||
Double contractAssets = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsDeposit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString());
|
||||
Double contractAssetsProfit = (Double) this.redisHandler.get(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString());
|
||||
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssets ? 0.000D : contractAssets, 0.000D - contractAssetsOrderOld.get("money_contract")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_DEPOSIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsDeposit ? 0.000D : contractAssetsDeposit, 0.000D - contractAssetsOrderOld.get("money_contract_deposit")));
|
||||
this.redisHandler.setSync(ContractRedisKeys.CONTRACT_ASSETS_PROFIT_PARTY_ID + order.getPartyId().toString(),
|
||||
Arith.add(null == contractAssetsProfit ? 0.000D : contractAssetsProfit, 0.000D - contractAssetsOrderOld.get("money_contract_profit")));
|
||||
|
||||
// 平仓则纪录数据(委托平仓,订单直接平仓)
|
||||
this.userDataService.saveClose(order);
|
||||
Party party = this.partyService.cachePartyBy(order.getPartyId(), false);
|
||||
if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRolename())) {
|
||||
tipService.deleteTip(order.getId().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收益结算,平仓时计算
|
||||
*
|
||||
* @param closevolume 平仓的张数
|
||||
*/
|
||||
public double settle(ContractOrder order, double volume) {
|
||||
double profit = 0;
|
||||
/**
|
||||
* 平仓比率
|
||||
*/
|
||||
double rate = Arith.div(volume, order.getVolume_open());
|
||||
|
||||
profit = Arith.mul(Arith.add(order.getDeposit(), order.getProfit()), rate);
|
||||
|
||||
order.setAmount_close(Arith.add(order.getAmount_close(), profit));
|
||||
|
||||
order.setVolume(Arith.sub(order.getVolume(), volume));
|
||||
order.setDeposit(Arith.sub(order.getDeposit(), Arith.mul(order.getDeposit_open(), rate)));
|
||||
|
||||
if (order.getVolume() <= 0) {
|
||||
order.setState(ContractOrder.STATE_CREATED);
|
||||
order.setClose_time(new Date());
|
||||
}
|
||||
|
||||
return profit;
|
||||
|
||||
}
|
||||
|
||||
public ContractOrder findByOrderNo(String order_no) {
|
||||
|
||||
// return (ContractOrder) redisHandler.get(ContractRedisKeys.CONTRACT_ORDERNO + order_no);
|
||||
//// StringBuffer queryString = new StringBuffer(" FROM ContractOrder where order_no=?");
|
||||
//// List<ContractOrder> list = getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
//// if (list.size() > 0) {
|
||||
//// return list.get(0);
|
||||
//// }
|
||||
//// return null;
|
||||
|
||||
ContractOrder order = (ContractOrder) this.redisHandler.get(ContractRedisKeys.CONTRACT_ORDERNO + order_no);
|
||||
if (null != order) {
|
||||
return order;
|
||||
}
|
||||
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where order_no=?0");
|
||||
List<ContractOrder> list = (List<ContractOrder>) this.getHibernateTemplate().find(queryString.toString(), new Object[] { order_no });
|
||||
if (list.size() > 0) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ContractOrder> findSubmitted(String partyId, String symbol, String direction) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {// 如果有partyId,走缓存查询
|
||||
Map<String, ContractOrder> map = (Map<String, ContractOrder>) redisHandler
|
||||
.get(ContractRedisKeys.CONTRACT_SUBMITTED_ORDER_PARTY_ID + partyId);
|
||||
List<ContractOrder> list = new ArrayList<ContractOrder>();
|
||||
if (map != null && !map.isEmpty()) {
|
||||
for (ContractOrder order : map.values()) {
|
||||
boolean valify = true;// 验证
|
||||
if (valify && !StringUtils.isNullOrEmpty(symbol)) {// 币种是否相同
|
||||
valify = symbol.equals(order.getSymbol());
|
||||
}
|
||||
if (valify && !StringUtils.isNullOrEmpty(direction)) {
|
||||
valify = direction.equals(order.getDirection());
|
||||
}
|
||||
if (valify) {// 条件全部满足,添加
|
||||
list.add(order);
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
}
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol ");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(direction)) {
|
||||
queryString.append(" and direction =:direction ");
|
||||
parameters.put("direction", direction);
|
||||
}
|
||||
|
||||
queryString.append(" and state =:state ");
|
||||
parameters.put("state", "submitted");
|
||||
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(0, Integer.MAX_VALUE, queryString.toString(), parameters);
|
||||
return page.getElements();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getPaged(int pageNo, int pageSize, String partyId, String symbol, String type) {
|
||||
StringBuffer queryString = new StringBuffer("");
|
||||
queryString.append(" FROM ");
|
||||
queryString.append(" ContractOrder ");
|
||||
queryString.append(" where 1=1 ");
|
||||
|
||||
Map<String, Object> parameters = new HashMap();
|
||||
queryString.append(" and partyId =:partyId");
|
||||
parameters.put("partyId", partyId);
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(symbol)) {
|
||||
queryString.append(" and symbol =:symbol");
|
||||
parameters.put("symbol", symbol);
|
||||
}
|
||||
|
||||
Date date = DateUtils.addDay(new Date(), -1);
|
||||
|
||||
if ("orders".equals(type)) {
|
||||
queryString.append(" and state =:state");
|
||||
parameters.put("state", "submitted");
|
||||
} else if ("hisorders".equals(type)) {
|
||||
queryString.append(" and state =:state");
|
||||
parameters.put("state", "created");
|
||||
}
|
||||
|
||||
queryString.append(" order by create_time desc ");
|
||||
Page page = this.pagedQueryDao.pagedQueryHql(pageNo, pageSize, queryString.toString(), parameters);
|
||||
|
||||
List<Map<String, Object>> data = this.bulidData(page.getElements());
|
||||
return data;
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> bulidData(List<ContractOrder> list) {
|
||||
List<Map<String, Object>> data = new ArrayList();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
Map<String, Object> map = bulidOne(order);
|
||||
data.add(map);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public Map<String, Object> bulidOne(ContractOrder order) {
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
if (order.getClose_time() != null) {
|
||||
map.put("close_time", DateUtils.format(order.getClose_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
} else {
|
||||
map.put("close_time", "");
|
||||
}
|
||||
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("trade_avg_price", order.getTrade_avg_price());
|
||||
map.put("close_avg_price", order.getClose_avg_price());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
map.put("deposit_open", order.getDeposit_open());
|
||||
map.put("change_ratio", order.getChange_ratio());
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
if (ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
map.put("profit",
|
||||
df.format(Arith.sub(
|
||||
Arith.add(Arith.add(order.getAmount_close(), order.getProfit()), order.getDeposit()),
|
||||
order.getDeposit_open())));
|
||||
} else {
|
||||
map.put("profit", df.format(
|
||||
Arith.sub(Arith.add(order.getAmount_close(), order.getDeposit()), order.getDeposit_open())));
|
||||
}
|
||||
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContractOrder> findSubmitted() {
|
||||
StringBuffer queryString = new StringBuffer(" FROM ContractOrder where state=?0");
|
||||
return (List<ContractOrder>) getHibernateTemplate().find(queryString.toString(), new Object[] { ContractOrder.STATE_SUBMITTED });
|
||||
}
|
||||
|
||||
public List<ContractOrder> findByPartyIdAndToday(String partyId) {
|
||||
List<ContractOrder> list = (List<ContractOrder>) getHibernateTemplate().find(
|
||||
" FROM ContractOrder WHERE partyId=?0 and DateDiff(create_time,NOW())=0 ", new Object[] { partyId });
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setUserDataService(UserDataService userDataService) {
|
||||
this.userDataService = userDataService;
|
||||
}
|
||||
|
||||
public void setItemService(ItemService itemService) {
|
||||
this.itemService = itemService;
|
||||
}
|
||||
|
||||
public void setMoneyLogService(MoneyLogService moneyLogService) {
|
||||
this.moneyLogService = moneyLogService;
|
||||
}
|
||||
|
||||
public void setContractApplyOrderService(ContractApplyOrderService contractApplyOrderService) {
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
}
|
||||
|
||||
public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
|
||||
this.pagedQueryDao = pagedQueryDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean lock(String order_no) {
|
||||
return ContractLock.add(order_no);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlock(String order_no) {
|
||||
ContractLock.remove(order_no);
|
||||
|
||||
}
|
||||
|
||||
public void setRedisHandler(RedisHandler redisHandler) {
|
||||
this.redisHandler = redisHandler;
|
||||
}
|
||||
|
||||
public void setTraderService(TraderService traderService) {
|
||||
this.traderService = traderService;
|
||||
}
|
||||
|
||||
public void setTraderFollowUserOrderService(TraderFollowUserOrderService traderFollowUserOrderService) {
|
||||
this.traderFollowUserOrderService = traderFollowUserOrderService;
|
||||
}
|
||||
|
||||
public void setPartyService(PartyService partyService) {
|
||||
this.partyService = partyService;
|
||||
}
|
||||
|
||||
public void setTipService(TipService tipService) {
|
||||
this.tipService = tipService;
|
||||
}
|
||||
|
||||
public void setAssetService(AssetService assetService) {
|
||||
this.assetService = assetService;
|
||||
}
|
||||
|
||||
}
|
||||
163
comm/Contract/src/project/contract/job/ContractApplyOrderHandleJob.java
Executable file
163
comm/Contract/src/project/contract/job/ContractApplyOrderHandleJob.java
Executable file
@@ -0,0 +1,163 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
|
||||
/**
|
||||
*
|
||||
* 委托单进入市场
|
||||
*/
|
||||
public class ContractApplyOrderHandleJob implements Runnable {
|
||||
private static Log logger = LogFactory.getLog(ContractApplyOrderHandleJob.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
private DataService dataService;
|
||||
|
||||
public void run() {
|
||||
/*
|
||||
* 系统启动先暂停30秒
|
||||
*/
|
||||
ThreadUtils.sleep(1000 * 30);
|
||||
while (true)
|
||||
try {
|
||||
List<ContractApplyOrder> list = this.contractApplyOrderService.findSubmitted();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractApplyOrder order = list.get(i);
|
||||
List<Realtime> realtime_list = this.dataService.realtime(order.getSymbol());
|
||||
Realtime realtime = null;
|
||||
if (realtime_list.size() > 0) {
|
||||
realtime = realtime_list.get(0);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("limit".equals(order.getOrder_price_type())) {
|
||||
/**
|
||||
* 限价单
|
||||
*/
|
||||
if ("buy".equals(order.getDirection())) {
|
||||
/**
|
||||
* 买涨
|
||||
*/
|
||||
if (realtime.getClose() <= order.getPrice()) {
|
||||
|
||||
this.handle(order, realtime);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
if (realtime.getClose() >= order.getPrice()) {
|
||||
this.handle(order, realtime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
/**
|
||||
* 非限制,直接进入市 场
|
||||
*/
|
||||
this.handle(order, realtime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("run fail", e);
|
||||
} finally {
|
||||
ThreadUtils.sleep(1000 * 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void handle(ContractApplyOrder applyOrder, Realtime realtime) {
|
||||
boolean lock = false;
|
||||
try {
|
||||
if (!ContractLock.add(applyOrder.getOrder_no())) {
|
||||
return;
|
||||
}
|
||||
lock = true;
|
||||
if ("open".equals(applyOrder.getOffset())) {
|
||||
this.contractOrderService.saveOpen(applyOrder, realtime);
|
||||
} else if ("close".equals(applyOrder.getOffset())) {
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*/
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted(applyOrder.getPartyId().toString(),
|
||||
applyOrder.getSymbol(), applyOrder.getDirection());
|
||||
if (list.size() == 0) {
|
||||
applyOrder.setVolume(0D);
|
||||
applyOrder.setState(ContractApplyOrder.STATE_CREATED);
|
||||
this.contractApplyOrderService.update(applyOrder);
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
boolean lock_order = false;
|
||||
try {
|
||||
if (!ContractLock.add(order.getOrder_no())) {
|
||||
continue;
|
||||
}
|
||||
lock_order = true;
|
||||
applyOrder = this.contractOrderService.saveClose(applyOrder, realtime, order.getOrder_no());
|
||||
|
||||
if (ContractApplyOrder.STATE_CREATED.equals(applyOrder.getState())) {
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock_order) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(order.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(applyOrder.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void start(){
|
||||
new Thread(this, "ContractApplyOrderHandleJob").start();
|
||||
if (logger.isInfoEnabled())
|
||||
logger.info("委托单处理线程启动!");
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setContractApplyOrderService(ContractApplyOrderService contractApplyOrderService) {
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
}
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
}
|
||||
78
comm/Contract/src/project/contract/job/ContractOrderCalculationJob.java
Executable file
78
comm/Contract/src/project/contract/job/ContractOrderCalculationJob.java
Executable file
@@ -0,0 +1,78 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
|
||||
public class ContractOrderCalculationJob implements Runnable {
|
||||
private static Log logger = LogFactory.getLog(ContractOrderCalculationJob.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private ContractOrderCalculationService contractOrderCalculationService;
|
||||
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder order = list.get(i);
|
||||
|
||||
boolean lock = false;
|
||||
try {
|
||||
if (!ContractLock.add(order.getOrder_no())) {
|
||||
continue;
|
||||
}
|
||||
lock = true;
|
||||
this.contractOrderCalculationService.saveCalculation(order.getOrder_no());
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
if (lock) {
|
||||
/**
|
||||
* 每秒处理20个订单
|
||||
*/
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(order.getOrder_no());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
logger.error("run fail", e);
|
||||
} finally {
|
||||
/**
|
||||
* 暂停0.1秒
|
||||
*/
|
||||
ThreadUtils.sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void start(){
|
||||
|
||||
new Thread(this, "ContractOrderCalculationJob").start();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("持仓单盈亏计算线程启动!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setContractOrderCalculationService(ContractOrderCalculationService contractOrderCalculationService) {
|
||||
this.contractOrderCalculationService = contractOrderCalculationService;
|
||||
}
|
||||
|
||||
}
|
||||
17
comm/Contract/src/project/contract/job/ContractOrderCalculationService.java
Executable file
17
comm/Contract/src/project/contract/job/ContractOrderCalculationService.java
Executable file
@@ -0,0 +1,17 @@
|
||||
package project.contract.job;
|
||||
|
||||
/**
|
||||
* 合约盈亏计算
|
||||
*/
|
||||
public interface ContractOrderCalculationService {
|
||||
|
||||
/*
|
||||
* 订单盈亏计算
|
||||
*/
|
||||
public void saveCalculation(String order_no);
|
||||
|
||||
public void setOrder_close_line(double order_close_line);
|
||||
|
||||
public void setOrder_close_line_type(int order_close_line_type);
|
||||
|
||||
}
|
||||
253
comm/Contract/src/project/contract/job/ContractOrderCalculationServiceImpl.java
Executable file
253
comm/Contract/src/project/contract/job/ContractOrderCalculationServiceImpl.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.contract.job;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.ThreadUtils;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
|
||||
public class ContractOrderCalculationServiceImpl implements ContractOrderCalculationService {
|
||||
private static Log logger = LogFactory.getLog(ContractOrderCalculationServiceImpl.class);
|
||||
private ContractOrderService contractOrderService;
|
||||
private DataService dataService;
|
||||
private WalletService walletService;
|
||||
/**
|
||||
* 平仓线 110%(订金价值 /收益=110%)
|
||||
*/
|
||||
public double order_close_line = 1.1;
|
||||
/**
|
||||
* 平仓方式 1全仓 2单个持仓
|
||||
*/
|
||||
public int order_close_line_type = 1;
|
||||
private SysparaService sysparaService;
|
||||
|
||||
public void saveCalculation(String order_no) {
|
||||
|
||||
try {
|
||||
ContractOrder order = contractOrderService.findByOrderNo(order_no);
|
||||
if (order == null || !ContractOrder.STATE_SUBMITTED.equals(order.getState())) {
|
||||
/**
|
||||
* 状态已改变,退出处理
|
||||
*/
|
||||
return;
|
||||
}
|
||||
List<Realtime> list = this.dataService.realtime(order.getSymbol());
|
||||
if (list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
Realtime realtime = list.get(0);
|
||||
|
||||
double close = realtime.getClose();
|
||||
|
||||
if (ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 0 买涨
|
||||
*/
|
||||
if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "profit", close);
|
||||
}
|
||||
|
||||
if (close <= Arith.sub(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "loss", close);
|
||||
}
|
||||
|
||||
} else {
|
||||
/*
|
||||
* 1 买跌
|
||||
*/
|
||||
if (close <= Arith.sub(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "profit", close);
|
||||
}
|
||||
if (close >= Arith.add(order.getTrade_avg_price(), order.getPips())) {
|
||||
settle(order, "loss", close);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logger.error("OrderCalculationServiceImpll run fail", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 盈亏计算
|
||||
*
|
||||
* @param profit_loss profit 盈 loss亏
|
||||
* @param currentPrice 当前点位
|
||||
*/
|
||||
public void settle(ContractOrder order, String profit_loss, double currentPrice) {
|
||||
|
||||
/**
|
||||
* 偏差点位
|
||||
*/
|
||||
double point = Arith.div(Math.abs(Arith.sub(currentPrice, order.getTrade_avg_price())), order.getPips());
|
||||
|
||||
/*
|
||||
* 根据偏 差点数和手数算出盈亏金额
|
||||
*/
|
||||
double amount = Arith.mul(Arith.mul(order.getPips_amount(), point), order.getVolume());
|
||||
|
||||
if ("profit".equals(profit_loss)) {
|
||||
/**
|
||||
* 盈 正数
|
||||
*/
|
||||
order.setProfit(Arith.add(0.0D, amount));
|
||||
} else if ("loss".equals(profit_loss)) {
|
||||
order.setProfit(Arith.sub(0.0D, amount));
|
||||
}
|
||||
/**
|
||||
* 多次平仓价格不对,后续修
|
||||
*/
|
||||
order.setClose_avg_price(currentPrice);
|
||||
this.contractOrderService.update(order);
|
||||
/**
|
||||
* 止盈价
|
||||
*/
|
||||
Double profit_stop = order.getStop_price_profit();
|
||||
if (profit_stop != null && profit_stop > 0 && ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 买涨
|
||||
*/
|
||||
if (currentPrice >= profit_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
} else if (profit_stop != null && profit_stop > 0
|
||||
&& ContractOrder.DIRECTION_SELL.equals(order.getDirection())) {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
if (currentPrice <= profit_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 止亏线
|
||||
*/
|
||||
Double loss_stop = order.getStop_price_loss();
|
||||
|
||||
if (loss_stop != null && loss_stop > 0 && ContractOrder.DIRECTION_BUY.equals(order.getDirection())) {
|
||||
/*
|
||||
* 买涨
|
||||
*/
|
||||
if (currentPrice <= loss_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
|
||||
}
|
||||
} else if (loss_stop != null && loss_stop > 0 && ContractOrder.DIRECTION_SELL.equals(order.getDirection())) {
|
||||
/**
|
||||
* 买跌
|
||||
*/
|
||||
|
||||
if (currentPrice >= loss_stop) {
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (order_close_line_type == 1) {
|
||||
/**
|
||||
* 收益
|
||||
*/
|
||||
double profit = 0;
|
||||
|
||||
List<ContractOrder> list = contractOrderService.findSubmitted(order.getPartyId().toString(), null, null);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder close_line = list.get(i);
|
||||
profit = Arith.add(profit, Arith.add(close_line.getProfit(), close_line.getDeposit()));
|
||||
}
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId().toString());
|
||||
|
||||
if (Arith.add(profit, wallet.getMoney()) <= 0) {
|
||||
/**
|
||||
* 触发全仓强平
|
||||
*/
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
ThreadUtils.sleep(100);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ContractOrder close_line = list.get(i);
|
||||
if (!order.getOrder_no().equals(close_line.getOrder_no())) {
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (ContractLock.add(close_line.getOrder_no())) {
|
||||
this.contractOrderService.saveClose(close_line.getPartyId().toString(),
|
||||
close_line.getOrder_no());
|
||||
/**
|
||||
* 处理完退出
|
||||
*/
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("error:", e);
|
||||
} finally {
|
||||
ContractLock.remove(close_line.getOrder_no());
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (order.getProfit() < 0 && (Arith.div(order.getDeposit(), Math.abs(order.getProfit())) <= Arith
|
||||
.div(order_close_line, 100))) {
|
||||
/**
|
||||
* 低于系统默认平仓线,进行强平
|
||||
*/
|
||||
this.contractOrderService.saveClose(order.getPartyId().toString(), order.getOrder_no());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void afterPropertiesSet() throws Exception {
|
||||
// order_close_line = this.sysparaService.find("order_close_line").getDouble();
|
||||
// order_close_line_type = this.sysparaService.find("order_close_line_type").getInteger();
|
||||
//
|
||||
// }
|
||||
|
||||
public void setDataService(DataService dataService) {
|
||||
this.dataService = dataService;
|
||||
}
|
||||
|
||||
public void setSysparaService(SysparaService sysparaService) {
|
||||
this.sysparaService = sysparaService;
|
||||
}
|
||||
|
||||
public void setContractOrderService(ContractOrderService contractOrderService) {
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
|
||||
public void setWalletService(WalletService walletService) {
|
||||
this.walletService = walletService;
|
||||
}
|
||||
|
||||
public void setOrder_close_line(double order_close_line) {
|
||||
this.order_close_line = order_close_line;
|
||||
}
|
||||
|
||||
public void setOrder_close_line_type(int order_close_line_type) {
|
||||
this.order_close_line_type = order_close_line_type;
|
||||
}
|
||||
|
||||
}
|
||||
128
comm/Contract/src/project/web/admin/AdminContractApplyOrderController.java
Executable file
128
comm/Contract/src/project/web/admin/AdminContractApplyOrderController.java
Executable file
@@ -0,0 +1,128 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractApplyOrderService;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
|
||||
/**
|
||||
* 永续合约委托
|
||||
*/
|
||||
@RestController
|
||||
public class AdminContractApplyOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminContractApplyOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractApplyOrderService adminContractApplyOrderService;
|
||||
@Autowired
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
|
||||
private final String action = "normal/adminContractApplyOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续合约委托列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String status_para = request.getParameter("status_para");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_apply_order_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
|
||||
this.page = this.adminContractApplyOrderService.pagedQuery(this.pageNo, this.pageSize, status_para,
|
||||
rolename_para, loginPartyId, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("status_para", status_para);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractApplyOrder order = this.contractApplyOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
this.contractApplyOrderService.saveCancel(order.getPartyId().toString(), order_no);
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
}
|
||||
557
comm/Contract/src/project/web/admin/AdminContractOrderController.java
Executable file
557
comm/Contract/src/project/web/admin/AdminContractOrderController.java
Executable file
@@ -0,0 +1,557 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.Log;
|
||||
import project.log.LogService;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
/**
|
||||
* 永续持仓单 当前单
|
||||
*/
|
||||
@RestController
|
||||
public class AdminContractOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractOrderService adminContractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
@Autowired
|
||||
private SecUserService secUserService;
|
||||
|
||||
private final String action = "normal/adminContractOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续合约持仓单列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, ContractOrder.STATE_SUBMITTED,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
List<Item> items = this.itemService.cacheGetAll();
|
||||
Item item_turn = null;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
item_turn = items.get(i);
|
||||
|
||||
if ("knc".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(1);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(1);
|
||||
items.add(1, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("abcoin".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(0);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(0);
|
||||
items.add(0, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("oxtrx".equals(item_turn.getSymbol())) {
|
||||
Item item_3 = items.get(0);
|
||||
if (item_3.getSymbol().equals(item_turn.getSymbol())) {
|
||||
continue;
|
||||
}
|
||||
items.remove(0);
|
||||
items.add(0, item_turn);
|
||||
items.remove(i);
|
||||
items.add(i, item_3);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> symbols = new LinkedHashMap<String, String>();
|
||||
for (Item item : items) {
|
||||
symbols.put(item.getSymbol(), item.getName());
|
||||
}
|
||||
|
||||
modelAndView.addObject("symbols", symbols);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 永续合约持仓单列表内容
|
||||
*/
|
||||
@RequestMapping(action + "content.action")
|
||||
public ModelAndView content(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_list_content");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
this.pageSize = 30;
|
||||
|
||||
String loginPartyId = getLoginPartyId();
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, ContractOrder.STATE_SUBMITTED,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示 调整页面
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整 页面计算
|
||||
*
|
||||
* type 0增加一个pips;1减少一个pips;2直接修改调整值;
|
||||
* value 调整值
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
String value = request.getParameter("value");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
String error = this.verif(type, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
int type_int = Integer.valueOf(request.getParameter("type")).intValue();
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
|
||||
if (0 == type_int) {
|
||||
temp = Arith.add(value_double, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (1 == type_int) {
|
||||
temp = Arith.sub(value_double, item.getPips());
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value_double;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*
|
||||
* value 调整值
|
||||
* second 延迟秒
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String value = request.getParameter("value");
|
||||
String second = request.getParameter("second");
|
||||
String username_login = request.getParameter("username_login");
|
||||
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verifAdjust(second, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double value_double = Double.valueOf(request.getParameter("value"));
|
||||
double second_double = Double.valueOf(request.getParameter("second"));
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
currentValue = realtime.getClose();
|
||||
}
|
||||
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
|
||||
String log = MessageFormat.format("ip:" + this.getIp() + ",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}", symbol,
|
||||
new BigDecimal(currentValue).toPlainString(), new BigDecimal(value_double).toPlainString(), second_double);
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, value_double, second_double);
|
||||
|
||||
saveLog(sec, username_login, log);
|
||||
ThreadUtils.sleep(1000);
|
||||
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(order.getPartyId().toString(), order_no, this.contractOrderService);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
public void saveLog(SecUser secUser, String operator, String context) {
|
||||
Log log = new Log();
|
||||
log.setCategory(Constants.LOG_CATEGORY_OPERATION);
|
||||
log.setOperator(operator);
|
||||
log.setUsername(secUser.getUsername());
|
||||
log.setPartyId(secUser.getPartyId());
|
||||
log.setLog(context);
|
||||
log.setCreateTime(new Date());
|
||||
this.logService.saveSync(log);
|
||||
}
|
||||
|
||||
protected String verif(String type, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(type)) {
|
||||
return "限制天数必填";
|
||||
}
|
||||
if (!StringUtils.isInteger(type)) {
|
||||
return "限制天数输入错误,请输入整数";
|
||||
}
|
||||
if (Integer.valueOf(type).intValue() < 0) {
|
||||
return "限制天数不能小于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
// if (Double.valueOf(value).doubleValue() < 0) {
|
||||
// return "调整值不能小于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String verifAdjust(String second, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(second)) {
|
||||
return "调整时间必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(second)) {
|
||||
return "调整时间不是浮点数";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
// if (Double.valueOf(value).doubleValue() <= 0) {
|
||||
// return "调整值不能小于等于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
|
||||
if (this.contractOrderService.lock(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
this.contractOrderService.unlock(order_no);
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
425
comm/Contract/src/project/web/admin/AdminHistoryContractOrderController.java
Executable file
425
comm/Contract/src/project/web/admin/AdminHistoryContractOrderController.java
Executable file
@@ -0,0 +1,425 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.PropertiesUtil;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminContractOrderService;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
|
||||
/**
|
||||
* 永续持仓单 历史单
|
||||
*/
|
||||
@RestController
|
||||
public class AdminHistoryContractOrderController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminHistoryContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private AdminContractOrderService adminContractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
|
||||
private final String action = "normal/adminHistoryContractOrderAction!";
|
||||
|
||||
/**
|
||||
* 获取 永续持仓历史单列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
String pageNo = request.getParameter("pageNo");
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
String order_no_para = request.getParameter("order_no_para");
|
||||
String name_para = request.getParameter("name_para");
|
||||
String rolename_para = request.getParameter("rolename_para");
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
String status_para = request.getParameter("status_para");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("contract_order_history_list");
|
||||
|
||||
try {
|
||||
|
||||
this.checkAndSetPageNo(pageNo);
|
||||
|
||||
// 直接取最大不做分页
|
||||
// this.pageSize = Integer.MAX_VALUE-1;
|
||||
|
||||
// if (StringUtils.isEmptyString(rolename_para)) {
|
||||
// rolename_para = Constants.SECURITY_ROLE_MEMBER;
|
||||
// }
|
||||
|
||||
String basePath = PropertiesUtil.getProperty("admin_url");
|
||||
basePath = this.getPath(request);
|
||||
|
||||
String loginPartyId = this.getLoginPartyId();
|
||||
|
||||
this.page = this.adminContractOrderService.pagedQuery(this.pageNo, this.pageSize, status_para,
|
||||
rolename_para, loginPartyId, start_time, end_time, name_para, order_no_para);
|
||||
|
||||
List<Map> list = this.page.getElements();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Map map = list.get(i);
|
||||
if (null == map.get("rolename")) {
|
||||
map.put("roleNameDesc", "");
|
||||
} else {
|
||||
String roleName = map.get("rolename").toString();
|
||||
map.put("roleNameDesc", Constants.ROLE_MAP.containsKey(roleName) ? Constants.ROLE_MAP.get(roleName) : roleName);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> symbols = new LinkedHashMap<String, String>();
|
||||
for (Item item : this.itemService.cacheGetAll()) {
|
||||
symbols.put(item.getSymbol(), item.getName());
|
||||
}
|
||||
|
||||
modelAndView.addObject("symbols", symbols);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("pageNo", this.pageNo);
|
||||
modelAndView.addObject("pageSize", this.pageSize);
|
||||
modelAndView.addObject("page", this.page);
|
||||
modelAndView.addObject("message", message);
|
||||
modelAndView.addObject("error", error);
|
||||
modelAndView.addObject("order_no_para", order_no_para);
|
||||
modelAndView.addObject("name_para", name_para);
|
||||
modelAndView.addObject("rolename_para", rolename_para);
|
||||
modelAndView.addObject("start_time", start_time);
|
||||
modelAndView.addObject("end_time", end_time);
|
||||
modelAndView.addObject("status_para", status_para);
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示 调整页面
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整 页面计算
|
||||
*
|
||||
* type 0增加一个pips;1减少一个pips;2直接修改调整值;
|
||||
* value 调整值
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
String value = request.getParameter("value");
|
||||
|
||||
Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
|
||||
try {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(this.getLoginPartyId())) {
|
||||
throw new BusinessException("无权限");
|
||||
}
|
||||
|
||||
String error = this.verif(type, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
int type_int = Integer.valueOf(request.getParameter("type")).intValue();
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (null == currentValue) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
|
||||
if (0 == type_int) {
|
||||
temp = Arith.add(value_double, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (1 == type_int) {
|
||||
temp = Arith.sub(value_double, item.getPips());
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value_double;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (null == currentValue) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
resultMap.put("code", 500);
|
||||
resultMap.put("message", "程序错误");
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*
|
||||
* value 调整值
|
||||
* second 延迟秒
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String value = request.getParameter("value");
|
||||
String second = request.getParameter("second");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
String error = this.verifAdjust(second, value);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double value_double = Double.valueOf(request.getParameter("value")).doubleValue();
|
||||
double second_double = Double.valueOf(request.getParameter("second")).doubleValue();
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, value_double, second_double);
|
||||
|
||||
ThreadUtils.sleep(1000);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓或撤单
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public ModelAndView close(HttpServletRequest request) {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ModelAndView modelAndView = new ModelAndView();
|
||||
modelAndView.setViewName("redirect:/" + action + "list.action");
|
||||
|
||||
try {
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
if (order != null) {
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(order.getPartyId().toString(), order_no, this.contractOrderService);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
}
|
||||
|
||||
} catch (BusinessException e) {
|
||||
modelAndView.addObject("error", e.getMessage());
|
||||
return modelAndView;
|
||||
} catch (Throwable t) {
|
||||
logger.error(" error ", t);
|
||||
modelAndView.addObject("error", "[ERROR] " + t.getMessage());
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
modelAndView.addObject("message", "操作成功");
|
||||
return modelAndView;
|
||||
}
|
||||
|
||||
private String getPath(HttpServletRequest request) {
|
||||
return String.format("%s://%s:%s%s", request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath());
|
||||
}
|
||||
|
||||
protected String verif(String type, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(type)) {
|
||||
return "限制天数必填";
|
||||
}
|
||||
if (!StringUtils.isInteger(type)) {
|
||||
return "限制天数输入错误,请输入整数";
|
||||
}
|
||||
if (Integer.valueOf(type).intValue() < 0) {
|
||||
return "限制天数不能小于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(value).doubleValue() < 0) {
|
||||
return "调整值不能小于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String verifAdjust(String second, String value) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(second)) {
|
||||
return "调整时间必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(second)) {
|
||||
return "调整时间不是浮点数";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)) {
|
||||
return "调整值必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(value)) {
|
||||
return "调整值不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(value).doubleValue() <= 0) {
|
||||
return "调整值不能小于等于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
|
||||
if (this.contractOrderService.lock(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
this.contractOrderService.unlock(order_no);
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
253
comm/Contract/src/project/web/admin/AdminMarketQuotationsManageController.java
Executable file
253
comm/Contract/src/project/web/admin/AdminMarketQuotationsManageController.java
Executable file
@@ -0,0 +1,253 @@
|
||||
package project.web.admin;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.providers.encoding.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.PageActionSupport;
|
||||
import project.Constants;
|
||||
import project.contract.AdminMarketQuotationsService;
|
||||
import project.data.AdjustmentValue;
|
||||
import project.data.AdjustmentValueService;
|
||||
import project.data.DataCache;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.log.LogService;
|
||||
import security.SecUser;
|
||||
import security.internal.SecUserService;
|
||||
|
||||
/**
|
||||
* 行情数据
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
public class AdminMarketQuotationsManageController extends PageActionSupport {
|
||||
|
||||
private Logger logger = LogManager.getLogger(AdminMarketQuotationsManageController.class);
|
||||
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private AdjustmentValueService adjustmentValueService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
@Autowired
|
||||
private AdminMarketQuotationsService adminMarketQuotationsService;
|
||||
@Autowired
|
||||
private SecUserService secUserService;
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
private final String action = "normal/adminMarketQuotationsManageAction!";
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public ModelAndView list(HttpServletRequest request) {
|
||||
|
||||
String message = request.getParameter("message");
|
||||
String error = request.getParameter("error");
|
||||
|
||||
this.checkAndSetPageNo(request.getParameter("pageNo"));
|
||||
this.pageSize = 30;
|
||||
this.page = this.adminMarketQuotationsService.pageQuery(this.pageNo, this.pageSize);
|
||||
|
||||
ModelAndView model = new ModelAndView();
|
||||
model.addObject("pageNo", this.pageNo);
|
||||
model.addObject("pageSize", this.pageSize);
|
||||
model.addObject("page", this.page);
|
||||
model.addObject("message", message);
|
||||
model.addObject("error", error);
|
||||
model.setViewName("market_quotations_list");
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
* 行情管理-调整弹框显示
|
||||
*/
|
||||
@RequestMapping(action + "showModal.action")
|
||||
public String showModal(HttpServletRequest request) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(getLoginPartyId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
Map<String, Double> resultMap = new HashMap<String, Double>();
|
||||
Realtime realtime = DataCache.getRealtime(symbol);
|
||||
if (realtime == null) {
|
||||
realtime = this.dataService.realtime(symbol).get(0);
|
||||
}
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", 0D);
|
||||
} else {
|
||||
resultMap.put("adjust_value", currentValue);
|
||||
}
|
||||
if (currentValue == null) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
resultMap.put("pips", item.getPips());
|
||||
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面计算
|
||||
*
|
||||
*/
|
||||
@RequestMapping(action + "getValue.action")
|
||||
public String getValue(HttpServletRequest request) {
|
||||
|
||||
if (!StringUtils.isNullOrEmpty(getLoginPartyId())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
String symbol = request.getParameter("symbol");
|
||||
// 0增加一个pips 1减少一个pips 2直接修改调整值
|
||||
String type_temp = request.getParameter("type");
|
||||
String value_temp = request.getParameter("value");
|
||||
|
||||
Double type = Double.valueOf(type_temp);
|
||||
Double value = Double.valueOf(value_temp);
|
||||
|
||||
Map<String, Double> resultMap = new HashMap<String, Double>();
|
||||
|
||||
Realtime realtime = null;
|
||||
|
||||
if (realtime == null) {
|
||||
realtime = this.dataService.realtime(symbol).get(0);
|
||||
}
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
resultMap.put("new_price", realtime.getClose());
|
||||
} else {
|
||||
resultMap.put("new_price", Arith.sub(realtime.getClose(), currentValue));
|
||||
}
|
||||
|
||||
double temp;
|
||||
if (type == 0) {
|
||||
temp = Arith.add(value, item.getPips());
|
||||
// 调整量
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
// 调整后的值
|
||||
resultMap.put("adjust_value_after", Double.valueOf(Arith.add(realtime.getClose(), temp)));
|
||||
} else if (type == 1) {
|
||||
temp = Arith.sub(value, item.getPips());
|
||||
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
} else {
|
||||
temp = value;
|
||||
resultMap.put("adjust_current_value", Double.valueOf(temp));
|
||||
resultMap.put("adjust_value_after", Arith.add(realtime.getClose(), temp));
|
||||
}
|
||||
|
||||
if (currentValue == null) {
|
||||
resultMap.put("adjust_value", Double.valueOf(item.getPips()));
|
||||
} else {
|
||||
resultMap.put("adjust_value", Arith.add(temp, currentValue));
|
||||
}
|
||||
AdjustmentValue delayValue = this.adjustmentValueService.getDelayValue(symbol);
|
||||
|
||||
if (delayValue != null) {
|
||||
resultMap.put("delay_value", delayValue.getValue());
|
||||
resultMap.put("delay_second", delayValue.getSecond());
|
||||
}
|
||||
|
||||
return JsonUtils.getJsonString(resultMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调整
|
||||
*/
|
||||
@RequestMapping(action + "adjust.action")
|
||||
public ModelAndView adjust(HttpServletRequest request) {
|
||||
|
||||
ModelAndView model = new ModelAndView();
|
||||
String message = "";
|
||||
String error = "";
|
||||
|
||||
// 调整值
|
||||
String value = request.getParameter("value");
|
||||
String symbol = request.getParameter("symbol");
|
||||
// 延迟秒
|
||||
String second = request.getParameter("second");
|
||||
|
||||
if (StringUtils.isNullOrEmpty(value)
|
||||
|| !StringUtils.isDouble(value)) {
|
||||
throw new BusinessException("请输入正确的调整值");
|
||||
}
|
||||
try {
|
||||
|
||||
Double currentValue = this.adjustmentValueService.getCurrentValue(symbol);
|
||||
if (currentValue == null) {
|
||||
Realtime realtime = this.dataService.realtime(symbol).get(0);;
|
||||
currentValue=realtime.getClose();
|
||||
}
|
||||
SecUser sec = this.secUserService.findUserByLoginName(this.getUsername_login());
|
||||
String log = MessageFormat.format("ip:"+this.getIp()+",管理员调整行情,币种:{0},原值:{1},调整值:{2},调整时间:{3}",
|
||||
symbol,new BigDecimal(currentValue).toPlainString(),new BigDecimal(value).toPlainString(),second);
|
||||
|
||||
this.adjustmentValueService.adjust(symbol, Double.valueOf(value), Double.valueOf(second));
|
||||
saveLog(sec, this.getUsername_login(), log);
|
||||
|
||||
ThreadUtils.sleep(1000);
|
||||
message = "操作成功";
|
||||
} catch (BusinessException e) {
|
||||
error = e.getMessage();
|
||||
} catch (Exception e) {
|
||||
logger.error("error ", e);
|
||||
error = "程序错误";
|
||||
}
|
||||
model.addObject("message", message);
|
||||
model.addObject("error", error);
|
||||
model.setViewName("redirect:/" + action + "list.action");
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public void saveLog(SecUser secUser, String operator,String context) {
|
||||
project.log.Log log = new project.log.Log();
|
||||
log.setCategory(Constants.LOG_CATEGORY_OPERATION);
|
||||
log.setOperator(operator);
|
||||
log.setUsername(secUser.getUsername());
|
||||
log.setPartyId(secUser.getPartyId());
|
||||
log.setLog(context);
|
||||
log.setCreateTime(new Date());
|
||||
logService.saveSync(log);
|
||||
}
|
||||
|
||||
}
|
||||
705
comm/Contract/src/project/web/api/ContractApplyOrderController.java
Executable file
705
comm/Contract/src/project/web/api/ContractApplyOrderController.java
Executable file
@@ -0,0 +1,705 @@
|
||||
package project.web.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.sessiontoken.SessionTokenService;
|
||||
import kernel.util.Arith;
|
||||
import kernel.util.DateUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.BaseAction;
|
||||
import kernel.web.ResultObject;
|
||||
import project.contract.ContractApplyOrder;
|
||||
import project.contract.ContractApplyOrderService;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.item.ItemService;
|
||||
import project.item.model.Item;
|
||||
import project.item.model.ItemLever;
|
||||
import project.party.PartyService;
|
||||
import project.party.model.Party;
|
||||
import project.syspara.SysparaService;
|
||||
import project.wallet.Wallet;
|
||||
import project.wallet.WalletService;
|
||||
|
||||
/**
|
||||
* 永续合约委托单
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class ContractApplyOrderController extends BaseAction {
|
||||
|
||||
private Logger logger = LogManager.getLogger(ContractApplyOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private ItemService itemService;
|
||||
@Autowired
|
||||
private WalletService walletService;
|
||||
@Autowired
|
||||
private PartyService partyService;
|
||||
@Autowired
|
||||
private SessionTokenService sessionTokenService;
|
||||
@Autowired
|
||||
protected SysparaService sysparaService;
|
||||
|
||||
private final String action = "/api/contractApplyOrder!";
|
||||
|
||||
/**
|
||||
* 开仓页面参数
|
||||
*
|
||||
* symbol 币种
|
||||
*/
|
||||
@RequestMapping(action + "openview.action")
|
||||
public Object openview(HttpServletRequest request) throws IOException {
|
||||
String symbol = request.getParameter("symbol");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
Item item = this.itemService.cacheBySymbol(symbol, false);
|
||||
data.put("amount", item.getUnit_amount());
|
||||
data.put("fee", item.getUnit_fee());
|
||||
|
||||
List<ItemLever> list = this.itemService.findLever(item.getId().toString());
|
||||
data.put("lever", list);
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
|
||||
Wallet wallet = this.walletService.saveWalletByPartyId(this.getLoginPartyId());
|
||||
|
||||
// 账户剩余资 金
|
||||
double use_amount = Arith.add(item.getUnit_amount(), item.getUnit_fee());
|
||||
double volume = Arith.div(wallet.getMoney(), use_amount);
|
||||
volume = new BigDecimal(volume).setScale(0, RoundingMode.DOWN).doubleValue();
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#");
|
||||
data.put("volume", df.format(volume));
|
||||
|
||||
String session_token = this.sessionTokenService.savePut(partyId);
|
||||
data.put("session_token", session_token);
|
||||
} else {
|
||||
data.put("volume", 0.00D);
|
||||
}
|
||||
|
||||
double contract_open_limit_min = Double.valueOf(this.sysparaService.find("contract_open_limit_min").getValue());
|
||||
data.put("contract_open_limit_min", contract_open_limit_min);
|
||||
double contract_open_limit_max = Double.valueOf(this.sysparaService.find("contract_open_limit_max").getValue());
|
||||
data.put("contract_open_limit_max", contract_open_limit_max);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓页面参数
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
*/
|
||||
@RequestMapping(action + "closeview.action")
|
||||
public Object closeview(HttpServletRequest request) throws IOException {
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
|
||||
try {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
if (!StringUtils.isNullOrEmpty(partyId)) {
|
||||
|
||||
List<ContractOrder> list = this.contractOrderService.findSubmitted(partyId, symbol, direction);
|
||||
|
||||
double ordervolume = 0;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
ordervolume = Arith.add(ordervolume, list.get(i).getVolume());
|
||||
}
|
||||
data.put("amount", ordervolume);
|
||||
|
||||
String session_token = this.sessionTokenService.savePut(partyId);
|
||||
data.put("session_token", session_token);
|
||||
} else {
|
||||
data.put("amount", 0);
|
||||
}
|
||||
|
||||
double contract_close_limit_min = Double.valueOf(this.sysparaService.find("contract_close_limit_min").getValue());
|
||||
data.put("contract_close_limit_min", contract_close_limit_min);
|
||||
double contract_close_limit_max = Double.valueOf(this.sysparaService.find("contract_close_limit_max").getValue());
|
||||
data.put("contract_close_limit_max", contract_close_limit_max);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开仓
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
* amount 委托数量(张)
|
||||
* lever_rate 杠杆倍数
|
||||
* price 交易价格
|
||||
* stop_price_profit 止盈触发价格
|
||||
* stop_price_loss 止损触发价格
|
||||
* price_type 订单报价类型:"limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
@RequestMapping(action + "open.action")
|
||||
public Object open(HttpServletRequest request) throws IOException {
|
||||
String session_token = request.getParameter("session_token");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
String amount = request.getParameter("amount");
|
||||
String lever_rate = request.getParameter("lever_rate");
|
||||
String price = request.getParameter("price");
|
||||
String stop_price_profit = request.getParameter("stop_price_profit");
|
||||
String stop_price_loss = request.getParameter("stop_price_loss");
|
||||
String price_type = request.getParameter("price_type");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
boolean lock = false;
|
||||
|
||||
try {
|
||||
|
||||
if (!ContractLock.add(partyId)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
lock = true;
|
||||
|
||||
Object object = this.sessionTokenService.cacheGet(session_token);
|
||||
this.sessionTokenService.delete(session_token);
|
||||
if (null == object || !this.getLoginPartyId().equals((String) object)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(lever_rate)) {
|
||||
lever_rate = "1";
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(stop_price_profit)) {
|
||||
stop_price_profit = "0";
|
||||
}
|
||||
if (StringUtils.isNullOrEmpty(stop_price_loss)) {
|
||||
stop_price_loss = "0";
|
||||
}
|
||||
|
||||
String error = this.verifOpen(amount, lever_rate, price, stop_price_profit, stop_price_loss);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double amount_double = Double.valueOf(request.getParameter("amount")).doubleValue();
|
||||
double lever_rate_double = Double.valueOf(lever_rate).doubleValue();
|
||||
double price_double = Double.valueOf(request.getParameter("price")).doubleValue();
|
||||
double stop_price_profit_double = Double.valueOf(stop_price_profit).doubleValue();
|
||||
double stop_price_loss_double = Double.valueOf(stop_price_loss).doubleValue();
|
||||
|
||||
Party party = this.partyService.cachePartyBy(partyId, false);
|
||||
if (!party.getEnabled()) {
|
||||
resultObject.setCode("506");
|
||||
resultObject.setMsg("用户已锁定");
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
// double contract_open_limit_min = Double.valueOf(this.sysparaService.find("contract_open_limit_min").getValue());
|
||||
// if (amount_double < contract_open_limit_min) {
|
||||
// throw new BusinessException("开仓金额不得小于开仓最小限额");
|
||||
// }
|
||||
// double contract_open_limit_max = Double.valueOf(this.sysparaService.find("contract_open_limit_max").getValue());
|
||||
// if (amount_double > contract_open_limit_max) {
|
||||
// throw new BusinessException("开仓金额不得大于开仓最大限额");
|
||||
// }
|
||||
|
||||
ContractApplyOrder order = new ContractApplyOrder();
|
||||
order.setPartyId(partyId);
|
||||
order.setSymbol(symbol);
|
||||
order.setDirection(direction);
|
||||
order.setOffset(ContractApplyOrder.OFFSET_OPEN);
|
||||
order.setVolume(amount_double);
|
||||
order.setVolume_open(amount_double);
|
||||
order.setLever_rate(lever_rate_double);
|
||||
order.setPrice(price_double);
|
||||
order.setStop_price_profit(stop_price_profit_double);
|
||||
order.setStop_price_loss(stop_price_loss_double);
|
||||
order.setOrder_price_type(price_type);
|
||||
|
||||
this.contractApplyOrderService.saveCreate(order);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(partyId);
|
||||
}
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*
|
||||
* symbol 币种
|
||||
* direction "buy":多 "sell":空
|
||||
* amount 委托数量(张)
|
||||
* price 交易价格
|
||||
* order_price_type 订单报价类型:"limit":限价 "opponent":对手价(市价)
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public Object close(HttpServletRequest request) throws IOException {
|
||||
String session_token = request.getParameter("session_token");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String direction = request.getParameter("direction");
|
||||
String amount = request.getParameter("amount");
|
||||
String price = request.getParameter("price");
|
||||
String price_type = request.getParameter("price_type");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
String partyId = this.getLoginPartyId();
|
||||
boolean lock = false;
|
||||
|
||||
try {
|
||||
|
||||
if (!ContractLock.add(partyId)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
lock = true;
|
||||
|
||||
Object object = this.sessionTokenService.cacheGet(session_token);
|
||||
this.sessionTokenService.delete(session_token);
|
||||
if (null == object || !this.getLoginPartyId().equals((String) object)) {
|
||||
throw new BusinessException("请稍后再试");
|
||||
}
|
||||
|
||||
String error = this.verifClose(amount, price);
|
||||
if (!StringUtils.isNullOrEmpty(error)) {
|
||||
throw new BusinessException(error);
|
||||
}
|
||||
|
||||
double amount_double = Double.valueOf(request.getParameter("amount")).doubleValue();
|
||||
double price_double = Double.valueOf(request.getParameter("price")).doubleValue();
|
||||
|
||||
Party party = this.partyService.cachePartyBy(partyId, false);
|
||||
if (!party.getEnabled()) {
|
||||
resultObject.setCode("506");
|
||||
resultObject.setMsg("用户已锁定");
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
// double contract_close_limit_min = Double.valueOf(this.sysparaService.find("contract_close_limit_min").getValue());
|
||||
// if (amount_double < contract_close_limit_min) {
|
||||
// throw new BusinessException("平仓金额不得小于平仓最小限额");
|
||||
// }
|
||||
// double contract_close_limit_max = Double.valueOf(this.sysparaService.find("contract_close_limit_max").getValue());
|
||||
// if (amount_double > contract_close_limit_max) {
|
||||
// throw new BusinessException("平仓金额不得大于平仓最大限额");
|
||||
// }
|
||||
|
||||
ContractApplyOrder order = new ContractApplyOrder();
|
||||
order.setPartyId(partyId);
|
||||
order.setSymbol(symbol);
|
||||
order.setDirection(direction);
|
||||
order.setOffset(ContractApplyOrder.OFFSET_CLOSE);
|
||||
order.setVolume(amount_double);
|
||||
order.setVolume_open(amount_double);
|
||||
order.setPrice(price_double);
|
||||
order.setOrder_price_type(price_type);
|
||||
|
||||
this.contractApplyOrderService.saveCreate(order);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (lock) {
|
||||
ThreadUtils.sleep(100);
|
||||
ContractLock.remove(partyId);
|
||||
}
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤单
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "cancel.action")
|
||||
public Object cancel(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CancelDelayThread lockDelayThread = new CancelDelayThread(this.getLoginPartyId(), order_no, this.contractApplyOrderService, false);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键撤单
|
||||
*/
|
||||
@RequestMapping(action + "cancelAll.action")
|
||||
public Object cancelAll(HttpServletRequest request) throws IOException {
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CancelDelayThread lockDelayThread = new CancelDelayThread(this.getLoginPartyId(), "", this.contractApplyOrderService, true);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单详情
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "get.action")
|
||||
public Object get(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(order_no)) {
|
||||
logger.info("contractApplyOrder!get order_no null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
ContractApplyOrder order = this.contractApplyOrderService.findByOrderNo(order_no);
|
||||
|
||||
if (null == order) {
|
||||
logger.info("contractApplyOrder!get order_no:" + order_no + ", order null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
resultObject.setData(this.bulidData(order));
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单列表
|
||||
*
|
||||
* page_no 页码
|
||||
* symbol 币种
|
||||
* type 查询类型:orders 当前委托单 ,hisorders 历史委托单
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public Object list(HttpServletRequest request) throws IOException {
|
||||
String page_no = request.getParameter("page_no");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
|
||||
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
resultObject.setData(data);
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(page_no)) {
|
||||
page_no = "1";
|
||||
}
|
||||
if (!StringUtils.isInteger(page_no)) {
|
||||
throw new BusinessException("页码不是整数");
|
||||
}
|
||||
if (Integer.valueOf(page_no).intValue() <= 0) {
|
||||
throw new BusinessException("页码不能小于等于0");
|
||||
}
|
||||
|
||||
int page_no_int = Integer.valueOf(page_no).intValue();
|
||||
|
||||
data = this.contractApplyOrderService.getPaged(page_no_int, 10, this.getLoginPartyId(), symbol, type);
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
private Map<String, Object> bulidData(ContractApplyOrder order) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("order_no", order.getOrder_no());
|
||||
map.put("name", this.itemService.cacheBySymbol(order.getSymbol(), false).getName());
|
||||
map.put("symbol", order.getSymbol());
|
||||
map.put("create_time", DateUtils.format(order.getCreate_time(), DateUtils.DF_yyyyMMddHHmmss));
|
||||
map.put("volume", order.getVolume());
|
||||
map.put("volume_open", order.getVolume_open());
|
||||
map.put("direction", order.getDirection());
|
||||
map.put("offset", order.getOffset());
|
||||
map.put("lever_rate", order.getLever_rate());
|
||||
map.put("price", order.getPrice());
|
||||
map.put("stop_price_profit", order.getStop_price_profit());
|
||||
map.put("stop_price_loss", order.getStop_price_loss());
|
||||
map.put("price_type", order.getOrder_price_type());
|
||||
map.put("state", order.getState());
|
||||
map.put("amount", Arith.mul(order.getVolume(), order.getUnit_amount()));
|
||||
map.put("amount_open", Arith.mul(order.getVolume_open(), order.getUnit_amount()));
|
||||
map.put("fee", order.getFee());
|
||||
map.put("deposit", order.getDeposit());
|
||||
return map;
|
||||
}
|
||||
|
||||
private String verifOpen(String amount, String lever_rate, String price, String stop_price_profit, String stop_price_loss) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(amount)) {
|
||||
return "委托金额必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(amount)) {
|
||||
return "委托金额不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(amount).doubleValue() <= 0) {
|
||||
return "委托金额不能小于等于0";
|
||||
}
|
||||
|
||||
// if (StringUtils.isNullOrEmpty(lever_rate)) {
|
||||
// return "杠杆倍数必填";
|
||||
// }
|
||||
if (!StringUtils.isDouble(lever_rate)) {
|
||||
return "杠杆倍数不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(lever_rate).doubleValue() <= 0) {
|
||||
return "杠杆倍数不能小于等于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(price)) {
|
||||
return "交易价格必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(price)) {
|
||||
return "交易价格不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(price).doubleValue() <= 0) {
|
||||
return "交易价格不能小于等于0";
|
||||
}
|
||||
|
||||
// if (StringUtils.isNullOrEmpty(stop_price_profit)) {
|
||||
// return "止盈触发价格必填";
|
||||
// }
|
||||
// if (!StringUtils.isDouble(stop_price_profit)) {
|
||||
// return "止盈触发价格不是浮点数";
|
||||
// }
|
||||
// if (Double.valueOf(stop_price_profit).doubleValue() < 0) {
|
||||
// return "止盈触发价格不能小于0";
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.isNullOrEmpty(stop_price_loss)) {
|
||||
// return "止损触发价格必填";
|
||||
// }
|
||||
// if (!StringUtils.isDouble(stop_price_loss)) {
|
||||
// return "止损触发价格不是浮点数";
|
||||
// }
|
||||
// if (Double.valueOf(stop_price_loss).doubleValue() < 0) {
|
||||
// return "止损触发价格不能小于0";
|
||||
// }
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String verifClose(String amount, String price) {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(amount)) {
|
||||
return "委托金额必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(amount)) {
|
||||
return "委托金额不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(amount).doubleValue() <= 0) {
|
||||
return "委托金额不能小于等于0";
|
||||
}
|
||||
|
||||
if (StringUtils.isNullOrEmpty(price)) {
|
||||
return "交易价格必填";
|
||||
}
|
||||
if (!StringUtils.isDouble(price)) {
|
||||
return "交易价格不是浮点数";
|
||||
}
|
||||
if (Double.valueOf(price).doubleValue() <= 0) {
|
||||
return "交易价格不能小于等于0";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CancelDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractApplyOrderService contractApplyOrderService;
|
||||
private boolean all = false;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (true == all) {
|
||||
// 一键撤单
|
||||
if (ContractLock.add("all")) {
|
||||
this.contractApplyOrderService.saveCancelAllByPartyId(partyId);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(100);
|
||||
} else {
|
||||
if (ContractLock.add(order_no)) {
|
||||
this.contractApplyOrderService.saveCancel(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
ThreadUtils.sleep(100);
|
||||
if (true == all) {
|
||||
ContractLock.remove("all");
|
||||
} else {
|
||||
ContractLock.remove(order_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CancelDelayThread(String partyId, String order_no, ContractApplyOrderService contractApplyOrderService, boolean all) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractApplyOrderService = contractApplyOrderService;
|
||||
this.all = all;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
294
comm/Contract/src/project/web/api/ContractOrderController.java
Executable file
294
comm/Contract/src/project/web/api/ContractOrderController.java
Executable file
@@ -0,0 +1,294 @@
|
||||
package project.web.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import kernel.exception.BusinessException;
|
||||
import kernel.util.JsonUtils;
|
||||
import kernel.util.StringUtils;
|
||||
import kernel.util.ThreadUtils;
|
||||
import kernel.web.BaseAction;
|
||||
import kernel.web.ResultObject;
|
||||
import project.Constants;
|
||||
import project.contract.ContractLock;
|
||||
import project.contract.ContractOrder;
|
||||
import project.contract.ContractOrderService;
|
||||
import project.data.DataService;
|
||||
import project.data.model.Realtime;
|
||||
|
||||
/**
|
||||
* 永续合约持仓单
|
||||
*/
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class ContractOrderController extends BaseAction {
|
||||
|
||||
private Logger logger = LogManager.getLogger(ContractOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private ContractOrderService contractOrderService;
|
||||
@Autowired
|
||||
private DataService dataService;
|
||||
|
||||
private final String action = "/api/contractOrder!";
|
||||
|
||||
/**
|
||||
* 平仓
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "close.action")
|
||||
public Object close(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(this.getLoginPartyId(), order_no, this.contractOrderService, false);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一键平仓
|
||||
*/
|
||||
@RequestMapping(action + "closeAll.action")
|
||||
public Object closeAll(HttpServletRequest request) throws IOException {
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
CloseDelayThread lockDelayThread = new CloseDelayThread(this.getLoginPartyId(), "", this.contractOrderService, true);
|
||||
Thread t = new Thread(lockDelayThread);
|
||||
t.start();
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单列表
|
||||
*
|
||||
* page_no 页码
|
||||
* symbol 币种
|
||||
* type 查询类型:orders 当前持仓单;hisorders 历史持仓单;
|
||||
*/
|
||||
@RequestMapping(action + "list.action")
|
||||
public Object list(HttpServletRequest request) throws IOException {
|
||||
String page_no = request.getParameter("page_no");
|
||||
String symbol = request.getParameter("symbol");
|
||||
String type = request.getParameter("type");
|
||||
|
||||
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(page_no)) {
|
||||
page_no = "1";
|
||||
}
|
||||
if (!StringUtils.isInteger(page_no)) {
|
||||
throw new BusinessException("页码不是整数");
|
||||
}
|
||||
if (Integer.valueOf(page_no).intValue() <= 0) {
|
||||
throw new BusinessException("页码不能小于等于0");
|
||||
}
|
||||
|
||||
int page_no_int = Integer.valueOf(page_no).intValue();
|
||||
|
||||
data = this.contractOrderService.getPaged(page_no_int, 10, this.getLoginPartyId(), symbol, type);
|
||||
|
||||
String symbolsStr = "";
|
||||
Set<String> symbols = new HashSet<String>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
String sym = data.get(i).get("symbol").toString();
|
||||
if (!symbols.contains(sym)) {
|
||||
symbols.add(sym);
|
||||
if (i != 0) {
|
||||
symbolsStr = symbolsStr + "," + sym;
|
||||
} else {
|
||||
symbolsStr = sym;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Realtime> realtime_all = this.dataService.realtime(symbolsStr);
|
||||
if (realtime_all.size() <= 0) {
|
||||
realtime_all = new ArrayList<Realtime>();
|
||||
// throw new BusinessException("系统错误,请稍后重试");
|
||||
}
|
||||
|
||||
Map<String, Realtime> realtimeMap = new HashMap<String, Realtime>();
|
||||
for (int i = 0; i < realtime_all.size(); i++) {
|
||||
realtimeMap.put(realtime_all.get(i).getSymbol(), realtime_all.get(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
Map<String, Object> map = data.get(i);
|
||||
|
||||
// 标记价格
|
||||
Realtime realtime = realtimeMap.get(map.get("symbol"));
|
||||
if (null == realtime) {
|
||||
map.put("mark_price", 0);
|
||||
} else {
|
||||
map.put("mark_price", realtime.getClose());
|
||||
}
|
||||
}
|
||||
|
||||
resultObject.setData(data);
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
*
|
||||
* order_no 订单号
|
||||
*/
|
||||
@RequestMapping(action + "get.action")
|
||||
public Object get(HttpServletRequest request) throws IOException {
|
||||
String order_no = request.getParameter("order_no");
|
||||
|
||||
ResultObject resultObject = new ResultObject();
|
||||
resultObject = this.readSecurityContextFromSession(resultObject);
|
||||
if (!"0".equals(resultObject.getCode())) {
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isNullOrEmpty(order_no)) {
|
||||
logger.info("contractOrder!get order_no null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
ContractOrder order = this.contractOrderService.findByOrderNo(order_no);
|
||||
|
||||
if (null == order) {
|
||||
logger.info("contractOrder!get order_no:" + order_no + ", order null");
|
||||
throw new BusinessException("订单不存在");
|
||||
}
|
||||
|
||||
resultObject.setData(this.contractOrderService.bulidOne(order));
|
||||
|
||||
} catch (BusinessException e) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg(e.getMessage());
|
||||
} catch (Throwable t) {
|
||||
resultObject.setCode("1");
|
||||
resultObject.setMsg("程序错误");
|
||||
logger.error("error:", t);
|
||||
}
|
||||
|
||||
return resultObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新线程处理,直接拿到订单锁处理完成后退出
|
||||
*/
|
||||
public class CloseDelayThread implements Runnable {
|
||||
private String partyId;
|
||||
private String order_no;
|
||||
private ContractOrderService contractOrderService;
|
||||
private boolean all = false;
|
||||
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
|
||||
while (true) {
|
||||
if (true == all) {
|
||||
// 一键平仓
|
||||
if (ContractLock.add("all")) {
|
||||
this.contractOrderService.saveCloseRemoveAllByPartyId(partyId);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
} else {
|
||||
if (ContractLock.add(order_no)) {
|
||||
this.contractOrderService.saveClose(partyId, order_no);
|
||||
// 处理完退出
|
||||
break;
|
||||
}
|
||||
ThreadUtils.sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
logger.error("error:", t);
|
||||
} finally {
|
||||
if (true == all) {
|
||||
ContractLock.remove("all");
|
||||
} else {
|
||||
ContractLock.remove(order_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CloseDelayThread(String partyId, String order_no, ContractOrderService contractOrderService, boolean all) {
|
||||
this.partyId = partyId;
|
||||
this.order_no = order_no;
|
||||
this.contractOrderService = contractOrderService;
|
||||
this.all = all;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user