├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── ee │ │ └── ctp │ │ ├── ApplicationRuntime.java │ │ ├── CtpClient.java │ │ ├── RequestIdentity.java │ │ ├── dto │ │ ├── ErrRtnOrderAction.java │ │ ├── FtdcReq.java │ │ ├── FtdcRsp.java │ │ ├── HeartBeat.java │ │ ├── ReqAccountRegister.java │ │ ├── ReqAuth.java │ │ ├── ReqContractBank.java │ │ ├── ReqFromBankToFuture.java │ │ ├── ReqFromFutureToBank.java │ │ ├── ReqFundPasswordUpdate.java │ │ ├── ReqInputOrder.java │ │ ├── ReqInvestorPosition.java │ │ ├── ReqOrderAction.java │ │ ├── ReqQryCommissionRate.java │ │ ├── ReqQryInstrument.java │ │ ├── ReqQryMarginRate.java │ │ ├── ReqQryOrder.java │ │ ├── ReqQrySettlementInfoConfirm.java │ │ ├── ReqQryTrade.java │ │ ├── ReqQryTransferSerial.java │ │ ├── ReqSettlementInfo.java │ │ ├── ReqSettlementInfoConfirm.java │ │ ├── ReqTradingAccount.java │ │ ├── ReqUserLogin.java │ │ ├── ReqUserLogout.java │ │ ├── ReqUserPasswordUpdate.java │ │ ├── RspAccountRegister.java │ │ ├── RspAuth.java │ │ ├── RspContractBank.java │ │ ├── RspError.java │ │ ├── RspFromBankToFuture.java │ │ ├── RspFundPasswordUpdate.java │ │ ├── RspFutureOrBank.java │ │ ├── RspInputOrder.java │ │ ├── RspInvestorPosition.java │ │ ├── RspOrderAction.java │ │ ├── RspQryCommissionRate.java │ │ ├── RspQryInstrument.java │ │ ├── RspQryMarginRate.java │ │ ├── RspQrySettlementInfoConfirm.java │ │ ├── RspQryTransferSerial.java │ │ ├── RspSettlementInfo.java │ │ ├── RspSettlementInfoConfirm.java │ │ ├── RspTradingAccount.java │ │ ├── RspUserLogin.java │ │ ├── RspUserLogout.java │ │ ├── RspUserPasswordUpdate.java │ │ ├── RtnBankOrFuture.java │ │ ├── RtnOrder.java │ │ ├── RtnTrade.java │ │ └── UserSession.java │ │ ├── enums │ │ ├── CTPErrorCode.java │ │ ├── ChainType.java │ │ ├── FtdTagType.java │ │ ├── FtdType.java │ │ ├── FtdcType.java │ │ ├── Sequence.java │ │ ├── TID.java │ │ └── business │ │ │ ├── FtdcActionFlagType.java │ │ │ ├── FtdcAvailabilityFlagType.java │ │ │ ├── FtdcBankAccType.java │ │ │ ├── FtdcBillHedgeFlag.java │ │ │ ├── FtdcCombinationType.java │ │ │ ├── FtdcContingentCondition.java │ │ │ ├── FtdcCurrencyID.java │ │ │ ├── FtdcCustType.java │ │ │ ├── FtdcDirection.java │ │ │ ├── FtdcExchange.java │ │ │ ├── FtdcFeePayFlagType.java │ │ │ ├── FtdcForceCLoseReson.java │ │ │ ├── FtdcFutureAccType.java │ │ │ ├── FtdcIdCardType.java │ │ │ ├── FtdcInstLifePhaseType.java │ │ │ ├── FtdcInvestorRangeType.java │ │ │ ├── FtdcLastFragmentType.java │ │ │ ├── FtdcMaxMarginSideAlgorithmType.java │ │ │ ├── FtdcOffsetFlagType.java │ │ │ ├── FtdcOpenOrDestroyType.java │ │ │ ├── FtdcOptionsType.java │ │ │ ├── FtdcOrderPriceType.java │ │ │ ├── FtdcOrderSourceType.java │ │ │ ├── FtdcOrderStatusType.java │ │ │ ├── FtdcOrderSubmitStatusType.java │ │ │ ├── FtdcOrderType.java │ │ │ ├── FtdcPosiDirectionType.java │ │ │ ├── FtdcPositionDateType.java │ │ │ ├── FtdcPositionType.java │ │ │ ├── FtdcPriceSourceType.java │ │ │ ├── FtdcProductClassType.java │ │ │ ├── FtdcPwdFlag.java │ │ │ ├── FtdcTimeCondition.java │ │ │ ├── FtdcTradeCode.java │ │ │ ├── FtdcTradeSourceType.java │ │ │ ├── FtdcTradeType.java │ │ │ ├── FtdcTradingRoleType.java │ │ │ ├── FtdcTransferStatusType.java │ │ │ ├── FtdcVolumeCondition.java │ │ │ └── FtdcYesNoIndicator.java │ │ ├── ftdc │ │ ├── FtdHeartbeatHandler.java │ │ ├── FtdcDecoder.java │ │ ├── FtdcEncoder.java │ │ ├── FtdcHandler.java │ │ ├── FtdcInitializer.java │ │ ├── FtdcProtocol.java │ │ └── processor │ │ │ ├── AccountRegisterTidProcessor.java │ │ │ ├── AuthTidProcessor.java │ │ │ ├── BankOrFurureProcessor.java │ │ │ ├── ContractbankTidProcessor.java │ │ │ ├── ErrRtnOrderActionTidProcessor.java │ │ │ ├── FtdcTidProcessor.java │ │ │ ├── FundPasswordUpdateTidProcessor.java │ │ │ ├── IgnoreTidProcessor.java │ │ │ ├── InvestorPoisitionTidProcessor.java │ │ │ ├── OrderActionTidProcessor.java │ │ │ ├── OrderInsertTidProcessor.java │ │ │ ├── QryCommissionRateTidProcessor.java │ │ │ ├── QryInstrumentTidProcessor.java │ │ │ ├── QryMarginRateTidProcessor.java │ │ │ ├── QryTransferSerialTidProcessor.java │ │ │ ├── RtnBankOrFutureTidProcessor.java │ │ │ ├── RtnOrderTidProcessor.java │ │ │ ├── RtnTradeTidProcessor.java │ │ │ ├── SettlementInfoConfirmTidProcessor.java │ │ │ ├── SettlementInfoTidProcessor.java │ │ │ ├── TidProcessorException.java │ │ │ ├── TidProcessorFactory.java │ │ │ ├── TradingAccountTidProcessor.java │ │ │ ├── UnuseTidProcessor.java │ │ │ ├── UserLoginTidProcessor.java │ │ │ ├── UserLogoutTidProcessor.java │ │ │ └── UserPasswordUpdateTidProcessor.java │ │ ├── handler │ │ ├── BaseFtdcTraderSpiAdapter.java │ │ ├── FtdcTraderApi.java │ │ ├── FtdcTraderApiAdapter.java │ │ ├── FtdcTraderSpi.java │ │ ├── PrintResultHandler.java │ │ └── task │ │ │ └── RecieveMessageTimerTask.java │ │ ├── pool │ │ ├── DefaultSocketAddressChooserFactory.java │ │ ├── FtdClientPool.java │ │ └── SocketAddressChooserFactory.java │ │ └── security │ │ ├── KAES.java │ │ └── KAESException.java └── resources │ ├── ThostFtdcUserApiDataType.h │ ├── dto.req │ └── dto.rsp └── test └── java └── com └── ee └── ctp ├── ApiTest.java ├── CodeTest.java ├── DtoMakeTest.java ├── PoolTradeTest.java ├── TradeOrderActionTest.java ├── TradeTest.java ├── TradeUserPasswordUpdateTest.java ├── enums ├── CTPErrorCodeTest.java ├── FtdTagTypeTest.java ├── FtdTypeTest.java ├── SequenceTest.java ├── TIDTest.java └── business │ ├── FtdcActionFlagTypeTest.java │ ├── FtdcAvailabilityFlagTypeTest.java │ └── FtdcBankAccTypeTest.java ├── ftdc ├── FtdcDecoderTest.java ├── FtdcEncoderTest.java ├── FtdcHandlerTest.java └── FtdcProtocolTest.java └── security └── KAESTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.project 2 | .settings 3 | target 4 | log 5 | .classpath 6 | .checkstyle 7 | .eclipse-pmd 8 | lib 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### 项目背景 2 | 1.CTP默认客户端适用于单一用户,多个用户同时使用一个则性能耗费增加 3 | 4 | ### 项目介绍 5 | 1.使用java实现ftdc协议,为代理服务性能提升提供保证 6 | 7 | ### 进度 8 | 1. 完成登录接口 9 | 2. 完成心跳 10 | 3. 签约银行查询 11 | 4. 完成登出接口 12 | 5. 完成结算单信息查询 13 | 6. 完成结算单确认 14 | 7. 完成结算单确认查询 15 | 8. 完成资金账户查询 16 | 9. 完成报单功能 17 | 10. 完成持仓查询功能 18 | 11. 完成报单查询功能 19 | 12. 完成成交查询功能 20 | 13. 完成合约手续费率查询功能 21 | 14. 完成合约保证金比例查询功能 22 | 15. 完成报单修改功能 23 | 16. 完成交易密码修改功能 24 | 17. 完成银期转账功能 25 | 18. 完成期银转账功能 26 | 27 | ### Features 28 | 1. 连接池改造完毕 29 | 2. 支持一个服务接入多家期货公司 30 | 31 | ### 使用方式 32 | mvn package 33 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.ee 6 | ctp 7 | 1.0 8 | jar 9 | 10 | ctp 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.7 16 | 1.7 17 | 18 | 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.1.7.Final 25 | 26 | 27 | 28 | org.apache.commons 29 | commons-lang3 30 | 3.4 31 | 32 | 33 | 34 | commons-io 35 | commons-io 36 | 2.4 37 | 38 | 39 | junit 40 | junit 41 | 4.11 42 | compile 43 | 44 | 45 | 46 | com.google.guava 47 | guava 48 | 18.0 49 | 50 | 51 | commons-codec 52 | commons-codec 53 | 1.4 54 | 55 | 56 | 57 | 58 | org.slf4j 59 | slf4j-api 60 | 1.7.12 61 | 62 | 63 | ch.qos.logback 64 | logback-core 65 | 1.1.7 66 | 67 | 68 | ch.qos.logback 69 | logback-classic 70 | 1.1.7 71 | 72 | 73 | 74 | 75 | 76 | mymirror1 77 | Human Readable Name for this Mirror.s 78 | http://192.168.59.98:8081/nexus/content/repositories/releases/ 79 | 80 | 81 | 82 | 83 | 84 | 85 | org.apache.maven.plugins 86 | maven-compiler-plugin 87 | 88 | ${maven.compiler.source} 89 | ${maven.compiler.source} 90 | 91 | 92 | 93 | org.apache.maven.plugins 94 | maven-jar-plugin 95 | 96 | 97 | 98 | true 99 | 100 | 101 | 102 | 103 | 104 | maven-dependency-plugin 105 | 2.1 106 | 107 | 108 | copy-dependencies 109 | prepare-package 110 | 111 | copy-dependencies 112 | 113 | 114 | 115 | 116 | jar 117 | junit*.jar 118 | true 119 | jar 120 | lib/ 121 | 122 | 123 | 124 | org.apache.maven.plugins 125 | maven-checkstyle-plugin 126 | 2.17 127 | 128 | 129 | com.jince 130 | build-tools 131 | 0.0.1 132 | 133 | 134 | 135 | 136 | maven-surefire-plugin 137 | 138 | true 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/CtpClient.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp; 2 | 3 | import com.ee.ctp.ftdc.FtdcInitializer; 4 | 5 | import io.netty.bootstrap.Bootstrap; 6 | import io.netty.channel.ChannelFuture; 7 | import io.netty.channel.ChannelFutureListener; 8 | import io.netty.channel.nio.NioEventLoopGroup; 9 | import io.netty.channel.socket.nio.NioSocketChannel; 10 | /** 11 | * 单次连接端,仅仅用作测试 12 | * @author ee 13 | * 2017年10月17日 下午8:11:43 14 | * 15 | */ 16 | public class CtpClient { 17 | private CtpClient() {} 18 | 19 | /** 20 | * 21 | * @param host 180.168.146.187 22 | * @param port 10030|10000 23 | * @throws Exception 24 | */ 25 | public static void ctp(String host, int port, ChannelFutureListener listener) throws Exception { 26 | NioEventLoopGroup group = new NioEventLoopGroup(); 27 | Bootstrap bs = new Bootstrap(); 28 | bs.group(group); 29 | bs.channel(NioSocketChannel.class); 30 | bs.handler(new FtdcInitializer()); 31 | 32 | ChannelFuture channelFuture = bs.connect(host, port); 33 | channelFuture.addListener(listener); 34 | channelFuture.sync(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/RequestIdentity.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp; 2 | 3 | import io.netty.channel.Channel; 4 | /** 5 | * 6 | * @author ee 7 | * 2017年10月17日 下午8:12:42 8 | * 9 | */ 10 | public class RequestIdentity { 11 | private int reqId; 12 | private String userId; 13 | private String brokerId; 14 | private Channel clientChannel; 15 | private String authCode; 16 | /** 17 | * 请求消息 18 | */ 19 | private Object reqMsg; 20 | 21 | public int getReqId() { 22 | return reqId; 23 | } 24 | 25 | public void setReqId(int reqId) { 26 | this.reqId = reqId; 27 | } 28 | 29 | public String getUserId() { 30 | return userId; 31 | } 32 | 33 | public void setUserId(String userId) { 34 | this.userId = userId; 35 | } 36 | 37 | public String getBrokerId() { 38 | return brokerId; 39 | } 40 | 41 | public void setBrokerId(String brokerId) { 42 | this.brokerId = brokerId; 43 | } 44 | 45 | public Channel getClientChannel() { 46 | return clientChannel; 47 | } 48 | 49 | public void setClientChannel(Channel clientChannel) { 50 | this.clientChannel = clientChannel; 51 | } 52 | 53 | public Object getReqMsg() { 54 | return reqMsg; 55 | } 56 | 57 | public void setReqMsg(Object reqMsg) { 58 | this.reqMsg = reqMsg; 59 | } 60 | 61 | public String getAuthCode() { 62 | return authCode; 63 | } 64 | 65 | public void setAuthCode(String authCode) { 66 | this.authCode = authCode; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "RequestIdentity [reqId=" + reqId + ", userId=" + userId + ", brokerId=" + brokerId + ", clientChannel=" 72 | + clientChannel + ", authCode=" + authCode 73 | + "]"; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/FtdcReq.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | /** 5 | * ftdc req 6 | * @author ee 7 | * 2017年11月9日 下午5:11:50 8 | * 9 | */ 10 | public interface FtdcReq { 11 | /** 12 | * 序列化 13 | * @param buffer 14 | * @return 15 | */ 16 | ByteBuf write(ByteBuf buffer); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/FtdcRsp.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | /** 5 | * ftdc rsp 6 | * @author ee 7 | * 2017年11月9日 下午5:12:16 8 | * 9 | */ 10 | public interface FtdcRsp { 11 | /** 12 | * 反序列化 13 | * @param body 14 | * @param error 15 | * @return 16 | */ 17 | FtdcRsp parseFrom(ByteBuf body, RspError error); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/HeartBeat.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import com.ee.ctp.enums.FtdTagType; 4 | import com.ee.ctp.enums.FtdType; 5 | import com.ee.ctp.ftdc.FtdcProtocol; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:15:02 10 | * 11 | */ 12 | public class HeartBeat { 13 | 14 | public static FtdcProtocol getHeartBeat() { 15 | FtdcProtocol fp = new FtdcProtocol(FtdType.FTDTypeNone); 16 | FtdTagType tagType = FtdTagType.FTDTagKeepAlive; 17 | fp.addExt(tagType.type(), tagType.length(), 0); 18 | return fp; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqAccountRegister.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcCurrencyID; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author wyz 11 | * 2017年10月17日 下午8:15:29 12 | * 13 | */ 14 | public class ReqAccountRegister implements FtdcReq{ 15 | private byte[] brokerID = new byte[11]; 16 | private byte[] accountID = new byte[13]; 17 | private byte[] bankID = new byte[4]; 18 | private byte[] bankBranchID = new byte[5]; 19 | private byte[] currencyID = new byte[4]; 20 | 21 | public void setBrokerID(String brokerID) { 22 | if (StringUtils.isNotEmpty(brokerID)) { 23 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 24 | } 25 | } 26 | 27 | public void setAccountID(String accountID) { 28 | if (StringUtils.isNotEmpty(accountID)) { 29 | System.arraycopy(accountID.getBytes(), 0, this.accountID, 0, accountID.getBytes().length); 30 | } 31 | } 32 | 33 | public void setBankID(String bankID) { 34 | if (StringUtils.isNotEmpty(bankID)) { 35 | System.arraycopy(bankID.getBytes(), 0, this.bankID, 0, bankID.getBytes().length); 36 | } 37 | } 38 | 39 | public void setBankBranchID(String bankBranchID) { 40 | if (StringUtils.isNotEmpty(bankBranchID)) { 41 | System.arraycopy(bankBranchID.getBytes(), 0, this.bankBranchID, 0, bankBranchID.getBytes().length); 42 | } 43 | } 44 | 45 | public void setCurrencyID(FtdcCurrencyID currencyID) { 46 | if (currencyID != null) { 47 | System.arraycopy(currencyID.id().getBytes(), 0, this.currencyID, 0, currencyID.id().getBytes().length); 48 | } 49 | } 50 | 51 | @Override 52 | public ByteBuf write(ByteBuf buffer) { 53 | buffer.writeBytes(brokerID); 54 | buffer.writeBytes(accountID); 55 | buffer.writeBytes(bankID); 56 | buffer.writeBytes(bankBranchID); 57 | buffer.writeBytes(currencyID); 58 | 59 | return buffer; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqAuth.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.security.KAES; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | 9 | /** 10 | * 11 | * @author lyb 12 | * 13 | */ 14 | public class ReqAuth implements FtdcReq{ 15 | 16 | private byte[] brokerID = new byte[11]; 17 | private byte[] investorID = new byte[16]; 18 | private byte[] productInfo = new byte[11]; 19 | private byte[] authCode = new byte[17]; 20 | private byte[] authInfo = new byte[133]; 21 | 22 | public void setBrokerID(String brokerID) { 23 | if (StringUtils.isNotEmpty(brokerID)) { 24 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 25 | } 26 | } 27 | public void setInvestorID(String investorID) { 28 | if (StringUtils.isNotEmpty(investorID)) { 29 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 30 | } 31 | } 32 | public void setProductInfo(String productInfo) { 33 | if (StringUtils.isNotEmpty(productInfo)) { 34 | System.arraycopy(productInfo.getBytes(), 0, this.productInfo, 0, productInfo.getBytes().length); 35 | } 36 | } 37 | public void setAuthCode(String authCode) { 38 | if (StringUtils.isNotEmpty(authCode)) { 39 | System.arraycopy(authCode.getBytes(), 0, this.authCode, 0, authCode.getBytes().length); 40 | } 41 | } 42 | 43 | public void setAuthInfo(byte[] authInfo) { 44 | System.arraycopy(authInfo, 0, this.authInfo, 0, authInfo.length); 45 | } 46 | 47 | 48 | public ByteBuf writeFirst(ByteBuf buffer) { 49 | buffer.writeBytes(brokerID); 50 | buffer.writeBytes(investorID); 51 | buffer.writeBytes(productInfo); 52 | buffer.writeBytes(authInfo); 53 | 54 | return buffer; 55 | } 56 | 57 | public ByteBuf writeSecond(ByteBuf buffer) { 58 | buffer.writeBytes(brokerID); 59 | buffer.writeBytes(investorID); 60 | buffer.writeBytes(productInfo); 61 | buffer.writeBytes(authInfo); 62 | 63 | return buffer; 64 | } 65 | 66 | public static ReqAuth buildSecondFrom(RspAuth auth, String authCode) { 67 | ReqAuth reqAuth = new ReqAuth(); 68 | byte[] authInfo = KAES.DEFAULT_INSTANCE.encrypt(auth.getAuthInfo(), authCode.getBytes()); 69 | reqAuth.setBrokerID(auth.getBrokerID()); 70 | reqAuth.setInvestorID(auth.getUserID()); 71 | reqAuth.setProductInfo(auth.getUserProductInfo()); 72 | reqAuth.setAuthInfo(authInfo); 73 | return reqAuth; 74 | } 75 | 76 | @Override 77 | public ByteBuf write(ByteBuf buffer) { 78 | return null; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqContractBank.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:15:47 10 | * 11 | */ 12 | public class ReqContractBank implements FtdcReq{ 13 | 14 | private byte[] brokerID = new byte[11]; 15 | private byte[] bankId = new byte[4]; 16 | private byte[] bankBrchId = new byte[5]; 17 | 18 | public void setBrokerID(String brokerID) { 19 | if (StringUtils.isNotEmpty(brokerID)) { 20 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 21 | } 22 | } 23 | 24 | public void setBankId(String bankId) { 25 | if (StringUtils.isNotEmpty(bankId)) { 26 | System.arraycopy(bankId.getBytes(), 0, this.bankId, 0, bankId.getBytes().length); 27 | } 28 | } 29 | 30 | public void setBankBrchId(String bankBrchId) { 31 | if (StringUtils.isNotEmpty(bankBrchId)) { 32 | System.arraycopy(bankBrchId.getBytes(), 0, this.bankBrchId, 0, bankBrchId.getBytes().length); 33 | } 34 | } 35 | 36 | @Override 37 | public ByteBuf write(ByteBuf buffer) { 38 | buffer.writeBytes(brokerID); 39 | buffer.writeBytes(bankId); 40 | buffer.writeBytes(bankBrchId); 41 | return buffer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqFundPasswordUpdate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import com.ee.ctp.enums.business.FtdcCurrencyID; 8 | /** 9 | * 10 | * @author lyb 11 | * 12 | */ 13 | public class ReqFundPasswordUpdate implements FtdcReq{ 14 | private byte[] brokerID = new byte[11]; 15 | private byte[] userID = new byte[13]; 16 | private byte[] oldPassword = new byte[41]; 17 | private byte[] newPassword = new byte[41]; 18 | private int currencyID; 19 | 20 | public void setBrokerID(String brokerID) { 21 | if (StringUtils.isNotEmpty(brokerID)) { 22 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 23 | } 24 | } 25 | 26 | public void setUserID(String userID) { 27 | if (StringUtils.isNotEmpty(userID)) { 28 | System.arraycopy(userID.getBytes(), 0, this.userID, 0, userID.getBytes().length); 29 | } 30 | } 31 | 32 | public void setOldPassword(String oldPassword) { 33 | if (StringUtils.isNotEmpty(oldPassword)) { 34 | int min = Math.min(oldPassword.getBytes().length, this.oldPassword.length); 35 | System.arraycopy(oldPassword.getBytes(), 0, this.oldPassword, 0, min); 36 | } 37 | } 38 | 39 | public void setNewPassword(String newPassword) { 40 | if (StringUtils.isNotEmpty(newPassword)) { 41 | int min = Math.min(newPassword.getBytes().length, this.newPassword.length); 42 | System.arraycopy(newPassword.getBytes(), 0, this.newPassword, 0, min); 43 | } 44 | } 45 | 46 | public void setCurrencyID(FtdcCurrencyID currencyID) { 47 | this.currencyID = currencyID.getId(); 48 | } 49 | 50 | @Override 51 | public ByteBuf write(ByteBuf buffer) { 52 | buffer.writeBytes(brokerID); 53 | buffer.writeBytes(userID); 54 | buffer.writeBytes(oldPassword); 55 | buffer.writeBytes(newPassword); 56 | buffer.writeInt(currencyID); 57 | return buffer; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqInvestorPosition.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:15:58 10 | * 11 | */ 12 | public class ReqInvestorPosition implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] instrumentID = new byte[31]; 16 | 17 | public void setBrokerID(String brokerID) { 18 | if (StringUtils.isNotEmpty(brokerID)) { 19 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 20 | } 21 | } 22 | 23 | public void setInvestorID(String investorID) { 24 | if (StringUtils.isNotEmpty(investorID)) { 25 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 26 | } 27 | } 28 | 29 | public void setInstrumentID(String instrumentID) { 30 | if (StringUtils.isNotEmpty(instrumentID)) { 31 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 32 | } 33 | } 34 | 35 | @Override 36 | public ByteBuf write(ByteBuf buffer) { 37 | buffer.writeBytes(brokerID); 38 | buffer.writeBytes(investorID); 39 | buffer.writeBytes(instrumentID); 40 | 41 | return buffer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqOrderAction.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import com.ee.ctp.enums.business.FtdcActionFlagType; 8 | import com.ee.ctp.enums.business.FtdcExchange; 9 | /** 10 | * 11 | * @author ee 12 | * 2017年10月17日 下午8:15:58 13 | * 14 | */ 15 | public class ReqOrderAction implements FtdcReq{ 16 | private byte[] brokerID = new byte[11]; 17 | private byte[] investorID = new byte[13]; 18 | private int orderActionRef; 19 | private byte[] orderRef = new byte[13]; 20 | private int requestID; 21 | private int frontID; 22 | private int sessionID; 23 | private byte[] exchangeID = new byte[9]; 24 | private byte[] orderSysID = new byte[21]; 25 | private byte[] actionFlag = new byte[1]; 26 | private double limitPrice; 27 | private int volumeChange; 28 | private byte[] userID = new byte[16]; 29 | private byte[] instrumentID = new byte[31]; 30 | private byte[] investUnitID = new byte[17]; 31 | private byte[] iPAddress = new byte[16]; 32 | private byte[] macAddress = new byte[21]; 33 | 34 | public void setBrokerID(String brokerID) { 35 | if (StringUtils.isNotEmpty(brokerID)) { 36 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 37 | } 38 | } 39 | 40 | public void setInvestorID(String investorID) { 41 | if (StringUtils.isNotEmpty(investorID)) { 42 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 43 | } 44 | } 45 | 46 | public void setOrderActionRef(int orderActionRef) { 47 | this.orderActionRef = orderActionRef; 48 | } 49 | 50 | public void setOrderRef(String orderRef) { 51 | if (StringUtils.isNotEmpty(orderRef)) { 52 | System.arraycopy(orderRef.getBytes(), 0, this.orderRef, 0, orderRef.getBytes().length); 53 | } 54 | } 55 | 56 | public void setRequestID(int requestID) { 57 | this.requestID = requestID; 58 | } 59 | 60 | public void setFrontID(int frontID) { 61 | this.frontID = frontID; 62 | } 63 | 64 | public void setSessionID(int sessionID) { 65 | this.sessionID = sessionID; 66 | } 67 | 68 | public void setExchangeID(FtdcExchange exchangeID) { 69 | if (exchangeID != null) { 70 | System.arraycopy(exchangeID.getExchange().getBytes(), 0, this.exchangeID, 0, 71 | exchangeID.getExchange().getBytes().length); 72 | } 73 | } 74 | 75 | public void setOrderSysID(String orderSysID) { 76 | if (StringUtils.isNotEmpty(orderSysID)) { 77 | System.arraycopy(orderSysID.getBytes(), 0, this.orderSysID, 0, orderSysID.getBytes().length); 78 | } 79 | } 80 | 81 | public void setActionFlag(FtdcActionFlagType actionFlag) { 82 | if (actionFlag != null) { 83 | System.arraycopy(actionFlag.type().getBytes(), 0, this.actionFlag, 0, actionFlag.type().getBytes().length); 84 | } 85 | } 86 | 87 | public void setLimitPrice(double limitPrice) { 88 | this.limitPrice = limitPrice; 89 | } 90 | 91 | public void setVolumeChange(int volumeChange) { 92 | this.volumeChange = volumeChange; 93 | } 94 | 95 | public void setUserID(String userID) { 96 | if (StringUtils.isNotEmpty(userID)) { 97 | System.arraycopy(userID.getBytes(), 0, this.userID, 0, userID.getBytes().length); 98 | } 99 | } 100 | 101 | public void setInstrumentID(String instrumentID) { 102 | if (StringUtils.isNotEmpty(instrumentID)) { 103 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 104 | } 105 | } 106 | 107 | public void setInvestUnitID(String investUnitID) { 108 | if (StringUtils.isNotEmpty(investUnitID)) { 109 | System.arraycopy(investUnitID.getBytes(), 0, this.investUnitID, 0, investUnitID.getBytes().length); 110 | } 111 | } 112 | 113 | public void setIPAddress(String iPAddress) { 114 | if (StringUtils.isNotEmpty(iPAddress)) { 115 | System.arraycopy(iPAddress.getBytes(), 0, this.iPAddress, 0, iPAddress.getBytes().length); 116 | } 117 | } 118 | 119 | public void setMacAddress(String macAddress) { 120 | if (StringUtils.isNotEmpty(macAddress)) { 121 | System.arraycopy(macAddress.getBytes(), 0, this.macAddress, 0, macAddress.getBytes().length); 122 | } 123 | } 124 | 125 | @Override 126 | public ByteBuf write(ByteBuf buffer) { 127 | buffer.writeBytes(brokerID); 128 | buffer.writeBytes(investorID); 129 | buffer.writeInt(orderActionRef); 130 | buffer.writeBytes(orderRef); 131 | buffer.writeInt(requestID); 132 | buffer.writeInt(frontID); 133 | buffer.writeInt(sessionID); 134 | buffer.writeBytes(exchangeID); 135 | buffer.writeBytes(orderSysID); 136 | buffer.writeBytes(actionFlag); 137 | buffer.writeDouble(limitPrice); 138 | buffer.writeInt(volumeChange); 139 | buffer.writeBytes(userID); 140 | buffer.writeBytes(instrumentID); 141 | buffer.writeBytes(investUnitID); 142 | buffer.writeBytes(iPAddress); 143 | buffer.writeBytes(macAddress); 144 | 145 | return buffer; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryCommissionRate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:15:58 10 | * 11 | */ 12 | public class ReqQryCommissionRate implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] instrumentID = new byte[31]; 16 | 17 | public void setBrokerID(String brokerID) { 18 | if (StringUtils.isNotEmpty(brokerID)) { 19 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 20 | } 21 | } 22 | 23 | public void setInvestorID(String investorID) { 24 | if (StringUtils.isNotEmpty(investorID)) { 25 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 26 | } 27 | } 28 | 29 | public void setInstrumentID(String instrumentID) { 30 | if (StringUtils.isNotEmpty(instrumentID)) { 31 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 32 | } 33 | } 34 | 35 | @Override 36 | public ByteBuf write(ByteBuf buffer) { 37 | buffer.writeBytes(brokerID); 38 | buffer.writeBytes(investorID); 39 | buffer.writeBytes(instrumentID); 40 | 41 | return buffer; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryInstrument.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcExchange; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:15:58 12 | * 13 | */ 14 | public class ReqQryInstrument implements FtdcReq{ 15 | private byte[] instrumentID = new byte[31]; 16 | private byte[] exchangeID = new byte[9]; 17 | private byte[] exchangeInstID = new byte[31]; 18 | private byte[] productID = new byte[31]; 19 | 20 | public void setInstrumentID(String instrumentID) { 21 | if (StringUtils.isNotEmpty(instrumentID)) { 22 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 23 | } 24 | } 25 | 26 | public void setExchangeID(FtdcExchange exchangeID) { 27 | if (exchangeID != null) { 28 | System.arraycopy(exchangeID.getExchange().getBytes(), 0, this.exchangeID, 0, 29 | exchangeID.getExchange().getBytes().length); 30 | } 31 | } 32 | 33 | public void setExchangeInstID(String exchangeInstID) { 34 | if (StringUtils.isNotEmpty(exchangeInstID)) { 35 | System.arraycopy(exchangeInstID.getBytes(), 0, this.exchangeInstID, 0, exchangeInstID.getBytes().length); 36 | } 37 | } 38 | 39 | public void setProductID(String productID) { 40 | if (StringUtils.isNotEmpty(productID)) { 41 | System.arraycopy(productID.getBytes(), 0, this.productID, 0, productID.getBytes().length); 42 | } 43 | } 44 | 45 | @Override 46 | public ByteBuf write(ByteBuf buffer) { 47 | buffer.writeBytes(instrumentID); 48 | buffer.writeBytes(exchangeID); 49 | buffer.writeBytes(exchangeInstID); 50 | buffer.writeBytes(productID); 51 | 52 | return buffer; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryMarginRate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcBillHedgeFlag; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:15:58 12 | * 13 | */ 14 | public class ReqQryMarginRate implements FtdcReq{ 15 | private byte[] brokerID = new byte[11]; 16 | private byte[] investorID = new byte[13]; 17 | private byte[] instrumentID = new byte[31]; 18 | private byte[] hedgeFlag = new byte[1]; 19 | 20 | public void setBrokerID(String brokerID) { 21 | if (StringUtils.isNotEmpty(brokerID)) { 22 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 23 | } 24 | } 25 | 26 | public void setInvestorID(String investorID) { 27 | if (StringUtils.isNotEmpty(investorID)) { 28 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 29 | } 30 | } 31 | 32 | public void setInstrumentID(String instrumentID) { 33 | if (StringUtils.isNotEmpty(instrumentID)) { 34 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 35 | } 36 | } 37 | 38 | public void setHedgeFlag(FtdcBillHedgeFlag hedgeFlag) { 39 | if (hedgeFlag != null) { 40 | System.arraycopy(hedgeFlag.getFlag().getBytes(), 0, this.hedgeFlag, 0, hedgeFlag.getFlag().getBytes().length); 41 | } 42 | } 43 | 44 | @Override 45 | public ByteBuf write(ByteBuf buffer) { 46 | buffer.writeBytes(brokerID); 47 | buffer.writeBytes(investorID); 48 | buffer.writeBytes(instrumentID); 49 | buffer.writeBytes(hedgeFlag); 50 | 51 | return buffer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryOrder.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcExchange; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:16:57 12 | * 13 | */ 14 | public class ReqQryOrder implements FtdcReq{ 15 | private byte[] brokerID = new byte[11]; 16 | private byte[] investorID = new byte[13]; 17 | private byte[] instrumentID = new byte[31]; 18 | private byte[] exchangeID = new byte[9]; 19 | private byte[] orderSysID = new byte[21]; 20 | private byte[] insertTimeStart = new byte[9]; 21 | private byte[] insertTimeEnd = new byte[9]; 22 | 23 | public void setBrokerID(String brokerID) { 24 | if (StringUtils.isNotEmpty(brokerID)) { 25 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 26 | } 27 | } 28 | 29 | public void setInvestorID(String investorID) { 30 | if (StringUtils.isNotEmpty(investorID)) { 31 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 32 | } 33 | } 34 | 35 | public void setInstrumentID(String instrumentID) { 36 | if (StringUtils.isNotEmpty(instrumentID)) { 37 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 38 | } 39 | } 40 | 41 | public void setExchangeID(FtdcExchange exchangeID) { 42 | if (exchangeID != null) { 43 | System.arraycopy(exchangeID.getExchange().getBytes(), 0, this.exchangeID, 0, exchangeID.getExchange().getBytes().length); 44 | } 45 | } 46 | 47 | public void setOrderSysID(String orderSysID) { 48 | if (StringUtils.isNotEmpty(orderSysID)) { 49 | System.arraycopy(orderSysID.getBytes(), 0, this.orderSysID, 0, orderSysID.getBytes().length); 50 | } 51 | } 52 | 53 | public void setInsertTimeStart(String insertTimeStart) { 54 | if (StringUtils.isNotEmpty(insertTimeStart)) { 55 | System.arraycopy(insertTimeStart.getBytes(), 0, this.insertTimeStart, 0, insertTimeStart.getBytes().length); 56 | } 57 | } 58 | 59 | public void setInsertTimeEnd(String insertTimeEnd) { 60 | if (StringUtils.isNotEmpty(insertTimeEnd)) { 61 | System.arraycopy(insertTimeEnd.getBytes(), 0, this.insertTimeEnd, 0, insertTimeEnd.getBytes().length); 62 | } 63 | } 64 | 65 | @Override 66 | public ByteBuf write(ByteBuf buffer) { 67 | buffer.writeBytes(brokerID); 68 | buffer.writeBytes(investorID); 69 | buffer.writeBytes(instrumentID); 70 | buffer.writeBytes(exchangeID); 71 | buffer.writeBytes(orderSysID); 72 | buffer.writeBytes(insertTimeStart); 73 | buffer.writeBytes(insertTimeEnd); 74 | 75 | return buffer; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQrySettlementInfoConfirm.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:17:04 10 | * 11 | */ 12 | public class ReqQrySettlementInfoConfirm implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | 16 | public void setBrokerID(String brokerID) { 17 | if(StringUtils.isNotEmpty(brokerID)) { 18 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 19 | } 20 | } 21 | 22 | public void setInvestorID(String investorID) { 23 | if(StringUtils.isNotEmpty(investorID)) { 24 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 25 | } 26 | } 27 | 28 | @Override 29 | public ByteBuf write(ByteBuf buffer) { 30 | buffer.writeBytes(brokerID); 31 | buffer.writeBytes(investorID); 32 | return buffer; 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryTrade.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:17:20 10 | * 11 | */ 12 | public class ReqQryTrade implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] instrumentID = new byte[31]; 16 | private byte[] exchangeID = new byte[9]; 17 | private byte[] tradeID = new byte[21]; 18 | private byte[] tradeTimeStart = new byte[9]; 19 | private byte[] tradeTimeEnd = new byte[9]; 20 | 21 | public void setBrokerID(String brokerID) { 22 | if (StringUtils.isNotEmpty(brokerID)) { 23 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 24 | } 25 | } 26 | 27 | public void setInvestorID(String investorID) { 28 | if (StringUtils.isNotEmpty(investorID)) { 29 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 30 | } 31 | } 32 | 33 | public void setInstrumentID(String instrumentID) { 34 | if (StringUtils.isNotEmpty(instrumentID)) { 35 | System.arraycopy(instrumentID.getBytes(), 0, this.instrumentID, 0, instrumentID.getBytes().length); 36 | } 37 | } 38 | 39 | public void setExchangeID(String exchangeID) { 40 | if (StringUtils.isNotEmpty(exchangeID)) { 41 | System.arraycopy(exchangeID.getBytes(), 0, this.exchangeID, 0, exchangeID.getBytes().length); 42 | } 43 | } 44 | 45 | public void setTradeID(String tradeID) { 46 | if (StringUtils.isNotEmpty(tradeID)) { 47 | System.arraycopy(tradeID.getBytes(), 0, this.tradeID, 0, tradeID.getBytes().length); 48 | } 49 | } 50 | 51 | public void setTradeTimeStart(String tradeTimeStart) { 52 | if (StringUtils.isNotEmpty(tradeTimeStart)) { 53 | System.arraycopy(tradeTimeStart.getBytes(), 0, this.tradeTimeStart, 0, tradeTimeStart.getBytes().length); 54 | } 55 | } 56 | 57 | public void setTradeTimeEnd(String tradeTimeEnd) { 58 | if (StringUtils.isNotEmpty(tradeTimeEnd)) { 59 | System.arraycopy(tradeTimeEnd.getBytes(), 0, this.tradeTimeEnd, 0, tradeTimeEnd.getBytes().length); 60 | } 61 | } 62 | 63 | @Override 64 | public ByteBuf write(ByteBuf buffer) { 65 | buffer.writeBytes(brokerID); 66 | buffer.writeBytes(investorID); 67 | buffer.writeBytes(instrumentID); 68 | buffer.writeBytes(exchangeID); 69 | buffer.writeBytes(tradeID); 70 | buffer.writeBytes(tradeTimeStart); 71 | buffer.writeBytes(tradeTimeEnd); 72 | 73 | return buffer; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqQryTransferSerial.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcCurrencyID; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:17:28 12 | * 13 | */ 14 | public class ReqQryTransferSerial implements FtdcReq{ 15 | private byte[] brokerID = new byte[11]; 16 | private byte[] accountID = new byte[13]; 17 | private byte[] bankID = new byte[4]; 18 | private int currencyID; 19 | 20 | public void setBrokerID(String brokerID) { 21 | if (StringUtils.isNotEmpty(brokerID)) { 22 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 23 | } 24 | } 25 | 26 | public void setAccountID(String accountID) { 27 | if (StringUtils.isNotEmpty(accountID)) { 28 | System.arraycopy(accountID.getBytes(), 0, this.accountID, 0, accountID.getBytes().length); 29 | } 30 | } 31 | 32 | public void setBankID(String bankID) { 33 | if (StringUtils.isNotEmpty(bankID)) { 34 | System.arraycopy(bankID.getBytes(), 0, this.bankID, 0, bankID.getBytes().length); 35 | } 36 | } 37 | 38 | public void setCurrencyID(FtdcCurrencyID currencyID) { 39 | if(currencyID != null) { 40 | this.currencyID = currencyID.getId(); } 41 | } 42 | 43 | @Override 44 | public ByteBuf write(ByteBuf buffer) { 45 | buffer.writeBytes(brokerID); 46 | buffer.writeBytes(accountID); 47 | buffer.writeBytes(bankID); 48 | buffer.writeInt(currencyID); 49 | return buffer; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqSettlementInfo.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:17:39 10 | * 11 | */ 12 | public class ReqSettlementInfo implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] tradingDay = new byte[9]; 16 | 17 | public void setTradingDay(String tradingDay) { 18 | if(StringUtils.isNotEmpty(tradingDay)) { 19 | System.arraycopy(tradingDay.getBytes(), 0, this.tradingDay, 0, tradingDay.getBytes().length); 20 | } 21 | } 22 | 23 | public void setBrokerID(String brokerID) { 24 | if(StringUtils.isNotEmpty(brokerID)) { 25 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 26 | } 27 | } 28 | 29 | public void setInvestorID(String investorID) { 30 | if(StringUtils.isNotEmpty(investorID)) { 31 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 32 | } 33 | } 34 | 35 | @Override 36 | public ByteBuf write(ByteBuf buffer) { 37 | buffer.writeBytes(brokerID); 38 | buffer.writeBytes(investorID); 39 | buffer.writeBytes(tradingDay); 40 | return buffer; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqSettlementInfoConfirm.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:17:51 10 | * 11 | */ 12 | public class ReqSettlementInfoConfirm implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] confirmDate = new byte[9]; 16 | private byte[] confirmTime = new byte[9]; 17 | 18 | public void setBrokerID(String brokerID) { 19 | if(StringUtils.isNotEmpty(brokerID)) { 20 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 21 | } 22 | } 23 | 24 | public void setInvestorID(String investorID) { 25 | if(StringUtils.isNotEmpty(investorID)) { 26 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 27 | } 28 | } 29 | 30 | public void setConfirmDate(String confirmDate) { 31 | if(StringUtils.isNotEmpty(confirmDate)) { 32 | System.arraycopy(confirmDate.getBytes(), 0, this.confirmDate, 0, confirmDate.getBytes().length); 33 | } 34 | } 35 | 36 | public void setConfirmTime(String confirmTime) { 37 | if(StringUtils.isNotEmpty(confirmTime)) { 38 | System.arraycopy(confirmTime.getBytes(), 0, this.confirmTime, 0, confirmTime.getBytes().length); 39 | } 40 | } 41 | 42 | @Override 43 | public ByteBuf write(ByteBuf buffer) { 44 | buffer.writeBytes(brokerID); 45 | buffer.writeBytes(investorID); 46 | buffer.writeBytes(confirmDate); 47 | buffer.writeBytes(confirmTime); 48 | return buffer; 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqTradingAccount.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:18:01 10 | * 11 | */ 12 | public class ReqTradingAccount implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] investorID = new byte[13]; 15 | private byte[] currencyID = new byte[4]; 16 | 17 | public void setCurrencyID(String currencyID) { 18 | if(StringUtils.isNotEmpty(currencyID)) { 19 | System.arraycopy(currencyID.getBytes(), 0, this.currencyID, 0, currencyID.getBytes().length); 20 | } 21 | } 22 | 23 | public void setBrokerID(String brokerID) { 24 | if(StringUtils.isNotEmpty(brokerID)) { 25 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 26 | } 27 | } 28 | 29 | public void setInvestorID(String investorID) { 30 | if(StringUtils.isNotEmpty(investorID)) { 31 | System.arraycopy(investorID.getBytes(), 0, this.investorID, 0, investorID.getBytes().length); 32 | } 33 | } 34 | 35 | @Override 36 | public ByteBuf write(ByteBuf buffer) { 37 | buffer.writeBytes(brokerID); 38 | buffer.writeBytes(investorID); 39 | buffer.writeBytes(currencyID); 40 | return buffer; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqUserLogin.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.RequestIdentity; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:18:23 12 | * 13 | */ 14 | public class ReqUserLogin implements FtdcReq{ 15 | /** 16 | * 猜测是控制订阅私有流、公有流 17 | */ 18 | private static final byte[] PADDING = new byte[]{ 19 | 0x10, 0x01, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 20 | 0x10, 0x01, 0x00, 0x06, 0x00, 0x02, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 21 | 0x10, 0x01, 0x00, 0x06, 0x00, 0x03, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, 22 | 0x10, 0x01, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 23 | }; 24 | private byte[] tradingDay = new byte[9]; 25 | private byte[] brokerID = new byte[11]; 26 | private byte[] userId = new byte[16]; 27 | private byte[] passwd = new byte[41]; 28 | private byte[] userProductInfo = new byte[11]; 29 | private byte[] interfaceProductInfo = new byte[11]; 30 | private byte[] protocolInfo = new byte[11]; 31 | private byte[] macAddress = new byte[21]; 32 | private byte[] oneTimePassword = new byte[41]; 33 | private byte[] clientIPAddress = new byte[16]; 34 | private byte[] loginRemark = new byte[36]; 35 | 36 | public void setTradingDay(String tradingDay) { 37 | if(StringUtils.isNotEmpty(tradingDay)) { 38 | System.arraycopy(tradingDay.getBytes(), 0, this.tradingDay, 0, tradingDay.getBytes().length); 39 | } 40 | } 41 | 42 | public void setBrokerID(String brokerID) { 43 | if(StringUtils.isNotEmpty(brokerID)) { 44 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 45 | } 46 | } 47 | 48 | public void setUserId(String userId) { 49 | if(StringUtils.isNotEmpty(userId)) { 50 | int min = Math.min(userId.getBytes().length, this.userId.length); 51 | System.arraycopy(userId.getBytes(), 0, this.userId, 0, min); 52 | } 53 | } 54 | 55 | public void setPasswd(String passwd) { 56 | if(StringUtils.isNotEmpty(passwd)) { 57 | int min = Math.min(passwd.getBytes().length, this.passwd.length); 58 | System.arraycopy(passwd.getBytes(), 0, this.passwd, 0, min); 59 | } 60 | } 61 | 62 | 63 | public void setUserProductInfo(String userProductInfo) { 64 | if(StringUtils.isNotEmpty(userProductInfo)) { 65 | System.arraycopy(userProductInfo.getBytes(), 0, this.userProductInfo, 0, userProductInfo.getBytes().length); 66 | } 67 | } 68 | 69 | public void setInterfaceProductInfo(String interfaceProductInfo) { 70 | if(StringUtils.isNotEmpty(interfaceProductInfo)) { 71 | System.arraycopy(interfaceProductInfo.getBytes(), 0, this.interfaceProductInfo, 0, interfaceProductInfo.getBytes().length); 72 | } 73 | } 74 | 75 | public void setProtocolInfo(String protocolInfo) { 76 | if(StringUtils.isNotEmpty(protocolInfo)) { 77 | System.arraycopy(protocolInfo.getBytes(), 0, this.protocolInfo, 0, protocolInfo.getBytes().length); 78 | } 79 | } 80 | 81 | public void setMacAddress(String macAddress) { 82 | if(StringUtils.isNotEmpty(macAddress)) { 83 | int min = Math.min(macAddress.getBytes().length, this.macAddress.length); 84 | System.arraycopy(macAddress.getBytes(), 0, this.macAddress, 0, min); 85 | } 86 | } 87 | 88 | public void setOneTimePassword(String oneTimePassword) { 89 | if(StringUtils.isNotEmpty(oneTimePassword)) { 90 | System.arraycopy(oneTimePassword.getBytes(), 0, this.oneTimePassword, 0, oneTimePassword.getBytes().length); 91 | } 92 | } 93 | 94 | public void setClientIPAddress(String clientIPAddress) { 95 | if(StringUtils.isNotEmpty(clientIPAddress)) { 96 | int min = Math.min(clientIPAddress.getBytes().length, this.clientIPAddress.length); 97 | System.arraycopy(clientIPAddress.getBytes(), 0, this.clientIPAddress, 0, min); 98 | } 99 | } 100 | 101 | public void setLoginRemark(String loginRemark) { 102 | if(StringUtils.isNotEmpty(loginRemark)) { 103 | int min = Math.min(loginRemark.getBytes().length, this.loginRemark.length); 104 | System.arraycopy(loginRemark.getBytes(), 0, this.loginRemark, 0, min); 105 | } 106 | } 107 | 108 | @Override 109 | public ByteBuf write(ByteBuf buffer) { 110 | buffer.writeBytes(tradingDay); 111 | buffer.writeBytes(brokerID); 112 | buffer.writeBytes(userId); 113 | buffer.writeBytes(passwd); 114 | buffer.writeBytes(userProductInfo); 115 | buffer.writeBytes(interfaceProductInfo); 116 | buffer.writeBytes(protocolInfo); 117 | buffer.writeBytes(macAddress); 118 | buffer.writeBytes(oneTimePassword); 119 | buffer.writeBytes(clientIPAddress); 120 | buffer.writeBytes(loginRemark); 121 | buffer.writeBytes(PADDING); 122 | return buffer; 123 | } 124 | 125 | public ReqAuth parseReqAuth(RequestIdentity ri) { 126 | ReqAuth reqAuth = new ReqAuth(); 127 | reqAuth.setBrokerID(ri.getBrokerId()); 128 | reqAuth.setInvestorID(ri.getUserId()); 129 | reqAuth.setProductInfo(new String(this.userProductInfo)); 130 | return reqAuth; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqUserLogout.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:18:31 10 | * 11 | */ 12 | public class ReqUserLogout implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] userId = new byte[16]; 15 | 16 | public void setBrokerID(String brokerID) { 17 | if(StringUtils.isNotEmpty(brokerID)) { 18 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 19 | } 20 | } 21 | 22 | public void setUserId(String userId) { 23 | if(StringUtils.isNotEmpty(userId)) { 24 | System.arraycopy(userId.getBytes(), 0, this.userId, 0, userId.getBytes().length); 25 | } 26 | } 27 | 28 | @Override 29 | public ByteBuf write(ByteBuf buffer) { 30 | buffer.writeBytes(brokerID); 31 | buffer.writeBytes(userId); 32 | return buffer; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/ReqUserPasswordUpdate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | /** 7 | * 8 | * @author zlj 9 | * 2017年10月17日 下午8:18:36 10 | * 11 | */ 12 | public class ReqUserPasswordUpdate implements FtdcReq{ 13 | private byte[] brokerID = new byte[11]; 14 | private byte[] userID = new byte[16]; 15 | private byte[] oldPassword = new byte[41]; 16 | private byte[] newPassword = new byte[41]; 17 | 18 | public void setBrokerID(String brokerID) { 19 | if (StringUtils.isNotEmpty(brokerID)) { 20 | System.arraycopy(brokerID.getBytes(), 0, this.brokerID, 0, brokerID.getBytes().length); 21 | } 22 | } 23 | 24 | public void setUserID(String userID) { 25 | if (StringUtils.isNotEmpty(userID)) { 26 | System.arraycopy(userID.getBytes(), 0, this.userID, 0, userID.getBytes().length); 27 | } 28 | } 29 | 30 | public void setOldPassword(String oldPassword) { 31 | if (StringUtils.isNotEmpty(oldPassword)) { 32 | int min = Math.min(oldPassword.getBytes().length, this.oldPassword.length); 33 | System.arraycopy(oldPassword.getBytes(), 0, this.oldPassword, 0, min); 34 | } 35 | } 36 | 37 | public void setNewPassword(String newPassword) { 38 | if (StringUtils.isNotEmpty(newPassword)) { 39 | int min = Math.min(newPassword.getBytes().length, this.newPassword.length); 40 | System.arraycopy(newPassword.getBytes(), 0, this.newPassword, 0, min); 41 | } 42 | } 43 | 44 | @Override 45 | public ByteBuf write(ByteBuf buffer) { 46 | buffer.writeBytes(brokerID); 47 | buffer.writeBytes(userID); 48 | buffer.writeBytes(oldPassword); 49 | buffer.writeBytes(newPassword); 50 | 51 | return buffer; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspAuth.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | 9 | /** 10 | * 11 | * @author lyb 12 | * 13 | */ 14 | public class RspAuth implements FtdcRsp{ 15 | private int errorCode; 16 | //81 17 | private String errorMsg; 18 | 19 | // 11 20 | private String brokerID; 21 | // 16 22 | private String userID; 23 | // 11 24 | private String userProductInfo; 25 | //128 26 | private byte[] authInfo; 27 | 28 | public String getBrokerID() { 29 | return brokerID; 30 | } 31 | public void setBrokerID(String brokerID) { 32 | this.brokerID = brokerID; 33 | } 34 | public String getUserID() { 35 | return userID; 36 | } 37 | public void setUserID(String userID) { 38 | this.userID = userID; 39 | } 40 | public String getUserProductInfo() { 41 | return userProductInfo; 42 | } 43 | public void setUserProductInfo(String userProductInfo) { 44 | this.userProductInfo = userProductInfo; 45 | } 46 | 47 | public byte[] getAuthInfo() { 48 | return authInfo; 49 | } 50 | public void setAuthInfo(byte[] authInfo) { 51 | this.authInfo = authInfo; 52 | } 53 | 54 | public int getErrorCode() { 55 | return errorCode; 56 | } 57 | public void setErrorCode(int errorCode) { 58 | this.errorCode = errorCode; 59 | } 60 | public String getErrorMsg() { 61 | return errorMsg; 62 | } 63 | public void setErrorMsg(String errorMsg) { 64 | this.errorMsg = errorMsg; 65 | } 66 | 67 | public RspAuth parseSecondFrom(ByteBuf body, RspError error) { 68 | RspAuth info = new RspAuth(); 69 | info.setErrorMsg(error.getErrorMsg()); 70 | info.setErrorCode(error.getErrorCode()); 71 | 72 | byte[] brokerID = new byte[11]; 73 | body.readBytes(brokerID); 74 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 75 | 76 | byte[] userID = new byte[16]; 77 | body.readBytes(userID); 78 | info.setUserID(StringUtils.trimToEmpty(new String(userID))); 79 | 80 | byte[] productInfo = new byte[11]; 81 | body.readBytes(productInfo); 82 | info.setUserProductInfo(StringUtils.trimToEmpty(new String(productInfo))); 83 | return info; 84 | } 85 | 86 | public RspAuth parseFirstFrom(ByteBuf body) { 87 | RspAuth info = new RspAuth(); 88 | 89 | byte[] brokerID = new byte[11]; 90 | body.readBytes(brokerID); 91 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 92 | 93 | byte[] userID = new byte[16]; 94 | body.readBytes(userID); 95 | info.setUserID(StringUtils.trimToEmpty(new String(userID))); 96 | 97 | byte[] productInfo = new byte[11]; 98 | body.readBytes(productInfo); 99 | info.setUserProductInfo(StringUtils.trimToEmpty(new String(productInfo))); 100 | 101 | byte[] authInfo = new byte[128]; 102 | body.readBytes(authInfo); 103 | info.setAuthInfo(authInfo); 104 | return info; 105 | } 106 | 107 | 108 | @Override 109 | public FtdcRsp parseFrom(ByteBuf body, RspError error) { 110 | return null; 111 | } 112 | 113 | @Override 114 | public String toString() { 115 | return "RspAuth [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", brokerID=" + brokerID + ", userID=" 116 | + userID + ", userProductInfo=" + userProductInfo + ", authInfo=" + Arrays.toString(authInfo) + "]"; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspContractBank.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import com.ee.ctp.ApplicationRuntime; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | import io.netty.util.ReferenceCountUtil; 11 | /** 12 | * 13 | * @author ee 14 | * 2017年10月17日 下午8:18:53 15 | * 16 | */ 17 | public class RspContractBank implements FtdcRsp{ 18 | // 11 19 | private String brokerID; 20 | // 4 21 | private String bankID; 22 | // 5 23 | private String bankBrchID; 24 | // 101 25 | private String bankName; 26 | 27 | 28 | public String getBrokerID() { 29 | return brokerID; 30 | } 31 | 32 | 33 | public void setBrokerID(String brokerID) { 34 | this.brokerID = brokerID; 35 | } 36 | 37 | 38 | public String getBankID() { 39 | return bankID; 40 | } 41 | 42 | 43 | public void setBankID(String bankID) { 44 | this.bankID = bankID; 45 | } 46 | 47 | 48 | public String getBankBrchID() { 49 | return bankBrchID; 50 | } 51 | 52 | 53 | public void setBankBrchID(String bankBrchID) { 54 | this.bankBrchID = bankBrchID; 55 | } 56 | 57 | 58 | public String getBankName() { 59 | return bankName; 60 | } 61 | 62 | 63 | public void setBankName(String bankName) { 64 | this.bankName = bankName; 65 | } 66 | 67 | 68 | @Override 69 | public RspContractBank parseFrom(ByteBuf body, RspError error) { 70 | try { 71 | RspContractBank info = new RspContractBank(); 72 | byte[] brokerID = new byte[11]; 73 | body.readBytes(brokerID); 74 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 75 | 76 | byte[] bankId = new byte[4]; 77 | body.readBytes(bankId); 78 | info.setBankID(StringUtils.trimToEmpty(new String(bankId))); 79 | 80 | byte[] bankBrchID = new byte[5]; 81 | body.readBytes(bankBrchID); 82 | info.setBankBrchID(StringUtils.trimToEmpty(new String(bankBrchID))); 83 | byte[] bankName = new byte[101]; 84 | body.readBytes(bankName); 85 | try { 86 | info.setBankName(StringUtils.trimToEmpty(new String(bankName, ApplicationRuntime.conf().defaultEncoding()))); 87 | } catch (UnsupportedEncodingException e) { 88 | // ignore 89 | } 90 | return info; 91 | } finally { 92 | ReferenceCountUtil.release(body); 93 | } 94 | } 95 | 96 | 97 | @Override 98 | public String toString() { 99 | return "RspContractBank [brokerID=" + brokerID + ", bankID=" + bankID + ", bankBrchID=" + bankBrchID 100 | + ", bankName=" + bankName + "]"; 101 | } 102 | 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspError.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import com.ee.ctp.ApplicationRuntime; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年10月17日 下午8:19:01 14 | * 15 | */ 16 | public class RspError { 17 | // 4 18 | private int errorCode; 19 | // 81 20 | private String errorMsg; 21 | 22 | public int getErrorCode() { 23 | return errorCode; 24 | } 25 | 26 | public void setErrorCode(int errorCode) { 27 | this.errorCode = errorCode; 28 | } 29 | 30 | public String getErrorMsg() { 31 | return errorMsg; 32 | } 33 | 34 | public void setErrorMsg(String errorMsg) { 35 | this.errorMsg = errorMsg; 36 | } 37 | 38 | public static RspError parseFrom(ByteBuf body) { 39 | RspError error = new RspError(); 40 | error.setErrorCode(body.readInt()); 41 | byte[] errorMsg = new byte[81]; 42 | body.readBytes(errorMsg); 43 | try { 44 | error.setErrorMsg(StringUtils.trimToEmpty(new String(errorMsg, ApplicationRuntime.conf().defaultEncoding()))); 45 | } catch (UnsupportedEncodingException e) { 46 | // ignore 47 | } 48 | return error; 49 | 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "RspError [errorCode=" + errorCode + ", errorMsg=" + errorMsg + "]"; 55 | } 56 | 57 | public static RspError buildConnectError() { 58 | RspError loginError = new RspError(); 59 | loginError.setErrorCode(9999); 60 | loginError.setErrorMsg("超过重试次数,连接失败"); 61 | return loginError; 62 | } 63 | 64 | public static RspError buildRecieveMessageError() { 65 | RspError loginError = new RspError(); 66 | loginError.setErrorCode(9999); 67 | loginError.setErrorMsg("消息超时"); 68 | return loginError; 69 | } 70 | 71 | public static RspError buildConnectionLostError() { 72 | RspError loginError = new RspError(); 73 | loginError.setErrorCode(9999); 74 | loginError.setErrorMsg("连接已断开,请重新登录"); 75 | return loginError; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspFundPasswordUpdate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcCurrencyID; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author lyb 11 | * 12 | */ 13 | public class RspFundPasswordUpdate implements FtdcRsp{ 14 | // 4 15 | private int errorCode; 16 | // 81 17 | private String errorMsg; 18 | // 11 19 | private String brokerID; 20 | // 13 21 | private String userID; 22 | // 41 23 | private String oldPassword; 24 | // 41 25 | private String newPassword; 26 | private FtdcCurrencyID currencyID; 27 | 28 | public String getBrokerID() { 29 | return brokerID; 30 | } 31 | public void setBrokerID(String brokerID) { 32 | this.brokerID = brokerID; 33 | } 34 | public String getUserID() { 35 | return userID; 36 | } 37 | public void setUserID(String userID) { 38 | this.userID = userID; 39 | } 40 | public String getOldPassword() { 41 | return oldPassword; 42 | } 43 | public void setOldPassword(String oldPassword) { 44 | this.oldPassword = oldPassword; 45 | } 46 | public String getNewPassword() { 47 | return newPassword; 48 | } 49 | public void setNewPassword(String newPassword) { 50 | this.newPassword = newPassword; 51 | } 52 | public int getErrorCode() { 53 | return errorCode; 54 | } 55 | public void setErrorCode(int errorCode) { 56 | this.errorCode = errorCode; 57 | } 58 | public String getErrorMsg() { 59 | return errorMsg; 60 | } 61 | public void setErrorMsg(String errorMsg) { 62 | this.errorMsg = errorMsg; 63 | } 64 | public FtdcCurrencyID getCurrencyID() { 65 | return currencyID; 66 | } 67 | public void setCurrencyID(FtdcCurrencyID currencyID) { 68 | this.currencyID = currencyID; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "RspFundPasswordUpdate [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", brokerID=" + brokerID 74 | + ", userID=" + userID + ", oldPassword=" + oldPassword + ", newPassword=" + newPassword 75 | + ", currencyID=" + currencyID + "]"; 76 | } 77 | 78 | 79 | @Override 80 | public RspFundPasswordUpdate parseFrom(ByteBuf body, RspError error) { 81 | 82 | this.setErrorMsg(error.getErrorMsg()); 83 | this.setErrorCode(error.getErrorCode()); 84 | 85 | byte[] brokerID = new byte[11]; 86 | body.readBytes(brokerID); 87 | this.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 88 | 89 | byte[] userID = new byte[13]; 90 | body.readBytes(userID); 91 | this.setUserID(StringUtils.trimToEmpty(new String(userID))); 92 | 93 | byte[] oldPassword = new byte[41]; 94 | body.readBytes(oldPassword); 95 | this.setOldPassword(StringUtils.trimToEmpty(new String(oldPassword))); 96 | 97 | byte[] newPassword = new byte[41]; 98 | body.readBytes(newPassword); 99 | this.setNewPassword(StringUtils.trimToEmpty(new String(newPassword))); 100 | 101 | return this; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspQryCommissionRate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcInvestorRangeType; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:19:36 12 | * 13 | */ 14 | public class RspQryCommissionRate implements FtdcRsp{ 15 | // 31 16 | private String instrumentID; 17 | // 1 18 | private FtdcInvestorRangeType investorRange; 19 | // 11 20 | private String brokerID; 21 | // 13 22 | private String investorID; 23 | // 8 24 | private double openRatioByMoney; 25 | // 8 26 | private double openRatioByVolume; 27 | // 8 28 | private double closeRatioByMoney; 29 | // 8 30 | private double closeRatioByVolume; 31 | // 8 32 | private double closeTodayRatioByMoney; 33 | // 8 34 | private double closeTodayRatioByVolume; 35 | 36 | 37 | public String getInstrumentID() { 38 | return instrumentID; 39 | } 40 | 41 | 42 | public void setInstrumentID(String instrumentID) { 43 | this.instrumentID = instrumentID; 44 | } 45 | 46 | 47 | public FtdcInvestorRangeType getInvestorRange() { 48 | return investorRange; 49 | } 50 | 51 | 52 | public void setInvestorRange(FtdcInvestorRangeType investorRange) { 53 | this.investorRange = investorRange; 54 | } 55 | 56 | 57 | public String getBrokerID() { 58 | return brokerID; 59 | } 60 | 61 | 62 | public void setBrokerID(String brokerID) { 63 | this.brokerID = brokerID; 64 | } 65 | 66 | 67 | public String getInvestorID() { 68 | return investorID; 69 | } 70 | 71 | 72 | public void setInvestorID(String investorID) { 73 | this.investorID = investorID; 74 | } 75 | 76 | 77 | public double getOpenRatioByMoney() { 78 | return openRatioByMoney; 79 | } 80 | 81 | 82 | public void setOpenRatioByMoney(double openRatioByMoney) { 83 | this.openRatioByMoney = openRatioByMoney; 84 | } 85 | 86 | 87 | public double getOpenRatioByVolume() { 88 | return openRatioByVolume; 89 | } 90 | 91 | 92 | public void setOpenRatioByVolume(double openRatioByVolume) { 93 | this.openRatioByVolume = openRatioByVolume; 94 | } 95 | 96 | 97 | public double getCloseRatioByMoney() { 98 | return closeRatioByMoney; 99 | } 100 | 101 | 102 | public void setCloseRatioByMoney(double closeRatioByMoney) { 103 | this.closeRatioByMoney = closeRatioByMoney; 104 | } 105 | 106 | 107 | public double getCloseRatioByVolume() { 108 | return closeRatioByVolume; 109 | } 110 | 111 | 112 | public void setCloseRatioByVolume(double closeRatioByVolume) { 113 | this.closeRatioByVolume = closeRatioByVolume; 114 | } 115 | 116 | 117 | public double getCloseTodayRatioByMoney() { 118 | return closeTodayRatioByMoney; 119 | } 120 | 121 | 122 | public void setCloseTodayRatioByMoney(double closeTodayRatioByMoney) { 123 | this.closeTodayRatioByMoney = closeTodayRatioByMoney; 124 | } 125 | 126 | 127 | public double getCloseTodayRatioByVolume() { 128 | return closeTodayRatioByVolume; 129 | } 130 | 131 | 132 | public void setCloseTodayRatioByVolume(double closeTodayRatioByVolume) { 133 | this.closeTodayRatioByVolume = closeTodayRatioByVolume; 134 | } 135 | 136 | @Override 137 | public RspQryCommissionRate parseFrom(ByteBuf body, RspError error) { 138 | RspQryCommissionRate info = new RspQryCommissionRate(); 139 | byte[] instrumentID = new byte[31]; 140 | body.readBytes(instrumentID); 141 | info.setInstrumentID(StringUtils.trimToEmpty(new String(instrumentID))); 142 | 143 | byte[] investorRange = new byte[1]; 144 | body.readBytes(investorRange); 145 | info.setInvestorRange(FtdcInvestorRangeType.parseFrom(StringUtils.trimToEmpty(new String(investorRange)))); 146 | 147 | byte[] brokerID = new byte[11]; 148 | body.readBytes(brokerID); 149 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 150 | 151 | byte[] investorID = new byte[13]; 152 | body.readBytes(investorID); 153 | info.setInvestorID(StringUtils.trimToEmpty(new String(investorID))); 154 | 155 | info.setOpenRatioByMoney(body.readDouble()); 156 | 157 | info.setOpenRatioByVolume(body.readDouble()); 158 | 159 | info.setCloseRatioByMoney(body.readDouble()); 160 | 161 | info.setCloseRatioByVolume(body.readDouble()); 162 | 163 | info.setCloseTodayRatioByMoney(body.readDouble()); 164 | 165 | info.setCloseTodayRatioByVolume(body.readDouble()); 166 | 167 | return info; 168 | } 169 | 170 | 171 | @Override 172 | public String toString() { 173 | return "RspQryCommissionRate [instrumentID=" + instrumentID + ", investorRange=" + investorRange + ", brokerID=" 174 | + brokerID + ", investorID=" + investorID + ", openRatioByMoney=" + openRatioByMoney 175 | + ", openRatioByVolume=" + openRatioByVolume + ", closeRatioByMoney=" + closeRatioByMoney 176 | + ", closeRatioByVolume=" + closeRatioByVolume + ", closeTodayRatioByMoney=" + closeTodayRatioByMoney 177 | + ", closeTodayRatioByVolume=" + closeTodayRatioByVolume + "]"; 178 | } 179 | 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspQryMarginRate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import com.ee.ctp.enums.business.FtdcBillHedgeFlag; 6 | import com.ee.ctp.enums.business.FtdcInvestorRangeType; 7 | 8 | import io.netty.buffer.ByteBuf; 9 | /** 10 | * 11 | * @author ee 12 | * 2017年10月17日 下午8:19:46 13 | * 14 | */ 15 | public class RspQryMarginRate implements FtdcRsp{ 16 | // 31 17 | private String instrumentID; 18 | // 1 19 | private FtdcInvestorRangeType investorRange; 20 | // 11 21 | private String brokerID; 22 | // 13 23 | private String investorID; 24 | // 1 25 | private FtdcBillHedgeFlag hedgeFlag; 26 | // 8 27 | private double longMarginRatioByMoney; 28 | // 8 29 | private double longMarginRatioByVolume; 30 | // 8 31 | private double shortMarginRatioByMoney; 32 | // 8 33 | private double shortMarginRatioByVolume; 34 | // 4 35 | private int isRelative; 36 | 37 | public String getInstrumentID() { 38 | return instrumentID; 39 | } 40 | 41 | public void setInstrumentID(String instrumentID) { 42 | this.instrumentID = instrumentID; 43 | } 44 | 45 | public FtdcInvestorRangeType getInvestorRange() { 46 | return investorRange; 47 | } 48 | 49 | public void setInvestorRange(FtdcInvestorRangeType investorRange) { 50 | this.investorRange = investorRange; 51 | } 52 | 53 | public String getBrokerID() { 54 | return brokerID; 55 | } 56 | 57 | public void setBrokerID(String brokerID) { 58 | this.brokerID = brokerID; 59 | } 60 | 61 | public String getInvestorID() { 62 | return investorID; 63 | } 64 | 65 | public void setInvestorID(String investorID) { 66 | this.investorID = investorID; 67 | } 68 | 69 | public FtdcBillHedgeFlag getHedgeFlag() { 70 | return hedgeFlag; 71 | } 72 | 73 | public void setHedgeFlag(FtdcBillHedgeFlag hedgeFlag) { 74 | this.hedgeFlag = hedgeFlag; 75 | } 76 | 77 | public double getLongMarginRatioByMoney() { 78 | return longMarginRatioByMoney; 79 | } 80 | 81 | public void setLongMarginRatioByMoney(double longMarginRatioByMoney) { 82 | this.longMarginRatioByMoney = longMarginRatioByMoney; 83 | } 84 | 85 | public double getLongMarginRatioByVolume() { 86 | return longMarginRatioByVolume; 87 | } 88 | 89 | public void setLongMarginRatioByVolume(double longMarginRatioByVolume) { 90 | this.longMarginRatioByVolume = longMarginRatioByVolume; 91 | } 92 | 93 | public double getShortMarginRatioByMoney() { 94 | return shortMarginRatioByMoney; 95 | } 96 | 97 | public void setShortMarginRatioByMoney(double shortMarginRatioByMoney) { 98 | this.shortMarginRatioByMoney = shortMarginRatioByMoney; 99 | } 100 | 101 | public double getShortMarginRatioByVolume() { 102 | return shortMarginRatioByVolume; 103 | } 104 | 105 | public void setShortMarginRatioByVolume(double shortMarginRatioByVolume) { 106 | this.shortMarginRatioByVolume = shortMarginRatioByVolume; 107 | } 108 | 109 | public int getIsRelative() { 110 | return isRelative; 111 | } 112 | 113 | public void setIsRelative(int isRelative) { 114 | this.isRelative = isRelative; 115 | } 116 | 117 | @Override 118 | public RspQryMarginRate parseFrom(ByteBuf body, RspError error) { 119 | RspQryMarginRate info = new RspQryMarginRate(); 120 | byte[] instrumentID = new byte[31]; 121 | body.readBytes(instrumentID); 122 | info.setInstrumentID(StringUtils.trimToEmpty(new String(instrumentID))); 123 | 124 | byte[] investorRange = new byte[1]; 125 | body.readBytes(investorRange); 126 | info.setInvestorRange(FtdcInvestorRangeType.parseFrom(StringUtils.trimToEmpty(new String(investorRange)))); 127 | 128 | byte[] brokerID = new byte[11]; 129 | body.readBytes(brokerID); 130 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 131 | 132 | byte[] investorID = new byte[13]; 133 | body.readBytes(investorID); 134 | info.setInvestorID(StringUtils.trimToEmpty(new String(investorID))); 135 | 136 | byte[] hedgeFlag = new byte[1]; 137 | body.readBytes(hedgeFlag); 138 | info.setHedgeFlag(FtdcBillHedgeFlag.parseFrom(StringUtils.trimToEmpty(new String(hedgeFlag)))); 139 | 140 | info.setLongMarginRatioByMoney(body.readDouble()); 141 | 142 | info.setLongMarginRatioByVolume(body.readDouble()); 143 | 144 | info.setShortMarginRatioByMoney(body.readDouble()); 145 | 146 | info.setShortMarginRatioByVolume(body.readDouble()); 147 | 148 | info.setIsRelative(body.readInt()); 149 | 150 | return info; 151 | } 152 | 153 | @Override 154 | public String toString() { 155 | return "RspQryMarginRate [instrumentID=" + instrumentID + ", investorRange=" + investorRange + ", brokerID=" 156 | + brokerID + ", investorID=" + investorID + ", hedgeFlag=" + hedgeFlag + ", longMarginRatioByMoney=" 157 | + longMarginRatioByMoney + ", longMarginRatioByVolume=" + longMarginRatioByVolume 158 | + ", shortMarginRatioByMoney=" + shortMarginRatioByMoney + ", shortMarginRatioByVolume=" 159 | + shortMarginRatioByVolume + ", isRelative=" + isRelative + "]"; 160 | } 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspQrySettlementInfoConfirm.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:19:51 10 | * 11 | */ 12 | public class RspQrySettlementInfoConfirm implements FtdcRsp{ 13 | // 11 14 | private String brokerID; 15 | // 13 16 | private String investorID; 17 | // 9 18 | private String confirmDate; 19 | // 9 20 | private String confirmTime; 21 | 22 | public String getBrokerID() { 23 | return brokerID; 24 | } 25 | public void setBrokerID(String brokerID) { 26 | this.brokerID = brokerID; 27 | } 28 | public String getInvestorID() { 29 | return investorID; 30 | } 31 | public void setInvestorID(String investorID) { 32 | this.investorID = investorID; 33 | } 34 | public String getConfirmDate() { 35 | return confirmDate; 36 | } 37 | public void setConfirmDate(String confirmDate) { 38 | this.confirmDate = confirmDate; 39 | } 40 | public String getConfirmTime() { 41 | return confirmTime; 42 | } 43 | public void setConfirmTime(String confirmTime) { 44 | this.confirmTime = confirmTime; 45 | } 46 | 47 | @Override 48 | public RspQrySettlementInfoConfirm parseFrom(ByteBuf body, RspError errror) { 49 | RspQrySettlementInfoConfirm info = new RspQrySettlementInfoConfirm(); 50 | 51 | byte[] brokerID = new byte[11]; 52 | body.readBytes(brokerID); 53 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 54 | 55 | byte[] investorID = new byte[13]; 56 | body.readBytes(investorID); 57 | info.setInvestorID(StringUtils.trimToEmpty(new String(investorID))); 58 | 59 | byte[] confirmDate = new byte[9]; 60 | body.readBytes(confirmDate); 61 | info.setConfirmDate(StringUtils.trimToEmpty(new String(confirmDate))); 62 | 63 | byte[] confirmTime = new byte[9]; 64 | body.readBytes(confirmTime); 65 | info.setConfirmTime(StringUtils.trimToEmpty(new String(confirmTime))); 66 | return info; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "RspQrySettlementInfoConfirm [brokerID=" + brokerID + ", investorID=" + investorID + ", confirmDate=" 72 | + confirmDate + ", confirmTime=" + confirmTime + "]"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspSettlementInfo.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import java.util.Comparator; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import io.netty.buffer.ByteBuf; 8 | import io.netty.util.ReferenceCountUtil; 9 | /** 10 | * 11 | * @author ee 12 | * 2017年10月17日 下午8:20:01 13 | * 14 | */ 15 | public class RspSettlementInfo implements FtdcRsp{ 16 | 17 | public static final SequenceComparator DEFAULT_COMPARATOR = new SequenceComparator(); 18 | 19 | //9 20 | private String tradingDay; 21 | //4 22 | private int settlementID; 23 | //11 24 | private String brokerID; 25 | //13 26 | private String investorID; 27 | //4 28 | private int sequenceNo; 29 | //501 30 | private byte[] content; 31 | 32 | public String getTradingDay() { 33 | return tradingDay; 34 | } 35 | public void setTradingDay(String tradingDay) { 36 | this.tradingDay = tradingDay; 37 | } 38 | public int getSettlementID() { 39 | return settlementID; 40 | } 41 | public void setSettlementID(int settlementID) { 42 | this.settlementID = settlementID; 43 | } 44 | public String getBrokerID() { 45 | return brokerID; 46 | } 47 | public void setBrokerID(String brokerID) { 48 | this.brokerID = brokerID; 49 | } 50 | public String getInvestorID() { 51 | return investorID; 52 | } 53 | public void setInvestorID(String investorID) { 54 | this.investorID = investorID; 55 | } 56 | public int getSequenceNo() { 57 | return sequenceNo; 58 | } 59 | public void setSequenceNo(int sequenceNo) { 60 | this.sequenceNo = sequenceNo; 61 | } 62 | public byte[] getContent() { 63 | return content; 64 | } 65 | public void setContent(byte[] content) { 66 | this.content = content; 67 | } 68 | 69 | @Override 70 | public RspSettlementInfo parseFrom(ByteBuf body, RspError error) { 71 | try { 72 | RspSettlementInfo info = new RspSettlementInfo(); 73 | byte[] tradingDay = new byte[9]; 74 | body.readBytes(tradingDay); 75 | info.setTradingDay(StringUtils.trimToEmpty(new String(tradingDay))); 76 | info.setSettlementID(body.readInt()); 77 | byte[] brokerID = new byte[11]; 78 | body.readBytes(brokerID); 79 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 80 | byte[] investorID = new byte[13]; 81 | body.readBytes(investorID); 82 | info.setInvestorID(StringUtils.trimToEmpty(new String(investorID))); 83 | info.setSequenceNo(body.readInt()); 84 | byte[] content = new byte[501]; 85 | body.readBytes(content); 86 | info.setContent(content); 87 | return info; 88 | } finally { 89 | ReferenceCountUtil.release(body); 90 | } 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "RspSettlementInfo [tradingDay=" + tradingDay + ", settlementID=" + settlementID + ", brokerID=" 96 | + brokerID + ", investorID=" + investorID + ", sequenceNo=" + sequenceNo + "]"; 97 | } 98 | 99 | static class SequenceComparator implements Comparator { 100 | 101 | @Override 102 | public int compare(RspSettlementInfo o1, RspSettlementInfo o2) { 103 | return Integer.compare(o1.getSequenceNo(), o2.getSequenceNo()); 104 | } 105 | 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspSettlementInfoConfirm.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:20:08 10 | * 11 | */ 12 | public class RspSettlementInfoConfirm implements FtdcRsp{ 13 | private int errorCode; 14 | //81 15 | private String errorMsg; 16 | // 11 17 | private String brokerID; 18 | // 13 19 | private String investorID; 20 | // 9 21 | private String confirmDate; 22 | // 9 23 | private String confirmTime; 24 | 25 | public String getBrokerID() { 26 | return brokerID; 27 | } 28 | public void setBrokerID(String brokerID) { 29 | this.brokerID = brokerID; 30 | } 31 | public String getInvestorID() { 32 | return investorID; 33 | } 34 | public void setInvestorID(String investorID) { 35 | this.investorID = investorID; 36 | } 37 | public String getConfirmDate() { 38 | return confirmDate; 39 | } 40 | public void setConfirmDate(String confirmDate) { 41 | this.confirmDate = confirmDate; 42 | } 43 | public String getConfirmTime() { 44 | return confirmTime; 45 | } 46 | public void setConfirmTime(String confirmTime) { 47 | this.confirmTime = confirmTime; 48 | } 49 | 50 | public int getErrorCode() { 51 | return errorCode; 52 | } 53 | public void setErrorCode(int errorCode) { 54 | this.errorCode = errorCode; 55 | } 56 | public String getErrorMsg() { 57 | return errorMsg; 58 | } 59 | public void setErrorMsg(String errorMsg) { 60 | this.errorMsg = errorMsg; 61 | } 62 | 63 | @Override 64 | public RspSettlementInfoConfirm parseFrom(ByteBuf body, RspError error) { 65 | RspSettlementInfoConfirm info = new RspSettlementInfoConfirm(); 66 | 67 | info.setErrorMsg(error.getErrorMsg()); 68 | info.setErrorCode(error.getErrorCode()); 69 | 70 | byte[] brokerID = new byte[11]; 71 | body.readBytes(brokerID); 72 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 73 | 74 | byte[] investorID = new byte[13]; 75 | body.readBytes(investorID); 76 | info.setInvestorID(StringUtils.trimToEmpty(new String(investorID))); 77 | 78 | byte[] confirmDate = new byte[9]; 79 | body.readBytes(confirmDate); 80 | info.setConfirmDate(StringUtils.trimToEmpty(new String(confirmDate))); 81 | 82 | byte[] confirmTime = new byte[9]; 83 | body.readBytes(confirmTime); 84 | info.setConfirmTime(StringUtils.trimToEmpty(new String(confirmTime))); 85 | return info; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return "RspSettlementInfoConfirm [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", brokerID=" + brokerID 91 | + ", investorID=" + investorID + ", confirmDate=" + confirmDate + ", confirmTime=" + confirmTime + "]"; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspUserLogin.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:20:20 10 | * 11 | */ 12 | public class RspUserLogin implements FtdcRsp{ 13 | private int errorCode; 14 | //81 15 | private String errorMsg; 16 | //9 17 | private String tradingDay; 18 | //9 19 | private String loginTime; 20 | //11 21 | private String brokerID; 22 | //16 23 | private String userID; 24 | //41 25 | private String systemName; 26 | //4 27 | private int frontId; 28 | //4 29 | private int sessionId; 30 | //13 31 | private String orderRefType; 32 | //9 33 | private String shfeTime; 34 | //9 35 | private String dcetTime; 36 | //9 37 | private String czceTime; 38 | //9 39 | private String ffexTime; 40 | //9 41 | private String inetTime; 42 | 43 | public int getErrorCode() { 44 | return errorCode; 45 | } 46 | public void setErrorCode(int errorCode) { 47 | this.errorCode = errorCode; 48 | } 49 | public String getErrorMsg() { 50 | return errorMsg; 51 | } 52 | public void setErrorMsg(String errorMsg) { 53 | this.errorMsg = errorMsg; 54 | } 55 | 56 | public String getTradingDay() { 57 | return tradingDay; 58 | } 59 | public void setTradingDay(String tradingDay) { 60 | this.tradingDay = tradingDay; 61 | } 62 | public String getLoginTime() { 63 | return loginTime; 64 | } 65 | public void setLoginTime(String loginTime) { 66 | this.loginTime = loginTime; 67 | } 68 | public String getBrokerID() { 69 | return brokerID; 70 | } 71 | public void setBrokerID(String brokerID) { 72 | this.brokerID = brokerID; 73 | } 74 | public String getUserID() { 75 | return userID; 76 | } 77 | public void setUserID(String userID) { 78 | this.userID = userID; 79 | } 80 | public String getSystemName() { 81 | return systemName; 82 | } 83 | public void setSystemName(String systemName) { 84 | this.systemName = systemName; 85 | } 86 | public int getFrontId() { 87 | return frontId; 88 | } 89 | public void setFrontId(int frontId) { 90 | this.frontId = frontId; 91 | } 92 | public int getSessionId() { 93 | return sessionId; 94 | } 95 | public void setSessionId(int sessionId) { 96 | this.sessionId = sessionId; 97 | } 98 | public String getOrderRefType() { 99 | return orderRefType; 100 | } 101 | public void setOrderRefType(String orderRefType) { 102 | this.orderRefType = orderRefType; 103 | } 104 | public String getShfeTime() { 105 | return shfeTime; 106 | } 107 | public void setShfeTime(String shfeTime) { 108 | this.shfeTime = shfeTime; 109 | } 110 | public String getDcetTime() { 111 | return dcetTime; 112 | } 113 | public void setDcetTime(String dcetTime) { 114 | this.dcetTime = dcetTime; 115 | } 116 | public String getCzceTime() { 117 | return czceTime; 118 | } 119 | public void setCzceTime(String czceTime) { 120 | this.czceTime = czceTime; 121 | } 122 | public String getFfexTime() { 123 | return ffexTime; 124 | } 125 | public void setFfexTime(String ffexTime) { 126 | this.ffexTime = ffexTime; 127 | } 128 | public String getInetTime() { 129 | return inetTime; 130 | } 131 | public void setInetTime(String inetTime) { 132 | this.inetTime = inetTime; 133 | } 134 | 135 | @Override 136 | public RspUserLogin parseFrom(ByteBuf body, RspError error) { 137 | RspUserLogin userLogin = new RspUserLogin(); 138 | 139 | userLogin.setErrorMsg(error.getErrorMsg()); 140 | userLogin.setErrorCode(error.getErrorCode()); 141 | 142 | byte[] tradingDay = new byte[9]; 143 | body.readBytes(tradingDay); 144 | userLogin.setTradingDay(StringUtils.trimToEmpty(new String(tradingDay))); 145 | 146 | byte[] tradingTime = new byte[9]; 147 | body.readBytes(tradingTime); 148 | userLogin.setLoginTime(StringUtils.trimToEmpty(new String(tradingTime))); 149 | 150 | byte[] brokerid = new byte[11]; 151 | body.readBytes(brokerid); 152 | userLogin.setBrokerID(StringUtils.trimToEmpty(new String(brokerid))); 153 | 154 | byte[] userid = new byte[16]; 155 | body.readBytes(userid); 156 | userLogin.setUserID(StringUtils.trimToEmpty(new String(userid))); 157 | 158 | byte[] sysname = new byte[41]; 159 | body.readBytes(sysname); 160 | userLogin.setSystemName(StringUtils.trimToEmpty(new String(sysname))); 161 | 162 | userLogin.setFrontId(body.readInt()); 163 | userLogin.setSessionId(body.readInt()); 164 | 165 | byte[] maxorderRef = new byte[13]; 166 | body.readBytes(maxorderRef); 167 | userLogin.setOrderRefType(StringUtils.trimToEmpty(new String(maxorderRef))); 168 | 169 | byte[] shfe = new byte[9]; 170 | body.readBytes(shfe); 171 | userLogin.setShfeTime(StringUtils.trimToEmpty(new String(shfe))); 172 | 173 | byte[] dcet = new byte[9]; 174 | body.readBytes(dcet); 175 | userLogin.setDcetTime(StringUtils.trimToEmpty(new String(dcet))); 176 | 177 | byte[] czce = new byte[9]; 178 | body.readBytes(czce); 179 | userLogin.setCzceTime(StringUtils.trimToEmpty(new String(czce))); 180 | 181 | byte[] ffex = new byte[9]; 182 | body.readBytes(ffex); 183 | userLogin.setFfexTime(StringUtils.trimToEmpty(new String(ffex))); 184 | 185 | byte[] inet = new byte[9]; 186 | body.readBytes(inet); 187 | userLogin.setInetTime(StringUtils.trimToEmpty(new String(inet))); 188 | 189 | return userLogin; 190 | } 191 | 192 | @Override 193 | public String toString() { 194 | return "RspUserLogin [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", tradingDay=" + tradingDay + ", loginTime=" + loginTime + ", brokerID=" + brokerID + ", userID=" 195 | + userID + ", systemName=" + systemName + ", frontId=" + frontId + ", sessionId=" + sessionId 196 | + ", orderRefType=" + orderRefType + ", shfeTime=" + shfeTime + ", dcetTime=" + dcetTime + ", czceTime=" 197 | + czceTime + ", ffexTime=" + ffexTime + ", inetTime=" + inetTime + "]"; 198 | } 199 | 200 | 201 | } 202 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspUserLogout.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年10月17日 下午8:20:25 10 | * 11 | */ 12 | public class RspUserLogout implements FtdcRsp{ 13 | // 4 14 | private int errorCode; 15 | // 81 16 | private String errorMsg; 17 | // 11 18 | private String brokerID; 19 | // 16 20 | private String userID; 21 | 22 | public int getErrorCode() { 23 | return errorCode; 24 | } 25 | public void setErrorCode(int errorCode) { 26 | this.errorCode = errorCode; 27 | } 28 | public String getErrorMsg() { 29 | return errorMsg; 30 | } 31 | public void setErrorMsg(String errorMsg) { 32 | this.errorMsg = errorMsg; 33 | } 34 | 35 | public String getBrokerID() { 36 | return brokerID; 37 | } 38 | public void setBrokerID(String brokerID) { 39 | this.brokerID = brokerID; 40 | } 41 | public String getUserID() { 42 | return userID; 43 | } 44 | public void setUserID(String userID) { 45 | this.userID = userID; 46 | } 47 | 48 | @Override 49 | public RspUserLogout parseFrom(ByteBuf body, RspError error) { 50 | RspUserLogout lout = new RspUserLogout(); 51 | lout.setErrorMsg(error.getErrorMsg()); 52 | lout.setErrorCode(error.getErrorCode()); 53 | 54 | byte[] brokerid = new byte[11]; 55 | body.readBytes(brokerid); 56 | lout.setBrokerID(StringUtils.trimToEmpty(new String(brokerid))); 57 | 58 | byte[] userid = new byte[16]; 59 | body.readBytes(userid); 60 | lout.setUserID(StringUtils.trimToEmpty(new String(userid))); 61 | return lout; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "RspUserLogout [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", brokerID=" + brokerID 67 | + ", userID=" + userID + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/RspUserPasswordUpdate.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | /** 7 | * 8 | * @author zlj 9 | * 2017年10月17日 下午8:20:30 10 | * 11 | */ 12 | public class RspUserPasswordUpdate implements FtdcRsp{ 13 | // 4 14 | private int errorCode; 15 | // 81 16 | private String errorMsg; 17 | // 11 18 | private String brokerID; 19 | // 16 20 | private String userID; 21 | // 41 22 | private String oldPassword; 23 | // 41 24 | private String newPassword; 25 | public String getBrokerID() { 26 | return brokerID; 27 | } 28 | public void setBrokerID(String brokerID) { 29 | this.brokerID = brokerID; 30 | } 31 | public String getUserID() { 32 | return userID; 33 | } 34 | public void setUserID(String userID) { 35 | this.userID = userID; 36 | } 37 | public String getOldPassword() { 38 | return oldPassword; 39 | } 40 | public void setOldPassword(String oldPassword) { 41 | this.oldPassword = oldPassword; 42 | } 43 | public String getNewPassword() { 44 | return newPassword; 45 | } 46 | public void setNewPassword(String newPassword) { 47 | this.newPassword = newPassword; 48 | } 49 | public int getErrorCode() { 50 | return errorCode; 51 | } 52 | public void setErrorCode(int errorCode) { 53 | this.errorCode = errorCode; 54 | } 55 | public String getErrorMsg() { 56 | return errorMsg; 57 | } 58 | public void setErrorMsg(String errorMsg) { 59 | this.errorMsg = errorMsg; 60 | } 61 | 62 | @Override 63 | public RspUserPasswordUpdate parseFrom(ByteBuf body, RspError error) { 64 | RspUserPasswordUpdate info = new RspUserPasswordUpdate(); 65 | 66 | info.setErrorMsg(error.getErrorMsg()); 67 | info.setErrorCode(error.getErrorCode()); 68 | 69 | byte[] brokerID = new byte[11]; 70 | body.readBytes(brokerID); 71 | info.setBrokerID(StringUtils.trimToEmpty(new String(brokerID))); 72 | 73 | byte[] userID = new byte[16]; 74 | body.readBytes(userID); 75 | info.setUserID(StringUtils.trimToEmpty(new String(userID))); 76 | 77 | byte[] oldPassword = new byte[41]; 78 | body.readBytes(oldPassword); 79 | info.setOldPassword(StringUtils.trimToEmpty(new String(oldPassword))); 80 | 81 | byte[] newPassword = new byte[41]; 82 | body.readBytes(newPassword); 83 | info.setNewPassword(StringUtils.trimToEmpty(new String(newPassword))); 84 | 85 | return info; 86 | } 87 | @Override 88 | public String toString() { 89 | return "RspUserPasswordUpdate [errorCode=" + errorCode + ", errorMsg=" + errorMsg + ", brokerID=" + brokerID 90 | + ", userID=" + userID + ", oldPassword=" + oldPassword + ", newPassword=" + newPassword + "]"; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/dto/UserSession.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.dto; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | /** 6 | * 登录成功存储用户信息 7 | * @author zlj 8 | * @date 2017年9月27日 9 | * 10 | * @modifyBy zlj 2017年9月27日 11 | */ 12 | public class UserSession { 13 | private int frontId; 14 | private String userID; 15 | private String brokerId; 16 | private int sessionId; 17 | private AtomicInteger orderRef = new AtomicInteger(10); 18 | 19 | public UserSession(){ 20 | } 21 | public UserSession(int frontId, String userID, int sessionId, String brokerId) { 22 | this.frontId = frontId; 23 | this.userID = userID; 24 | this.sessionId = sessionId; 25 | this.brokerId = brokerId; 26 | } 27 | 28 | public UserSession(RspUserLogin rspUserLogin) { 29 | this.frontId = rspUserLogin.getFrontId(); 30 | this.userID = rspUserLogin.getUserID(); 31 | this.sessionId = rspUserLogin.getSessionId(); 32 | this.brokerId = rspUserLogin.getBrokerID(); 33 | } 34 | public int getFrontId() { 35 | return frontId; 36 | } 37 | public void setFrontId(int frontId) { 38 | this.frontId = frontId; 39 | } 40 | public String getUserID() { 41 | return userID; 42 | } 43 | public void setUserID(String userID) { 44 | this.userID = userID; 45 | } 46 | public int getSessionId() { 47 | return sessionId; 48 | } 49 | public void setSessionId(int sessionId) { 50 | this.sessionId = sessionId; 51 | } 52 | public String getBrokerId() { 53 | return brokerId; 54 | } 55 | public void setBrokerId(String brokerId) { 56 | this.brokerId = brokerId; 57 | } 58 | 59 | public int orderRef() { 60 | return this.orderRef.getAndIncrement(); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/CTPErrorCode.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | /** 4 | * 5 | * @author ee 6 | * 2017年11月3日 上午10:32:14 7 | * 8 | */ 9 | public enum CTPErrorCode { 10 | /** 11 | * 成功 12 | */ 13 | CTP_OK(0, "CTP:正确"), 14 | /** 15 | * 以下三个对应的code,channel已经认证通过 16 | */ 17 | CTP_WEAK_PASSWORD(131, "CTP:弱密码过期,请修改密码后重新登录"), 18 | CTP_FIRST_LOGIN(140, "CTP:首次登陆,请修改密码后重新登录"), 19 | CTP_PWD_OUT_OF_DATE(141, "CTP:密码过期,请修改密码后重新登录") 20 | ; 21 | 22 | private int code; 23 | private String msg; 24 | private CTPErrorCode(int code, String msg) { 25 | this.code = code; 26 | this.msg = msg; 27 | } 28 | 29 | public static CTPErrorCode parseFrom(int code) { 30 | CTPErrorCode retCode = null; 31 | for (CTPErrorCode t : CTPErrorCode.values()) { 32 | if(t.code == code) { 33 | retCode = t; 34 | break; 35 | } 36 | } 37 | return retCode; 38 | } 39 | 40 | public int getCode() { 41 | return code; 42 | } 43 | 44 | public String getMsg() { 45 | return msg; 46 | } 47 | 48 | public static boolean isChannelAuthPassed(CTPErrorCode code) { 49 | boolean passed = false; 50 | if(code == CTP_OK || CTP_WEAK_PASSWORD == code || CTP_FIRST_LOGIN == code || CTP_PWD_OUT_OF_DATE == code) { 51 | passed = true; 52 | } 53 | return passed; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/ChainType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * 当长包被分包时,一种区分方式通过chain来区分 4 | * @author ee 5 | * 6 | */ 7 | public enum ChainType { 8 | /** 9 | * 结束 10 | */ 11 | END(0x4c), 12 | /** 13 | * 未结束 14 | */ 15 | MID(0x43); 16 | 17 | private int chain; 18 | private ChainType(int chain) { 19 | this.chain = chain; 20 | } 21 | 22 | public int chain() { 23 | return this.chain; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/FtdTagType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * ftd扩展报文头类型 4 | * @author ee 5 | * 2017年10月17日 下午5:57:54 6 | * 7 | */ 8 | public enum FtdTagType { 9 | /** 10 | * 无 11 | */ 12 | FTDTagNone(0x00, 0), 13 | /** 14 | * 时间戳 15 | */ 16 | FTDTagDatetime(0x01, 4), 17 | /** 18 | * 信息正文压缩 19 | */ 20 | FTDTagCompressMethod(0x02, 1), 21 | /** 22 | * 发送端状态 23 | */ 24 | FTDTagSessionState(0x03, 1), 25 | /** 26 | * 心跳 27 | */ 28 | FTDTagKeepAlive(0x05, 0), 29 | /** 30 | * 交易所当前交易日期 31 | */ 32 | FTDTagTradedate(0x06, 4), 33 | /** 34 | * 报文目标 35 | */ 36 | FTDTagTarget(0x07, 2); 37 | 38 | private int type; 39 | private int length; 40 | 41 | private FtdTagType(int type, int length) { 42 | this.type = type; 43 | this.length = length; 44 | } 45 | 46 | public int type() { 47 | return type; 48 | } 49 | 50 | public int length() { 51 | return length; 52 | } 53 | 54 | public static FtdTagType parseFrom(int type) { 55 | switch (type) { 56 | case 0: 57 | return FTDTagNone; 58 | case 1: 59 | return FTDTagDatetime; 60 | case 2: 61 | return FTDTagCompressMethod; 62 | case 3: 63 | return FTDTagSessionState; 64 | case 5: 65 | return FTDTagKeepAlive; 66 | case 6: 67 | return FTDTagTradedate; 68 | case 7: 69 | return FTDTagTarget; 70 | default: 71 | throw new IllegalArgumentException(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/FtdType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * ftd报文类型 4 | * @author ee 5 | * 2017年10月17日 下午5:58:13 6 | * 7 | */ 8 | public enum FtdType { 9 | /** 10 | * 无 11 | */ 12 | FTDTypeNone(0), 13 | /** 14 | * 信息正文正常数据域 15 | */ 16 | FTDTypeFTDC(1), 17 | /** 18 | * 信息正文压缩数据 19 | */ 20 | FTDTypeCompressed(2); 21 | 22 | private int type; 23 | private FtdType(int type) { 24 | this.type = type; 25 | } 26 | 27 | public int type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdType parseFrom(int type) { 32 | switch(type) { 33 | case 0: 34 | return FTDTypeNone; 35 | case 1: 36 | return FTDTypeFTDC; 37 | case 2: 38 | return FTDTypeCompressed; 39 | default: 40 | throw new IllegalArgumentException("unknown type of " + type); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/FtdcType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:49:39 6 | * 7 | */ 8 | public enum FtdcType { 9 | /** 10 | * 请求 11 | */ 12 | REQ(0), 13 | /** 14 | * 应答 15 | */ 16 | RSP(3), 17 | /** 18 | * 请求应答都兼容 19 | */ 20 | REQ_RSP(-1); 21 | 22 | private int type; 23 | private FtdcType(int type) { 24 | this.type = type; 25 | } 26 | 27 | public int type() { 28 | return type; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/Sequence.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * 当长包被分包时,另外一种区分方式是: 4 | * sequenceType 拆包的个数 5 | * currentSequence 表示当前应答到了第几个 6 | * @author ee 7 | * 8 | */ 9 | public enum Sequence { 10 | /** 11 | * 错误应答 12 | */ 13 | RspError(0x0001, 0x00000000), 14 | UserLogin(0x0000, 0x00003000), 15 | AfterUserLogin(0x0000, 0x0000f102), 16 | UserLogout(0x0001, 0x00003002), 17 | ContractBank(0x0004, 0x00008103), 18 | SettlementInfo(0x0004, 0x0000803c), 19 | SettlementInfoConfirm(0x0001, 0x00004013), 20 | QrySettlementInfoConfirm(0x0004, 0x00008056), 21 | TradingAccount(0x0004, 0x00008006), 22 | OrderInsert(0x0001, 0x00004000), 23 | InvestorPosition(0x0004, 0x00008004), 24 | QryOrder(0x0004, 0x00008000), 25 | QryTrade(0x0004, 0x00008002), 26 | QryMarginRate(0x0004, 0x0000800e), 27 | QryCommissionRate(0x0004, 0x00008010), 28 | OrderAction(0x0001, 0x00004006), 29 | AccountRegister(0x0004, 0x00008202), 30 | /** 31 | * 转账流水查询 32 | */ 33 | QryTransferSerial(0x0004, 0x00008200), 34 | 35 | QryInstrument(0x0004, 0x0000802e), 36 | /** 37 | * 银转期 38 | */ 39 | FromBankToFuture(0x0001, 0x0001800b), 40 | /** 41 | * 期转银 42 | */ 43 | FromFutureToBank(0x0001, 0x0001800d), 44 | RtnBankOrFuture(0x0002, 0x0000f204), 45 | UserPasswordUpdate(0x0002, 0x0000300a), 46 | /** 47 | * 资金密码更新 48 | */ 49 | FundPassworeUpdate(0x0001, 0x0000300e), 50 | /** 51 | * 客户端认证 52 | */ 53 | Auth(0x0001, 0x00003010); 54 | 55 | private int sequenceType; 56 | private int sequence; 57 | private int rspSequence; 58 | 59 | private Sequence(int sequenceType, int sequence) { 60 | this.sequence = sequence; 61 | this.sequenceType = sequenceType; 62 | this.rspSequence = this.sequence + 1; 63 | } 64 | 65 | public int sequence() { 66 | return this.sequence; 67 | } 68 | 69 | public int rspSequence() { 70 | return this.rspSequence; 71 | } 72 | 73 | public int sequenceType() { 74 | return this.sequenceType; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/TID.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | /** 3 | * 4 | * 业务标志符: 5 | * 1.前三个字节表示业务结构类型 6 | * 2.最后一个字节表示业务结构的长度 7 | * @author ee 8 | * 2017年10月17日 下午8:49:30 9 | * 10 | */ 11 | public enum TID { 12 | /** 13 | * 未使用的TID,专用于标志尚未识别的业务 14 | */ 15 | UNUSE(0xffffffff, FtdcType.REQ_RSP), 16 | UserLoginReq(0x100200e0, FtdcType.REQ), 17 | UserLoginRsp(0x10030098, FtdcType.RSP), 18 | UserLogoutReq(0x1004001b, FtdcType.REQ), 19 | UserLogoutRsp(0x1004001b, FtdcType.RSP), 20 | /** 21 | * 该TID为公共使用的,代表的是CThostFtdcRspInfoField,包含错误码和错误消息 22 | */ 23 | CommonRsp(0x00000055, FtdcType.RSP), 24 | ContractbankReq(0x24690014, FtdcType.REQ), 25 | ContractbankRsp(0x24700079, FtdcType.RSP), 26 | SettlementInfoReq(0x070c0021, FtdcType.REQ), 27 | SettlementInfoRsp(0x001b021e, FtdcType.RSP), 28 | SettlementInfoConfirmReq(0x040f002a, FtdcType.REQ), 29 | SettlementInfoConfirmRsp(0x040f002a, FtdcType.RSP), 30 | QrySettlementInfoConfirmReq(0x24580018, FtdcType.REQ), 31 | QrySettlementInfoConfirmRsp(0x040f002a, FtdcType.RSP), 32 | TradingAccountReq(0x0703001c, FtdcType.REQ), 33 | TradingAccountRsp(0x000c0171, FtdcType.RSP), 34 | OrderInsertReq(0x04000105, FtdcType.REQ), 35 | OrderInsertRsp(0x04000105, FtdcType.RSP), 36 | /** 37 | * 报单回报以及报单查询都是该TID 38 | */ 39 | RtnOrder(0x0401027b, FtdcType.RSP), 40 | /** 41 | * 成交回报以及成交查询都是该TID 42 | */ 43 | RtnTrade(0x04090138, FtdcType.RSP), 44 | InvestorPositionReq(0x07020037, FtdcType.REQ), 45 | InvestorPositionRsp(0x000d012f, FtdcType.RSP), 46 | QryOrderReq(0x07000067, FtdcType.REQ), 47 | QryTradeReq(0x07010067, FtdcType.REQ), 48 | QryMarginRateReq(0x07070038, FtdcType.REQ), 49 | QryMarginRateRsp(0x000e005d, FtdcType.RSP), 50 | QryCommissionRateReq(0x07080037, FtdcType.REQ), 51 | QryCommissionRateRsp(0x000f0068, FtdcType.RSP), 52 | /** 53 | * 报单操作请求 54 | */ 55 | OrderActionReq(0x040400c5, FtdcType.REQ), 56 | OrderActionRsp(0x040400c5, FtdcType.RSP), 57 | /** 58 | * 报单操作请求响应 59 | */ 60 | /** 61 | * 报单操作错误回报 62 | */ 63 | ErrRtnOrderAction(0x04050190, FtdcType.RSP), 64 | AccountRegisterReq(0x30110025, FtdcType.REQ), 65 | AccountRegisterRsp(0x30120197, FtdcType.RSP), 66 | QryTransferSerialReq(0x300d0020, FtdcType.REQ), 67 | QryTransferSerialRsp(0x300c0193, FtdcType.RSP), 68 | QryInstrumentReq(0x07170066, FtdcType.REQ), 69 | QryInstrumentRsp(0x00030116, FtdcType.RSP), 70 | FromBankToFutureReq(0x2807034a, FtdcType.REQ), 71 | BankOrFutureRsp1(0x100800a7, FtdcType.RSP), 72 | BankOrFutureRsp2(0x100a00a7, FtdcType.RSP), 73 | BankOrFutureRsp(0x2807034a, FtdcType.RSP), 74 | FromFutureToBankReq(0x2807034a, FtdcType.REQ), 75 | RtnBankOrFuture(0x2808039f, FtdcType.RSP), 76 | /** 77 | * 用户口令更新请求 78 | */ 79 | UserPasswordUpdateReq(0x0304006d, FtdcType.REQ), 80 | UserPasswordUpdateRsp(0x0304006d, FtdcType.RSP), 81 | /** 82 | * 用户资金密码更新请求 83 | */ 84 | FundPasswordUpdateReq(0x2460006e, FtdcType.REQ), 85 | FundPasswordUpdateRsp(0x2460006e, FtdcType.RSP), 86 | /** 87 | * 客户端认证 88 | */ 89 | Auth(0x101200ab, FtdcType.RSP); 90 | 91 | private static final int UMASK = 0xffff0000; 92 | 93 | private int id; 94 | private FtdcType type; 95 | private TID(int id, FtdcType type) { 96 | this.id = id; 97 | this.type = type; 98 | } 99 | 100 | public int id() { 101 | return id; 102 | } 103 | 104 | public int validId() { 105 | return id & UMASK; 106 | } 107 | 108 | /** 109 | * 110 | * @param id 111 | * @return 112 | */ 113 | public static TID parseFrom(long id, FtdcType type) { 114 | int validId = (int)(id & UMASK); 115 | TID retTID = TID.UNUSE; 116 | TID[] tids = TID.values(); 117 | for (TID tid: tids) { 118 | if (tid.type != type) { 119 | continue; 120 | } 121 | if(tid.validId() == validId) { 122 | retTID = tid; 123 | break; 124 | } 125 | } 126 | return retTID; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcActionFlagType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午6:25:59 6 | * 7 | */ 8 | public enum FtdcActionFlagType { 9 | /** 10 | * 删除 11 | */ 12 | THOST_FTDCAF_Delete("0"), 13 | /** 14 | * 修改 15 | */ 16 | THOST_FTDCAF_Modify("3"); 17 | 18 | private String type; 19 | private FtdcActionFlagType(String type) { 20 | this.type = type; 21 | } 22 | 23 | public String type() { 24 | return this.type; 25 | } 26 | 27 | public static FtdcActionFlagType parseFrom(String type) { 28 | FtdcActionFlagType retType = null; 29 | for (FtdcActionFlagType t : FtdcActionFlagType.values()) { 30 | if(t.type.equals(type)) { 31 | retType = t; 32 | break; 33 | } 34 | } 35 | return retType; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcAvailabilityFlagType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:34:39 6 | * 7 | */ 8 | public enum FtdcAvailabilityFlagType { 9 | /** 10 | * 未确认 11 | */ 12 | THOST_FTDC_Invalid("0"), 13 | /** 14 | * 有效 15 | */ 16 | THOST_FTDC_Valid("1"), 17 | /** 18 | * 冲正 19 | */ 20 | THOST_FTDC_Repeal("2"); 21 | 22 | private String type; 23 | private FtdcAvailabilityFlagType(String type) { 24 | this.type = type; 25 | } 26 | 27 | public String type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdcAvailabilityFlagType parseFrom(String type) { 32 | FtdcAvailabilityFlagType retType = null; 33 | for (FtdcAvailabilityFlagType t : FtdcAvailabilityFlagType.values()) { 34 | if(t.type.equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcBankAccType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:34:51 6 | * 7 | */ 8 | public enum FtdcBankAccType { 9 | /** 10 | * 银行存折 11 | */ 12 | THOST_FTDCBAT_BankBook("1"), 13 | /** 14 | * 储蓄卡 15 | */ 16 | THOST_FTDCBAT_SavingCard("2"), 17 | /** 18 | * 信用卡 19 | */ 20 | THOST_FTDCBAT_CreditCard("3"); 21 | 22 | private String type; 23 | private FtdcBankAccType(String type) { 24 | this.type = type; 25 | } 26 | 27 | /** 28 | * @return the type 29 | */ 30 | public String type() { 31 | return type; 32 | } 33 | 34 | public static FtdcBankAccType parseFrom(String type) { 35 | FtdcBankAccType retType = null; 36 | for (FtdcBankAccType t : FtdcBankAccType.values()) { 37 | if(t.type.equals(type)) { 38 | retType = t; 39 | break; 40 | } 41 | } 42 | return retType; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcBillHedgeFlag.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:35:38 6 | * 7 | */ 8 | public enum FtdcBillHedgeFlag { 9 | /** 10 | * 投机 11 | */ 12 | FTDC_Speculation("1"), 13 | /** 14 | * 套利 15 | */ 16 | FTDC_Arbitrage("2"), 17 | /** 18 | * 套保 19 | */ 20 | FTDC_Hedge("3"); 21 | 22 | private String flag; 23 | 24 | private FtdcBillHedgeFlag(String flag) { 25 | this.flag = flag; 26 | } 27 | 28 | public String getFlag() { 29 | return flag; 30 | } 31 | 32 | public static FtdcBillHedgeFlag parseFrom(String flag) { 33 | FtdcBillHedgeFlag retFlag = null; 34 | switch(flag) { 35 | case "1": 36 | retFlag = FTDC_Speculation; 37 | break; 38 | case "2": 39 | retFlag = FTDC_Arbitrage; 40 | break; 41 | case "3": 42 | retFlag = FtdcBillHedgeFlag.FTDC_Hedge; 43 | break; 44 | default: 45 | break; 46 | } 47 | return retFlag; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcCombinationType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 组合类型类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcCombinationType { 11 | /** 12 | * 期货组合 13 | */ 14 | THOST_FTDC_COMBT_Future("0"), 15 | /** 16 | * 垂直价差BUL 17 | */ 18 | THOST_FTDC_COMBT_BUL("1"), 19 | /** 20 | * 垂直价差BER 21 | */ 22 | THOST_FTDC_COMBT_BER("2"), 23 | /** 24 | * 跨式组合 25 | */ 26 | THOST_FTDC_COMBT_STD("3"), 27 | /** 28 | * 宽跨式组合 29 | */ 30 | THOST_FTDC_COMBT_STG("4"), 31 | /** 32 | * 备兑组合 33 | */ 34 | THOST_FTDC_COMBT_PRT("5"), 35 | /** 36 | * 时间价差组合 37 | */ 38 | THOST_FTDC_COMBT_CLD("6"); 39 | 40 | private String type; 41 | private FtdcCombinationType(String type) { 42 | this.type = type; 43 | } 44 | 45 | public String type() { 46 | return this.type; 47 | } 48 | 49 | public static FtdcCombinationType parseFrom(String type) { 50 | FtdcCombinationType retType = null; 51 | for (FtdcCombinationType t : FtdcCombinationType.values()) { 52 | if(t.type.equals(type)) { 53 | retType = t; 54 | break; 55 | } 56 | } 57 | return retType; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcContingentCondition.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午7:38:23 6 | * 7 | */ 8 | public enum FtdcContingentCondition { 9 | 10 | /** 11 | * 立即 12 | */ 13 | FTDC_Immediately("1"), 14 | /** 15 | * 止损 16 | */ 17 | FTDC_Touch("2"), 18 | /** 19 | * 止赢 20 | */ 21 | FTDC_TouchProfit("3"), 22 | /** 23 | * 预埋单 24 | */ 25 | FTDC_ParkedOrder("4"), 26 | /** 27 | * 最新价大于条件价 28 | */ 29 | FTDC_LastPriceGreaterThanStopPrice("5"), 30 | /** 31 | * 最新价大于等于条件价 32 | */ 33 | FTDC_LastPriceGreaterEqualStopPrice("6"), 34 | /** 35 | * 最新价小于条件价 36 | */ 37 | FTDC_LastPriceLesserThanStopPrice("7"), 38 | /** 39 | * 最新价小于等于条件价 40 | */ 41 | FTDC_LastPriceLesserEqualStopPrice("8"), 42 | /** 43 | * 卖一价大于条件价 44 | */ 45 | FTDC_AskPriceGreaterThanStopPrice("9"), 46 | /** 47 | * 卖一价大于等于条件价 48 | */ 49 | FTDC_AskPriceGreaterEqualStopPrice("A"), 50 | /** 51 | * 卖一价小于条件价 52 | */ 53 | FTDC_AskPriceLesserThanStopPrice("B"), 54 | /** 55 | * 卖一价小于等于条件价 56 | */ 57 | FTDC_AskPriceLesserEqualStopPrice("C"), 58 | /** 59 | * 买一价大于条件价 60 | */ 61 | FTDC_BidPriceGreaterThanStopPrice("D"), 62 | /** 63 | * 买一价大于等于条件价 64 | */ 65 | FTDC_BidPriceGreaterEqualStopPrice("E"), 66 | /** 67 | * 买一价小于条件价 68 | */ 69 | FTDC_BidPriceLesserThanStopPrice("F"), 70 | /** 71 | * 买一价小于等于条件价 72 | */ 73 | FTDC_BidPriceLesserEqualStopPrice("H"); 74 | 75 | private String contingent; 76 | 77 | private FtdcContingentCondition(String contingent) { 78 | this.contingent = contingent; 79 | } 80 | 81 | public String getContingent() { 82 | return contingent; 83 | } 84 | 85 | public static FtdcContingentCondition parseFrom(String flag) { 86 | FtdcContingentCondition retFlag = null; 87 | switch(flag) { 88 | case "1": 89 | retFlag = FTDC_Immediately; 90 | break; 91 | case "2": 92 | retFlag = FTDC_Touch; 93 | break; 94 | case "3": 95 | retFlag = FTDC_TouchProfit; 96 | break; 97 | case "4": 98 | retFlag = FTDC_ParkedOrder; 99 | break; 100 | case "5": 101 | retFlag = FTDC_LastPriceGreaterThanStopPrice; 102 | break; 103 | case "6": 104 | retFlag = FTDC_LastPriceGreaterEqualStopPrice; 105 | break; 106 | case "7": 107 | retFlag = FTDC_LastPriceLesserThanStopPrice; 108 | break; 109 | case "8": 110 | retFlag = FTDC_LastPriceLesserEqualStopPrice; 111 | break; 112 | case "9": 113 | retFlag = FTDC_AskPriceGreaterThanStopPrice; 114 | break; 115 | case "A": 116 | retFlag = FTDC_AskPriceGreaterEqualStopPrice; 117 | break; 118 | case "B": 119 | retFlag = FTDC_AskPriceLesserThanStopPrice; 120 | break; 121 | case "C": 122 | retFlag = FTDC_AskPriceLesserEqualStopPrice; 123 | break; 124 | case "D": 125 | retFlag = FTDC_BidPriceGreaterThanStopPrice; 126 | break; 127 | case "E": 128 | retFlag = FTDC_BidPriceGreaterEqualStopPrice; 129 | break; 130 | case "F": 131 | retFlag = FTDC_BidPriceLesserThanStopPrice; 132 | break; 133 | case "H": 134 | retFlag = FTDC_BidPriceLesserEqualStopPrice; 135 | break; 136 | default: 137 | break; 138 | } 139 | return retFlag; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcCurrencyID.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | /** 5 | * 6 | * @author ee 7 | * 2017年10月17日 下午7:38:43 8 | * 9 | */ 10 | public enum FtdcCurrencyID { 11 | /** 12 | * 人民币 13 | */ 14 | CNY("CNY"); 15 | 16 | private String id; 17 | 18 | private FtdcCurrencyID(String id) { 19 | this.id = id; 20 | } 21 | 22 | public int getId() { 23 | byte[] idBytes = id.getBytes(); 24 | int retId = 0; 25 | for (int i = 0; i < idBytes.length; i++) { 26 | retId += (int)idBytes[i] << ((3 - i) * 8); 27 | } 28 | return retId; 29 | } 30 | 31 | public String id() { 32 | return this.id; 33 | } 34 | 35 | public static FtdcCurrencyID parseFrom(String id) { 36 | FtdcCurrencyID currencyId = null; 37 | switch(id) { 38 | case "CNY": 39 | currencyId = CNY; 40 | break; 41 | default: 42 | currencyId = CNY; 43 | break; 44 | } 45 | return currencyId; 46 | } 47 | 48 | public static FtdcCurrencyID parseFrom(int id) { 49 | FtdcCurrencyID currencyId = null; 50 | byte[] bs = new byte[Integer.SIZE / 8]; 51 | for(int i = 0; i < bs.length; i++) { 52 | bs[i] = (byte)(id >> ((3 - i) * 8)); 53 | } 54 | String str = StringUtils.trimToEmpty(new String(bs)); 55 | switch(str) { 56 | case "CNY": 57 | currencyId = CNY; 58 | break; 59 | default: 60 | currencyId = CNY; 61 | break; 62 | } 63 | return currencyId; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcCustType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午7:38:59 6 | * 7 | */ 8 | public enum FtdcCustType { 9 | /** 10 | * 自然人 11 | */ 12 | THOST_FTDC_CUSTT_Person("0"), 13 | /** 14 | * 机构户 15 | */ 16 | THOST_FTDC_CUSTT_Institution("1"); 17 | 18 | private String type; 19 | private FtdcCustType(String type) { 20 | this.type = type; 21 | } 22 | 23 | /** 24 | * @return the type 25 | */ 26 | public String type() { 27 | return type; 28 | } 29 | 30 | public static FtdcCustType parseFrom(String type) { 31 | FtdcCustType retType = null; 32 | for (FtdcCustType t : FtdcCustType.values()) { 33 | if(t.type.equals(type)) { 34 | retType = t; 35 | break; 36 | } 37 | } 38 | return retType; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcDirection.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:39:31 6 | * 7 | */ 8 | public enum FtdcDirection { 9 | /** 10 | * 买 11 | */ 12 | BUY("0"), 13 | /** 14 | * 卖 15 | */ 16 | SELL("1"); 17 | 18 | private String direction; 19 | 20 | private FtdcDirection(String direction) { 21 | this.direction = direction; 22 | } 23 | public String getDirection() { 24 | return direction; 25 | } 26 | 27 | public static FtdcDirection parseFrom(String direction) { 28 | FtdcDirection retDirection = null; 29 | switch(direction) { 30 | case "0": 31 | retDirection = FtdcDirection.BUY; 32 | break; 33 | case "1": 34 | retDirection = FtdcDirection.SELL; 35 | break; 36 | default: 37 | break; 38 | } 39 | return retDirection; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcExchange.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午7:39:45 6 | * 7 | */ 8 | public enum FtdcExchange { 9 | /** 10 | * 上海期货交易所 11 | */ 12 | FTDC_SHFE("SHFE"), 13 | /** 14 | * 郑州商品交易所 15 | */ 16 | FTDC_CZCE("CZCE"), 17 | /** 18 | * 大连商品交易所 19 | */ 20 | FTDC_DCE("DCE"), 21 | /** 22 | * 中国金融期货交易所 23 | */ 24 | FTDC_CFFEX("CFFEX"); 25 | 26 | private String exchange; 27 | 28 | private FtdcExchange(String exchange) { 29 | this.exchange = exchange; 30 | } 31 | 32 | public String getExchange() { 33 | return exchange; 34 | } 35 | 36 | public static FtdcExchange parseFrom(String flag) { 37 | FtdcExchange retFlag = null; 38 | switch(flag) { 39 | case "SHFE": 40 | retFlag = FTDC_SHFE; 41 | break; 42 | case "CZCE": 43 | retFlag = FTDC_CZCE; 44 | break; 45 | case "DCE": 46 | retFlag = FTDC_DCE; 47 | break; 48 | case "CFFEX": 49 | retFlag = FTDC_CFFEX; 50 | break; 51 | default: 52 | break; 53 | } 54 | return retFlag; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcFeePayFlagType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:40:52 6 | * 7 | */ 8 | public enum FtdcFeePayFlagType { 9 | /** 10 | * 由受益方支付费用 11 | */ 12 | THOST_FTDC_FPF_BEN("0"), 13 | /** 14 | * 由发送方支付费用 15 | */ 16 | THOST_FTDC_FPF_OUR("1"), 17 | /** 18 | * 由发送方支付发起的费用,受益方支付接受的费用 19 | */ 20 | THOST_FTDC_FPF_SHA("2"); 21 | 22 | private String type; 23 | private FtdcFeePayFlagType(String type) { 24 | this.type = type; 25 | } 26 | 27 | /** 28 | * @return the type 29 | */ 30 | public String type() { 31 | return type; 32 | } 33 | 34 | public static FtdcFeePayFlagType parseFrom(String type) { 35 | FtdcFeePayFlagType retType = null; 36 | for (FtdcFeePayFlagType t : FtdcFeePayFlagType.values()) { 37 | if(t.type.equals(type)) { 38 | retType = t; 39 | break; 40 | } 41 | } 42 | return retType; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcForceCLoseReson.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:41:04 6 | * 7 | */ 8 | public enum FtdcForceCLoseReson { 9 | /** 10 | * 非强平 11 | */ 12 | THOST_FTDCFCC_NotForceClose("0"), 13 | /** 14 | * 资金不足 15 | */ 16 | THOST_FTDCFCC_LackDeposit("1"), 17 | /** 18 | * 客户超仓 19 | */ 20 | THOST_FTDCFCC_ClientOverPositionLimit("2"), 21 | /** 22 | * 会员超仓 23 | */ 24 | THOST_FTDCFCC_MemberOverPositionLimit("3"), 25 | /** 26 | * 持仓非整数倍 27 | */ 28 | THOST_FTDCFCC_NotMultiple("4"), 29 | /** 30 | * 违规 31 | */ 32 | THOST_FTDCFCC_Violation("5"), 33 | /** 34 | * 其它 35 | */ 36 | THOST_FTDCFCC_Other("6"), 37 | /** 38 | * 自然人临近交割 39 | */ 40 | THOST_FTDCFCC_PersonDeliv("7"); 41 | 42 | private String type; 43 | private FtdcForceCLoseReson(String type) { 44 | this.type = type; 45 | } 46 | 47 | public String type() { 48 | return this.type; 49 | } 50 | 51 | public static FtdcForceCLoseReson parseFrom(String reson) { 52 | FtdcForceCLoseReson retReason = null; 53 | switch(reson) { 54 | case "0": 55 | retReason = THOST_FTDCFCC_NotForceClose; 56 | break; 57 | case "1": 58 | retReason = THOST_FTDCFCC_LackDeposit; 59 | break; 60 | case "2": 61 | retReason = THOST_FTDCFCC_ClientOverPositionLimit; 62 | break; 63 | case "3": 64 | retReason = THOST_FTDCFCC_MemberOverPositionLimit; 65 | break; 66 | case "4": 67 | retReason = THOST_FTDCFCC_NotMultiple; 68 | break; 69 | case "5": 70 | retReason = THOST_FTDCFCC_Violation; 71 | break; 72 | case "6": 73 | retReason = THOST_FTDCFCC_Other; 74 | break; 75 | case "7": 76 | retReason = THOST_FTDCFCC_PersonDeliv; 77 | break; 78 | default: 79 | break; 80 | } 81 | return retReason; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcFutureAccType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:44:02 6 | * 7 | */ 8 | public enum FtdcFutureAccType { 9 | /** 10 | * 银行存折 11 | */ 12 | THOST_FTDC_BankBook("1"), 13 | /** 14 | * 储蓄卡 15 | */ 16 | THOST_FTDC_SavingCard("2"), 17 | /** 18 | * 信用卡 19 | */ 20 | THOST_FTDC_CreditCard("3"); 21 | 22 | private String type; 23 | private FtdcFutureAccType(String type) { 24 | this.type = type; 25 | } 26 | 27 | public String type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdcFutureAccType parseFrom(String type) { 32 | FtdcFutureAccType retType = null; 33 | for (FtdcFutureAccType t : FtdcFutureAccType.values()) { 34 | if(t.type.equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcIdCardType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午7:44:55 6 | * 7 | */ 8 | public enum FtdcIdCardType { 9 | /** 10 | * 组织机构代码 11 | */ 12 | THOST_FTDCICT_EID("0"), 13 | /** 14 | * 中国公民身份证 15 | */ 16 | THOST_FTDCICT_IDCard("1"), 17 | /** 18 | * 军官证 19 | */ 20 | THOST_FTDCICT_OfficerIDCard("2"), 21 | /** 22 | * 警官证 23 | */ 24 | THOST_FTDCICT_PoliceIDCard("3"), 25 | /** 26 | * 士兵证 27 | */ 28 | THOST_FTDCICT_SoldierIDCard("4"), 29 | /** 30 | * 户口簿 31 | */ 32 | THOST_FTDCICT_HouseholdRegister("5"), 33 | /** 34 | * 护照 35 | */ 36 | THOST_FTDCICT_Passport("6"), 37 | /** 38 | * 台胞证 39 | */ 40 | THOST_FTDCICT_TaiwanCompatriotIDCard("7"), 41 | /** 42 | * 回乡证 43 | */ 44 | THOST_FTDCICT_HomeComingCard("8"), 45 | /** 46 | * 营业执照号 47 | */ 48 | THOST_FTDCICT_LicenseNo("9"), 49 | /** 50 | * 税务登记号/当地纳税ID 51 | */ 52 | THOST_FTDCICT_TaxNo("A"), 53 | /** 54 | * 港澳居民来往内地通行证 55 | */ 56 | THOST_FTDCICT_HMMainlandTravelPermit ("B"), 57 | /** 58 | * 台湾居民来往大陆通行证 59 | */ 60 | THOST_FTDCICT_TwMainlandTravelPermit("C"), 61 | /** 62 | * 驾照 63 | */ 64 | THOST_FTDCICT_DrivingLicense("D"), 65 | /** 66 | * 当地社保ID 67 | */ 68 | THOST_FTDCICT_SocialID("F"), 69 | /** 70 | * 当地身份证 71 | */ 72 | THOST_FTDCICT_LocalID("G"), 73 | /** 74 | * 商业登记证 75 | */ 76 | THOST_FTDCICT_BusinessRegistration ("H"), 77 | /** 78 | * 港澳永久性居民身份证 79 | */ 80 | THOST_FTDCICT_HKMCIDCard("I"), 81 | /** 82 | * 人行开户许可证 83 | */ 84 | THOST_FTDCICT_AccountsPermits("J"), 85 | /** 86 | * 其他证件 87 | */ 88 | THOST_FTDCICT_OtherCard("x"); 89 | 90 | private String type; 91 | private FtdcIdCardType(String type) { 92 | this.type = type; 93 | } 94 | 95 | 96 | /** 97 | * @return the type 98 | */ 99 | public String type() { 100 | return type; 101 | } 102 | 103 | 104 | public static FtdcIdCardType parseFrom(String type) { 105 | FtdcIdCardType retType = null; 106 | for (FtdcIdCardType t : FtdcIdCardType.values()) { 107 | if(t.type.equals(type)) { 108 | retType = t; 109 | break; 110 | } 111 | } 112 | return retType; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcInstLifePhaseType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 合约生命周期状态类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcInstLifePhaseType { 11 | /** 12 | * 未上市 13 | */ 14 | THOST_FTDC_IP_NotStart("0"), 15 | /** 16 | * 上市 17 | */ 18 | THOST_FTDC_IP_Started("1"), 19 | /** 20 | * 停牌 21 | */ 22 | THOST_FTDC_IP_Pause("2"), 23 | /** 24 | * 到期 25 | */ 26 | THOST_FTDC_IP_Expired("3"); 27 | 28 | private String type; 29 | private FtdcInstLifePhaseType(String type) { 30 | this.type = type; 31 | } 32 | 33 | public String type() { 34 | return this.type; 35 | } 36 | 37 | public static FtdcInstLifePhaseType parseFrom(String type) { 38 | FtdcInstLifePhaseType retType = null; 39 | for (FtdcInstLifePhaseType t : FtdcInstLifePhaseType.values()) { 40 | if(t.type.equals(type)) { 41 | retType = t; 42 | break; 43 | } 44 | } 45 | return retType; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcInvestorRangeType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:49:18 6 | * 7 | */ 8 | public enum FtdcInvestorRangeType { 9 | /** 10 | * 所有 11 | */ 12 | THOST_IR_All("1"), 13 | /** 14 | * 投资者组 15 | */ 16 | THOST_IR_Group("2"), 17 | /** 18 | * 单一投资者 19 | */ 20 | THOST_IR_Single("3"); 21 | 22 | private String type; 23 | private FtdcInvestorRangeType(String type) { 24 | this.type = type; 25 | } 26 | 27 | public String type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdcInvestorRangeType parseFrom(String type) { 32 | FtdcInvestorRangeType retType = null; 33 | for (FtdcInvestorRangeType t : FtdcInvestorRangeType.values()) { 34 | if(t.type.equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcLastFragmentType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author wyz 5 | * 2017年10月17日 下午7:49:27 6 | * 7 | */ 8 | public enum FtdcLastFragmentType { 9 | /** 10 | * 是最后分片 11 | */ 12 | THOST_FTDC_LF_Yes("0"), 13 | /** 14 | * 不是最后分片 15 | */ 16 | THOST_FTDC_LF_No("1"); 17 | 18 | private String type; 19 | private FtdcLastFragmentType(String type) { 20 | this.type = type; 21 | } 22 | 23 | /** 24 | * @return the type 25 | */ 26 | public String type() { 27 | return type; 28 | } 29 | 30 | 31 | public static FtdcLastFragmentType parseFrom(String type) { 32 | FtdcLastFragmentType retType = null; 33 | for (FtdcLastFragmentType t : FtdcLastFragmentType.values()) { 34 | if(t.type.equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcMaxMarginSideAlgorithmType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 大额单边保证金算法类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcMaxMarginSideAlgorithmType { 11 | /** 12 | * 不使用大额单边保证金算法 13 | */ 14 | THOST_FTDC_MMSA_NO("0"), 15 | /** 16 | * 使用大额单边保证金算法 17 | */ 18 | THOST_FTDC_MMSA_YES("1"); 19 | 20 | private String type; 21 | private FtdcMaxMarginSideAlgorithmType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public String type() { 26 | return this.type; 27 | } 28 | 29 | public static FtdcMaxMarginSideAlgorithmType parseFrom(String type) { 30 | FtdcMaxMarginSideAlgorithmType retType = null; 31 | for (FtdcMaxMarginSideAlgorithmType t : FtdcMaxMarginSideAlgorithmType.values()) { 32 | if(t.type.equals(type)) { 33 | retType = t; 34 | break; 35 | } 36 | } 37 | return retType; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOffsetFlagType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:50:37 6 | * 7 | */ 8 | public enum FtdcOffsetFlagType { 9 | /** 10 | * 开仓 11 | */ 12 | FTDC_Open("0"), 13 | /** 14 | * 平仓 15 | */ 16 | FTDC_Close("1"), 17 | /** 18 | * 强平 19 | */ 20 | FTDC_ForceClose("2"), 21 | /** 22 | * 平今 23 | */ 24 | FTDC_CloseToday("3"), 25 | /** 26 | * 平昨 27 | */ 28 | FTDC_CloseYesterday("4"), 29 | /** 30 | * 强减 31 | */ 32 | FTDC_ForceOff("5"), 33 | /** 34 | * 本地强平 35 | */ 36 | FTDC_LocalForceClose("6"); 37 | 38 | private String offset; 39 | 40 | private FtdcOffsetFlagType(String offset) { 41 | this.offset = offset; 42 | } 43 | 44 | public String getOffset() { 45 | return offset; 46 | } 47 | 48 | public static FtdcOffsetFlagType parseFrom(String flag) { 49 | FtdcOffsetFlagType retFlag = null; 50 | switch(flag) { 51 | case "0": 52 | retFlag = FTDC_Open; 53 | break; 54 | case "1": 55 | retFlag = FTDC_Close; 56 | break; 57 | case "2": 58 | retFlag = FTDC_ForceClose; 59 | break; 60 | case "3": 61 | retFlag = FTDC_CloseToday; 62 | break; 63 | case "4": 64 | retFlag = FTDC_CloseYesterday; 65 | break; 66 | case "5": 67 | retFlag = FTDC_ForceOff; 68 | break; 69 | case "6": 70 | retFlag = FTDC_LocalForceClose; 71 | break; 72 | default: 73 | break; 74 | } 75 | return retFlag; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOpenOrDestroyType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:50:45 6 | * 7 | */ 8 | public enum FtdcOpenOrDestroyType { 9 | /** 10 | * 开户 11 | */ 12 | THOST_FTDC_OOD_Destroy("0"), 13 | /** 14 | * 销户 15 | */ 16 | THOST_FTDC_OOD_Open("1"); 17 | 18 | private String type; 19 | private FtdcOpenOrDestroyType(String type) { 20 | this.type = type; 21 | } 22 | 23 | public String type() { 24 | return this.type; 25 | } 26 | 27 | public static FtdcOpenOrDestroyType parseFrom(String type) { 28 | FtdcOpenOrDestroyType retType = null; 29 | for (FtdcOpenOrDestroyType t : FtdcOpenOrDestroyType.values()) { 30 | if(t.type.equals(type)) { 31 | retType = t; 32 | break; 33 | } 34 | } 35 | return retType; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOptionsType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 期权类型类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcOptionsType { 11 | /** 12 | * 看涨 13 | */ 14 | THOST_FTDC_CP_CallOptions("1"), 15 | /** 16 | * 看跌 17 | */ 18 | THOST_FTDC_CP_PutOptions("2"); 19 | 20 | private String type; 21 | private FtdcOptionsType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public String type() { 26 | return this.type; 27 | } 28 | 29 | public static FtdcOptionsType parseFrom(String type) { 30 | FtdcOptionsType retType = null; 31 | for (FtdcOptionsType t : FtdcOptionsType.values()) { 32 | if(t.type.equals(type)) { 33 | retType = t; 34 | break; 35 | } 36 | } 37 | return retType; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOrderPriceType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午7:51:58 6 | * 7 | */ 8 | public enum FtdcOrderPriceType { 9 | 10 | /** 11 | * 任意价 12 | */ 13 | FTDC_AnyPrice("1"), 14 | /** 15 | * 限价 16 | */ 17 | FTDC_LimitPrice("2"), 18 | /** 19 | * 最优价 20 | */ 21 | FTDC_BestPrice("3"), 22 | /** 23 | * 最新价 24 | */ 25 | FTDC_LastPrice("4"), 26 | /** 27 | * 最新价浮动上浮1个ticks 28 | */ 29 | FTDC_LastPricePlusOneTicks("5"), 30 | /** 31 | * 最新价浮动上浮2个ticks 32 | */ 33 | FTDC_LastPricePlusTwoTicks("6"), 34 | /** 35 | * 最新价浮动上浮3个ticks 36 | */ 37 | FTDC_LastPricePlusThreeTicks("7"), 38 | /** 39 | * 卖一价 40 | */ 41 | FTDC_AskPrice1("8"), 42 | /** 43 | * 卖一价浮动上浮1个ticks 44 | */ 45 | FTDC_AskPrice1PlusOneTicks("9"), 46 | /** 47 | * 卖一价浮动上浮2个ticks 48 | */ 49 | FTDC_AskPrice1PlusTwoTicks("A"), 50 | /** 51 | * 卖一价浮动上浮3个ticks 52 | */ 53 | FTDC_AskPrice1PlusThreeTicks("B"), 54 | /** 55 | * 买一价 56 | */ 57 | FTDC_BidPrice1("C"), 58 | /** 59 | * 买一价浮动上浮1个ticks 60 | */ 61 | FTDC_BidPrice1PlusOneTicks("D"), 62 | /** 63 | * 买一价浮动上浮2个ticks 64 | */ 65 | FTDC_BidPrice1PlusTwoTicks("E"), 66 | /** 67 | * 买一价浮动上浮3个ticks 68 | */ 69 | FTDC_BidPrice1PlusThreeTicks("F"); 70 | 71 | private String type; 72 | 73 | private FtdcOrderPriceType(String type) { 74 | this.type = type; 75 | } 76 | 77 | public String getType() { 78 | return type; 79 | } 80 | 81 | public static FtdcOrderPriceType parseFrom(String type) { 82 | FtdcOrderPriceType retType = null; 83 | switch(type) { 84 | case "1": 85 | retType = FTDC_AnyPrice; 86 | break; 87 | case "2": 88 | retType = FTDC_LimitPrice; 89 | break; 90 | case "3": 91 | retType = FTDC_BestPrice; 92 | break; 93 | case "4": 94 | retType = FTDC_LastPrice; 95 | break; 96 | case "5": 97 | retType = FTDC_LastPricePlusOneTicks; 98 | break; 99 | case "6": 100 | retType = FTDC_LastPricePlusTwoTicks; 101 | break; 102 | case "7": 103 | retType = FTDC_LastPricePlusThreeTicks; 104 | break; 105 | case "8": 106 | retType = FTDC_AskPrice1; 107 | break; 108 | case "9": 109 | retType = FTDC_AskPrice1PlusOneTicks; 110 | break; 111 | case "A": 112 | retType = FTDC_AskPrice1PlusTwoTicks; 113 | break; 114 | case "B": 115 | retType = FTDC_AskPrice1PlusThreeTicks; 116 | break; 117 | case "C": 118 | retType = FTDC_BidPrice1; 119 | break; 120 | case "D": 121 | retType = FTDC_BidPrice1PlusOneTicks; 122 | break; 123 | case "E": 124 | retType = FTDC_BidPrice1PlusTwoTicks; 125 | break; 126 | case "F": 127 | retType = FTDC_BidPrice1PlusThreeTicks; 128 | break; 129 | default: 130 | break; 131 | } 132 | return retType; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOrderSourceType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:52:22 6 | * 7 | */ 8 | public enum FtdcOrderSourceType { 9 | /** 10 | * 来自参与者 11 | */ 12 | THOST_FTDCOSRC_Participant("0"), 13 | /** 14 | * 来自管理员 15 | */ 16 | THOST_FTDCOSRC_Administrator("1"); 17 | 18 | private String source; 19 | private FtdcOrderSourceType(String source) { 20 | this.source = source; 21 | } 22 | 23 | public String source() { 24 | return this.source; 25 | } 26 | 27 | public static FtdcOrderSourceType parseFrom(String source) { 28 | FtdcOrderSourceType retSource = null; 29 | switch(source) { 30 | case "0": 31 | retSource = THOST_FTDCOSRC_Participant; 32 | break; 33 | case "1": 34 | retSource = THOST_FTDCOSRC_Administrator; 35 | break; 36 | default: 37 | break; 38 | } 39 | return retSource; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOrderStatusType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:55:50 6 | * 7 | */ 8 | public enum FtdcOrderStatusType { 9 | /** 10 | * 全部成交 11 | */ 12 | THOST_FTDCOST_AllTraded("0"), 13 | /** 14 | * 部分成交还在队列中 15 | */ 16 | THOST_FTDCOST_PartTradedQueueing("1"), 17 | /** 18 | * 部分成交不在队列中 19 | */ 20 | THOST_FTDCOST_PartTradedNotQueueing("2"), 21 | /** 22 | * 未成交还在队列中 23 | */ 24 | THOST_FTDCOST_NoTradeQueueing("3"), 25 | /** 26 | * 未成交不在队列中 27 | */ 28 | THOST_FTDCOST_NoTradeNotQueueing("4"), 29 | /** 30 | * 撤单 31 | */ 32 | THOST_FTDCOST_Canceled("5"), 33 | /** 34 | * 未知 35 | */ 36 | THOST_FTDCOST_Unknown("a"), 37 | /** 38 | * 尚未触发 39 | */ 40 | THOST_FTDCOST_NotTouched("b"), 41 | /** 42 | * 已触发 43 | */ 44 | THOST_FTDCOST_Touched("c"); 45 | 46 | private String status; 47 | private FtdcOrderStatusType(String status) { 48 | this.status = status; 49 | } 50 | 51 | public String status() { 52 | return this.status; 53 | } 54 | 55 | public static FtdcOrderStatusType parseFrom(String status) { 56 | FtdcOrderStatusType retStatus = null; 57 | switch (status) { 58 | case "0": 59 | retStatus = THOST_FTDCOST_AllTraded; 60 | break; 61 | case "1": 62 | retStatus = THOST_FTDCOST_PartTradedQueueing; 63 | break; 64 | case "2": 65 | retStatus = THOST_FTDCOST_PartTradedNotQueueing; 66 | break; 67 | case "3": 68 | retStatus = THOST_FTDCOST_NoTradeQueueing; 69 | break; 70 | case "4": 71 | retStatus = THOST_FTDCOST_NoTradeNotQueueing; 72 | break; 73 | case "5": 74 | retStatus = THOST_FTDCOST_Canceled; 75 | break; 76 | case "a": 77 | retStatus = THOST_FTDCOST_Unknown; 78 | break; 79 | case "b": 80 | retStatus = THOST_FTDCOST_NotTouched; 81 | break; 82 | case "c": 83 | retStatus = THOST_FTDCOST_Touched; 84 | break; 85 | default: 86 | break; 87 | } 88 | return retStatus; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOrderSubmitStatusType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:56:08 6 | * 7 | */ 8 | public enum FtdcOrderSubmitStatusType { 9 | /** 10 | * 已经提交 11 | */ 12 | THOST_FTDCOSS_InsertSubmitted("0"), 13 | /** 14 | * 撤单已经提交 15 | */ 16 | THOST_FTDCOSS_CancelSubmitted("1"), 17 | /** 18 | * 修改已经提交 19 | */ 20 | THOST_FTDCOSS_ModifySubmitted("2"), 21 | /** 22 | * 已经接受 23 | */ 24 | THOST_FTDCOSS_Accepted("3"), 25 | /** 26 | * 报单已经被拒绝 27 | */ 28 | THOST_FTDCOSS_InsertRejected("4"), 29 | /** 30 | * 撤单已经倍决绝 31 | */ 32 | THOST_FTDCOSS_CancelRejected("5"), 33 | /** 34 | * 改单已经被拒绝 35 | */ 36 | THOST_FTDCOSS_ModifyRejected("6"); 37 | 38 | private String status; 39 | private FtdcOrderSubmitStatusType(String status) { 40 | this.status = status; 41 | } 42 | 43 | public String status() { 44 | return this.status; 45 | } 46 | 47 | public static FtdcOrderSubmitStatusType parseFrom(String status) { 48 | FtdcOrderSubmitStatusType retStatus = null; 49 | switch (status) { 50 | case "0": 51 | retStatus = THOST_FTDCOSS_InsertSubmitted; 52 | break; 53 | case "1": 54 | retStatus = THOST_FTDCOSS_CancelSubmitted; 55 | break; 56 | case "2": 57 | retStatus = THOST_FTDCOSS_ModifySubmitted; 58 | break; 59 | case "3": 60 | retStatus = THOST_FTDCOSS_Accepted; 61 | break; 62 | case "4": 63 | retStatus = THOST_FTDCOSS_InsertRejected; 64 | break; 65 | case "5": 66 | retStatus = THOST_FTDCOSS_CancelRejected; 67 | break; 68 | case "6": 69 | retStatus = THOST_FTDCOSS_ModifyRejected; 70 | break; 71 | default: 72 | break; 73 | } 74 | return retStatus; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcOrderType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午7:59:37 6 | * 7 | */ 8 | public enum FtdcOrderType { 9 | /** 10 | * 正常 11 | */ 12 | THOST_FTDCORDT_Normal("0"), 13 | /** 14 | * 报价衍生 15 | */ 16 | THOST_FTDCORDT_DeriveFromQuote("1"), 17 | /** 18 | * 组合衍生 19 | */ 20 | THOST_FTDCORDT_DeriveFromCombination("2"), 21 | /** 22 | * 组合报单 23 | */ 24 | THOST_FTDCORDT_Combination("3"), 25 | /** 26 | * 条件单 27 | */ 28 | THOST_FTDCORDT_ConditionalOrder("4"), 29 | /** 30 | * 互换单 31 | */ 32 | THOST_FTDCORDT_Swap("5"); 33 | 34 | private String type; 35 | private FtdcOrderType(String type) { 36 | this.type = type; 37 | } 38 | 39 | public String type() { 40 | return this.type; 41 | } 42 | 43 | public static FtdcOrderType parseFrom(String type) { 44 | FtdcOrderType retType = null; 45 | switch (type) { 46 | case "0": 47 | retType = THOST_FTDCORDT_Normal; 48 | break; 49 | case "1": 50 | retType = THOST_FTDCORDT_DeriveFromQuote; 51 | break; 52 | case "2": 53 | retType = THOST_FTDCORDT_DeriveFromCombination; 54 | break; 55 | case "3": 56 | retType = THOST_FTDCORDT_Combination; 57 | break; 58 | case "4": 59 | retType = THOST_FTDCORDT_ConditionalOrder; 60 | break; 61 | case "5": 62 | retType = THOST_FTDCORDT_Swap; 63 | break; 64 | default: 65 | break; 66 | } 67 | return retType; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcPosiDirectionType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:00:27 6 | * 7 | */ 8 | public enum FtdcPosiDirectionType { 9 | /** 10 | * 净 11 | */ 12 | THOST_FTDCPD_Net("1"), 13 | /** 14 | * 多头 15 | */ 16 | THOST_FTDCPD_Long("2"), 17 | /** 18 | * 空头 19 | */ 20 | THOST_FTDCPD_Short("3"); 21 | 22 | private String direction; 23 | private FtdcPosiDirectionType(String direction) { 24 | this.direction = direction; 25 | } 26 | 27 | public String direction() { 28 | return this.direction; 29 | } 30 | 31 | public static FtdcPosiDirectionType parseFrom(String direction) { 32 | FtdcPosiDirectionType retDirection = null; 33 | for (FtdcPosiDirectionType type : FtdcPosiDirectionType.values()) { 34 | if(type.direction().equals(direction)) { 35 | retDirection = type; 36 | break; 37 | } 38 | } 39 | return retDirection; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcPositionDateType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:00:40 6 | * 7 | */ 8 | public enum FtdcPositionDateType { 9 | /** 10 | * 今日持仓 11 | */ 12 | THOST_FTDCPSD_Today("1"), 13 | /** 14 | * 历史持仓 15 | */ 16 | THOST_FTDCPSD_History("2"); 17 | 18 | private String type; 19 | private FtdcPositionDateType(String type) { 20 | this.type = type; 21 | } 22 | 23 | public String type() { 24 | return this.type; 25 | } 26 | 27 | public static FtdcPositionDateType parseFrom(String direction) { 28 | FtdcPositionDateType retType = null; 29 | for (FtdcPositionDateType type : FtdcPositionDateType.values()) { 30 | if(type.type().equals(direction)) { 31 | retType = type; 32 | break; 33 | } 34 | } 35 | return retType; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcPositionType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 持仓类型类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcPositionType { 11 | /** 12 | * 净持仓 13 | */ 14 | THOST_FTDC_PT_Net("1"), 15 | /** 16 | * 综合持仓 17 | */ 18 | THOST_FTDC_PT_Gross("2"); 19 | 20 | private String type; 21 | private FtdcPositionType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public String type() { 26 | return this.type; 27 | } 28 | 29 | public static FtdcPositionType parseFrom(String type) { 30 | FtdcPositionType retType = null; 31 | for (FtdcPositionType t : FtdcPositionType.values()) { 32 | if(t.type.equals(type)) { 33 | retType = t; 34 | break; 35 | } 36 | } 37 | return retType; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcPriceSourceType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:02:19 6 | * 7 | */ 8 | public enum FtdcPriceSourceType { 9 | /** 10 | * 前成交价 11 | */ 12 | THOST_FTDCPSRC_LastPrice("0"), 13 | /** 14 | * 买委托价 15 | */ 16 | THOST_FTDCPSRC_Buy("1"), 17 | /** 18 | * 卖委托价 19 | */ 20 | THOST_FTDCPSRC_Sell("2"); 21 | 22 | private String type; 23 | private FtdcPriceSourceType(String type) { 24 | this.type = type; 25 | } 26 | 27 | public String type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdcPriceSourceType parseFrom(String type) { 32 | FtdcPriceSourceType retType = null; 33 | for (FtdcPriceSourceType t : FtdcPriceSourceType.values()) { 34 | if(t.type.equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcProductClassType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 产品类型类型 5 | * @author zlj 6 | * @date 2017年10月13日 7 | * 8 | * @modifyBy zlj 2017年10月13日 9 | */ 10 | public enum FtdcProductClassType { 11 | /** 12 | * 期货 13 | */ 14 | THOST_FTDC_PC_Futures("1"), 15 | /** 16 | * 期货期权 17 | */ 18 | THOST_FTDC_PC_Options("2"), 19 | /** 20 | * 组合 21 | */ 22 | THOST_FTDC_PC_Combination("3"), 23 | /** 24 | * 即期 25 | */ 26 | THOST_FTDC_PC_Spot("4"), 27 | /** 28 | * 期转现 29 | */ 30 | THOST_FTDC_PC_EFP("5"), 31 | /** 32 | * 现货期权 33 | */ 34 | THOST_FTDC_PC_SpotOption("6"); 35 | 36 | private String type; 37 | private FtdcProductClassType(String type) { 38 | this.type = type; 39 | } 40 | 41 | public String type() { 42 | return this.type; 43 | } 44 | 45 | public static FtdcProductClassType parseFrom(String type) { 46 | FtdcProductClassType retType = null; 47 | for (FtdcProductClassType t : FtdcProductClassType.values()) { 48 | if(t.type.equals(type)) { 49 | retType = t; 50 | break; 51 | } 52 | } 53 | return retType; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcPwdFlag.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:04:48 6 | * 7 | */ 8 | public enum FtdcPwdFlag { 9 | /** 10 | * 不核对 11 | */ 12 | FTDC_NoCheck("0"), 13 | /** 14 | * 明文核对 15 | */ 16 | FTDC_BlankCheck("1"), 17 | /** 18 | * 密文核对 19 | */ 20 | FTDC_EncryptCheck("2"); 21 | 22 | private String flag; 23 | 24 | private FtdcPwdFlag(String flag) { 25 | this.flag = flag; 26 | } 27 | 28 | public String getFlag() { 29 | return flag; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTimeCondition.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午8:05:12 6 | * 7 | */ 8 | public enum FtdcTimeCondition { 9 | /** 10 | * 立即完成,否则撤销 11 | */ 12 | FTDC_IOC("1"), 13 | /** 14 | * 本节有效 15 | */ 16 | FTDC_GFS("2"), 17 | /** 18 | * 当日有效 19 | */ 20 | FTDC_GFD("3"), 21 | /** 22 | * 指定日期前有效 23 | */ 24 | FTDC_GTD("4"), 25 | /** 26 | * 撤销前有效 27 | */ 28 | FTDC_GTC("5"), 29 | /** 30 | * 集合竞价有效 31 | */ 32 | FTDC_GFA("6"); 33 | 34 | private String codition; 35 | 36 | private FtdcTimeCondition(String codition) { 37 | this.codition = codition; 38 | } 39 | 40 | public String getCodition() { 41 | return codition; 42 | } 43 | 44 | public static FtdcTimeCondition parseFrom(String flag) { 45 | FtdcTimeCondition retFlag = null; 46 | switch(flag) { 47 | case "1": 48 | retFlag = FTDC_IOC; 49 | break; 50 | case "2": 51 | retFlag = FTDC_GFS; 52 | break; 53 | case "3": 54 | retFlag = FTDC_GFD; 55 | break; 56 | case "4": 57 | retFlag = FTDC_GTD; 58 | break; 59 | case "5": 60 | retFlag = FTDC_GTC; 61 | break; 62 | case "6": 63 | retFlag = FTDC_GFA; 64 | break; 65 | default: 66 | break; 67 | } 68 | return retFlag; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTradeCode.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:05:35 6 | * 7 | */ 8 | public enum FtdcTradeCode { 9 | /** 10 | * 银转期 11 | */ 12 | BankToFuture("202001"), 13 | /** 14 | * 期转银 15 | */ 16 | FutureToBank("202002"); 17 | 18 | private String code; 19 | 20 | private FtdcTradeCode(String code) { 21 | this.code = code; 22 | } 23 | 24 | public String getCode() { 25 | return code; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTradeSourceType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:06:37 6 | * 7 | */ 8 | public enum FtdcTradeSourceType { 9 | /** 10 | * 来自交易所普通回报 11 | */ 12 | THOST_FTDCTSRC_NORMAL("0"), 13 | /** 14 | * 来自查询 15 | */ 16 | THOST_FTDCTSRC_QUERY("1"); 17 | 18 | private String type; 19 | private FtdcTradeSourceType(String type) { 20 | this.type = type; 21 | } 22 | 23 | public static FtdcTradeSourceType parseFrom(String type) { 24 | FtdcTradeSourceType retType = null; 25 | for (FtdcTradeSourceType t : FtdcTradeSourceType.values()) { 26 | if(t.type.equals(type)) { 27 | retType = t; 28 | break; 29 | } 30 | } 31 | return retType; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTradeType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:07:17 6 | * 7 | */ 8 | public enum FtdcTradeType { 9 | /** 10 | * 组合持仓拆分为单一持仓,初始化不应包含该类型的持仓 11 | */ 12 | THOST_FTDCTRDT_SplitCombination("#"), 13 | /** 14 | * 普通成交 15 | */ 16 | THOST_FTDCTRDT_Common("0"), 17 | /** 18 | * 期权成交 19 | */ 20 | THOST_FTDCTRDT_OptionsExecution("1"), 21 | /** 22 | * OTC成交 23 | */ 24 | THOST_FTDCTRDT_OTC("2"), 25 | /** 26 | * 期转现衍生成交 27 | */ 28 | THOST_FTDCTRDT_EFPDerived("3"), 29 | /** 30 | * 组合衍生成交 31 | */ 32 | THOST_FTDCTRDT_CombinationDerived("4"); 33 | 34 | private String type; 35 | private FtdcTradeType(String type) { 36 | this.type = type; 37 | } 38 | 39 | 40 | public static FtdcTradeType parseFrom(String type) { 41 | FtdcTradeType retType = null; 42 | for (FtdcTradeType t : FtdcTradeType.values()) { 43 | if(t.type.equals(type)) { 44 | retType = t; 45 | break; 46 | } 47 | } 48 | return retType; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTradingRoleType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:08:38 6 | * 7 | */ 8 | public enum FtdcTradingRoleType { 9 | /** 10 | * 代理 11 | */ 12 | THOST_FTDCER_Broker("1"), 13 | /** 14 | * 自营 15 | */ 16 | THOST_FTDCER_Host("2"), 17 | /** 18 | * 做市商 19 | */ 20 | THOST_FTDCER_Maker("3"); 21 | 22 | private String type; 23 | private FtdcTradingRoleType(String type) { 24 | this.type = type; 25 | } 26 | 27 | public String type() { 28 | return this.type; 29 | } 30 | 31 | public static FtdcTradingRoleType parseFrom(String type) { 32 | FtdcTradingRoleType retType = null; 33 | for (FtdcTradingRoleType t : FtdcTradingRoleType.values()) { 34 | if(t.type().equals(type)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcTransferStatusType.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author lyb 5 | * 2017年10月17日 下午8:09:13 6 | * 7 | */ 8 | public enum FtdcTransferStatusType { 9 | /** 10 | * 正常 11 | */ 12 | THOST_FTDC_TRFS_Normal("0"), 13 | /** 14 | * 做冲正 15 | */ 16 | THOST_FTDC_TRFS_Repealed("1"); 17 | 18 | private String type; 19 | private FtdcTransferStatusType(String type) { 20 | this.type = type; 21 | } 22 | 23 | /** 24 | * @return the type 25 | */ 26 | public String type() { 27 | return type; 28 | } 29 | 30 | public static FtdcTransferStatusType parseFrom(String type) { 31 | FtdcTransferStatusType retType = null; 32 | for (FtdcTransferStatusType t : FtdcTransferStatusType.values()) { 33 | if(t.type.equals(type)) { 34 | retType = t; 35 | break; 36 | } 37 | } 38 | return retType; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcVolumeCondition.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | /** 3 | * 4 | * @author ee 5 | * 2017年10月17日 下午8:09:48 6 | * 7 | */ 8 | public enum FtdcVolumeCondition { 9 | /** 10 | * 任何数量 11 | */ 12 | HOST_AV("1"), 13 | /** 14 | * 最小数量 15 | */ 16 | HOST_MV("2"), 17 | /** 18 | * 全部数量 19 | */ 20 | HOST_CV("3"); 21 | 22 | private String vCondition; 23 | 24 | private FtdcVolumeCondition(String vCondition) { 25 | this.vCondition = vCondition; 26 | } 27 | 28 | public String getvCondition() { 29 | return vCondition; 30 | } 31 | 32 | public static FtdcVolumeCondition parseFrom(String flag) { 33 | FtdcVolumeCondition retFlag = null; 34 | switch(flag) { 35 | case "1": 36 | retFlag = HOST_AV; 37 | break; 38 | case "2": 39 | retFlag = HOST_MV; 40 | break; 41 | case "3": 42 | retFlag = HOST_CV; 43 | break; 44 | default: 45 | break; 46 | } 47 | return retFlag; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/enums/business/FtdcYesNoIndicator.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | /** 4 | * 验证客户证件号码标志 5 | * @author lyb 6 | * 2017年10月17日 下午8:10:21 7 | * 8 | */ 9 | public enum FtdcYesNoIndicator { 10 | /** 11 | * 是 12 | */ 13 | TDC_Yes("0"), 14 | /** 15 | * 否 16 | */ 17 | TDC_No("1"); 18 | 19 | private String flag; 20 | private FtdcYesNoIndicator(String flag) { 21 | this.flag = flag; 22 | } 23 | 24 | /** 25 | * @return the type 26 | */ 27 | public String getFlag() { 28 | return flag; 29 | } 30 | 31 | public static FtdcYesNoIndicator parseFrom(String flag) { 32 | FtdcYesNoIndicator retType = null; 33 | for (FtdcYesNoIndicator t : FtdcYesNoIndicator.values()) { 34 | if(t.flag.equals(flag)) { 35 | retType = t; 36 | break; 37 | } 38 | } 39 | return retType; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/FtdHeartbeatHandler.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.ee.ctp.ApplicationRuntime; 7 | import com.ee.ctp.dto.HeartBeat; 8 | 9 | import io.netty.channel.ChannelHandlerContext; 10 | import io.netty.channel.ChannelInboundHandlerAdapter; 11 | import io.netty.handler.timeout.IdleState; 12 | import io.netty.handler.timeout.IdleStateEvent; 13 | /** 14 | * 15 | * @author ee 16 | * 2017年10月17日 下午8:27:13 17 | * 18 | */ 19 | public class FtdHeartbeatHandler extends ChannelInboundHandlerAdapter{ 20 | private static final Logger logger = LoggerFactory.getLogger(FtdHeartbeatHandler.class); 21 | @Override 22 | public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { 23 | if(evt instanceof IdleStateEvent) { 24 | IdleStateEvent event = (IdleStateEvent) evt; 25 | if(event.state() == IdleState.READER_IDLE) { 26 | //超过约定时间没有收到数据认为链路有问题 27 | logger.warn("not recieve heartbeat , exceed {}", ApplicationRuntime.conf().getFtdcReaderIdle()); 28 | ctx.close(); 29 | }else if(event.state() == IdleState.WRITER_IDLE) { 30 | //超过约定时间没有写数据发心跳保活 31 | ctx.writeAndFlush(HeartBeat.getHeartBeat()); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/FtdcEncoder.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import java.util.List; 4 | 5 | import io.netty.buffer.ByteBuf; 6 | import io.netty.channel.ChannelHandlerContext; 7 | import io.netty.handler.codec.MessageToMessageEncoder; 8 | import io.netty.util.ReferenceCountUtil; 9 | /** 10 | * 11 | * @author ee 12 | * 2017年10月17日 下午8:26:22 13 | * 14 | */ 15 | public class FtdcEncoder extends MessageToMessageEncoder{ 16 | 17 | @Override 18 | protected void encode(ChannelHandlerContext ctx, FtdcProtocol msg, List out) throws Exception { 19 | ByteBuf buffer = null; 20 | try { 21 | buffer = ctx.alloc().buffer(); 22 | msg.write(buffer.retain()); 23 | out.add(buffer.retain()); 24 | } finally { 25 | ReferenceCountUtil.release(buffer); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/FtdcHandler.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import org.apache.commons.lang3.exception.ExceptionUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import com.ee.ctp.dto.HeartBeat; 8 | import com.ee.ctp.dto.RspError; 9 | import com.ee.ctp.enums.FtdTagType; 10 | import com.ee.ctp.enums.FtdcType; 11 | import com.ee.ctp.enums.Sequence; 12 | import com.ee.ctp.enums.TID; 13 | import com.ee.ctp.ftdc.FtdcProtocol.Ext; 14 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 15 | import com.ee.ctp.ftdc.processor.FtdcTidProcessor; 16 | import com.ee.ctp.ftdc.processor.TidProcessorFactory; 17 | import com.ee.ctp.handler.FtdcTraderSpi; 18 | import com.google.common.base.Verify; 19 | 20 | import io.netty.buffer.ByteBuf; 21 | import io.netty.channel.ChannelHandlerContext; 22 | import io.netty.channel.SimpleChannelInboundHandler; 23 | import io.netty.util.Attribute; 24 | /** 25 | * 26 | * @author ee 27 | * 2017年10月17日 下午8:26:30 28 | * 29 | */ 30 | public class FtdcHandler extends SimpleChannelInboundHandler { 31 | private static final Logger logger = LoggerFactory.getLogger(FtdcHandler.class); 32 | 33 | @Override 34 | protected void channelRead0(ChannelHandlerContext ctx, FtdcProtocol msg) throws Exception { 35 | if(msg.hasExt()) { 36 | handleFtdExt(ctx, msg); 37 | } 38 | if(msg.hasBody()) { 39 | Ftdc ftdc = null; 40 | try{ 41 | ftdc = msg.ftdc(); 42 | if(Sequence.AfterUserLogin.sequence() == ftdc.getSequence()) { 43 | //暂时忽略,认为是登录后的数据 44 | return; 45 | } 46 | ByteBuf ftdcBody = ftdc.ftdcBody(); 47 | if(ctx.channel().hasAttr(FtdcTraderSpi.TRADER_API)) { 48 | Attribute attr = ctx.channel().attr(FtdcTraderSpi.TRADER_API); 49 | FtdcTraderSpi ftdcTraderApi = attr.get(); 50 | Verify.verifyNotNull(ftdcTraderApi, "FtdcTraderSpi not register, pls register it first"); 51 | handleDataByTID(ftdc, ftdcBody, ftdcTraderApi); 52 | } 53 | } finally { 54 | if(ftdc != null) { 55 | ftdc.release(); 56 | } 57 | } 58 | } 59 | 60 | } 61 | 62 | private void handleDataByTID(Ftdc ftdc, ByteBuf ftdcBody, FtdcTraderSpi spi) { 63 | if(!ftdc.hasBody()) { 64 | spi.onNodata((int)ftdc.getReqId()); 65 | return; 66 | } 67 | TID tid = TID.parseFrom(ftdc.getTid(), FtdcType.RSP); 68 | RspError rspError = null; 69 | if(TID.CommonRsp == tid) { 70 | rspError = RspError.parseFrom(ftdcBody); 71 | if(ftdcBody.isReadable(Integer.SIZE / Byte.SIZE)) { 72 | tid = TID.parseFrom(ftdcBody.readUnsignedInt(), FtdcType.RSP); 73 | }else { 74 | int reqId = (int)ftdc.getReqId(); 75 | spi.onRspError(rspError, reqId); 76 | logger.warn("{} with error {}", reqId, rspError); 77 | return; 78 | } 79 | } 80 | FtdcTidProcessor processor = TidProcessorFactory.Holder.INSTANCE.processor(tid); 81 | processor.process(ftdc, spi, rspError); 82 | } 83 | 84 | private void handleFtdExt(ChannelHandlerContext ctx, FtdcProtocol msg) { 85 | Ext ext = msg.ext(); 86 | while(ext != null) { 87 | FtdTagType tagType = FtdTagType.parseFrom(ext.getTagType()); 88 | if(FtdTagType.FTDTagKeepAlive.equals(tagType)) { 89 | logger.debug("recieve heart beat from ctp"); 90 | ctx.writeAndFlush(HeartBeat.getHeartBeat()); 91 | } 92 | ext = ext.next(); 93 | } 94 | } 95 | 96 | @Override 97 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { 98 | logger.error(ExceptionUtils.getStackTrace(cause)); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/FtdcInitializer.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import com.ee.ctp.ApplicationRuntime; 4 | 5 | import io.netty.channel.ChannelInitializer; 6 | import io.netty.channel.socket.SocketChannel; 7 | /** 8 | * 仅用于ctp client 9 | * @author ee 10 | * 2017年10月17日 下午8:26:36 11 | * 12 | */ 13 | public class FtdcInitializer extends ChannelInitializer { 14 | 15 | @Override 16 | protected void initChannel(SocketChannel ch) throws Exception { 17 | ch.pipeline().addLast(new FtdcDecoder()); 18 | ch.pipeline().addLast(new FtdcEncoder()); 19 | ch.pipeline().addLast(ApplicationRuntime.EEG, new FtdcHandler()); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/AccountRegisterTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspAccountRegister; 4 | import com.ee.ctp.dto.RspError; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:21:30 11 | * 12 | */ 13 | public class AccountRegisterTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspAccountRegister rspAccountRegister = new RspAccountRegister().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspQryAccountRegister(rspAccountRegister, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/AuthTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspAuth; 4 | import com.ee.ctp.dto.RspError; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:21:41 11 | * 12 | */ 13 | public class AuthTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | if(error == null) { 18 | RspAuth rspAuth = new RspAuth().parseFirstFrom(ftdc.ftdcBody()); 19 | spi.onRspUserAuthFirst(rspAuth, (int)ftdc.getReqId(), true); 20 | }else { 21 | RspAuth rspAuth = new RspAuth().parseSecondFrom(ftdc.ftdcBody(), error); 22 | spi.onRspUserAuthSecond(rspAuth, (int)ftdc.getReqId(), true); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/BankOrFurureProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspFutureOrBank; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:21:48 11 | * 12 | */ 13 | public class BankOrFurureProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspFutureOrBank rspFutureToBank = new RspFutureOrBank().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspFutureOrBank(rspFutureToBank, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/ContractbankTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspContractBank; 4 | import com.ee.ctp.dto.RspError; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:21:55 14 | * 15 | */ 16 | public class ContractbankTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RspContractBank rspContractBank = new RspContractBank().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | spi.onRspQryContractBank(rspContractBank, (int)ftdc.getReqId(), isLast); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/ErrRtnOrderActionTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.ErrRtnOrderAction; 4 | import com.ee.ctp.dto.RspError; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:01 11 | * 12 | */ 13 | public class ErrRtnOrderActionTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | ErrRtnOrderAction errRtnOrderAction = new ErrRtnOrderAction().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onErrRtnOrderAction(errRtnOrderAction, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/FtdcTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 5 | import com.ee.ctp.handler.FtdcTraderSpi; 6 | /** 7 | * tid 处理器 8 | * @author ee 9 | * 2017年11月12日 下午11:20:48 10 | * 11 | */ 12 | public interface FtdcTidProcessor { 13 | /** 14 | * tid 处理 15 | * @param ftdc 16 | * @param spi 17 | * @param error 18 | */ 19 | void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/FundPasswordUpdateTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspFundPasswordUpdate; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:09 11 | * 12 | */ 13 | public class FundPasswordUpdateTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspFundPasswordUpdate rspFund = new RspFundPasswordUpdate().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspFundPasswordUpdate(rspFund, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/IgnoreTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 5 | import com.ee.ctp.handler.FtdcTraderSpi; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年11月12日 下午11:22:16 10 | * 11 | */ 12 | public class IgnoreTidProcessor implements FtdcTidProcessor{ 13 | 14 | @Override 15 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 16 | //nop 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/InvestorPoisitionTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspInvestorPosition; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:22:22 14 | * 15 | */ 16 | public class InvestorPoisitionTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RspInvestorPosition rspInvestorPosition = new RspInvestorPosition().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | spi.onRspInvestorPosition(rspInvestorPosition, (int)ftdc.getReqId(), isLast); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/OrderActionTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspOrderAction; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:30 11 | * 12 | */ 13 | public class OrderActionTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspOrderAction rspOrderAction = new RspOrderAction().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspOrderAction(rspOrderAction, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/OrderInsertTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspInputOrder; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:36 11 | * 12 | */ 13 | public class OrderInsertTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspInputOrder inputOrder = new RspInputOrder().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspOrderInput(inputOrder, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/QryCommissionRateTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspQryCommissionRate; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:42 11 | * 12 | */ 13 | public class QryCommissionRateTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspQryCommissionRate qryCommissionRate = new RspQryCommissionRate().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspQryCommissionRate(qryCommissionRate, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/QryInstrumentTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspQryInstrument; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:22:48 14 | * 15 | */ 16 | public class QryInstrumentTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RspQryInstrument rspQryInstrument = new RspQryInstrument().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | spi.onRspQryInstrument(rspQryInstrument, (int)ftdc.getReqId(), isLast); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/QryMarginRateTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspQryMarginRate; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:22:55 11 | * 12 | */ 13 | public class QryMarginRateTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspQryMarginRate qryMarginRate = new RspQryMarginRate().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspQryMarginRate(qryMarginRate, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/QryTransferSerialTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspQryTransferSerial; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:23:02 14 | * 15 | */ 16 | public class QryTransferSerialTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RspQryTransferSerial info = new RspQryTransferSerial().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | spi.onRspQryTransferSerial(info, (int)ftdc.getReqId(), isLast); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/RtnBankOrFutureTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RtnBankOrFuture; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:23:08 11 | * 12 | */ 13 | public class RtnBankOrFutureTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RtnBankOrFuture rtnBankOrFuture = new RtnBankOrFuture().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRtnBankOrFuture(rtnBankOrFuture, (int)ftdc.getReqId(), true); 19 | } 20 | } -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/RtnOrderTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RtnOrder; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:23:14 14 | * 15 | */ 16 | public class RtnOrderTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RtnOrder rtnOrder = new RtnOrder().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | int reqId = (int)ftdc.getReqId(); 37 | if(reqId == 0) { 38 | spi.onRtnOrder(rtnOrder, reqId, isLast); 39 | }else { 40 | spi.onRspQryOrder(rtnOrder, reqId, isLast); 41 | } 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/RtnTradeTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RtnTrade; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:23:20 14 | * 15 | */ 16 | public class RtnTradeTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RtnTrade rtnTrade = new RtnTrade().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | int reqId = (int)ftdc.getReqId(); 37 | if(reqId == 0) { 38 | spi.onRtnTrade(rtnTrade, reqId, isLast); 39 | }else { 40 | spi.onRspQryTrade(rtnTrade, reqId, isLast); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/SettlementInfoConfirmTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspQrySettlementInfoConfirm; 5 | import com.ee.ctp.dto.RspSettlementInfoConfirm; 6 | import com.ee.ctp.enums.Sequence; 7 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 8 | import com.ee.ctp.handler.FtdcTraderSpi; 9 | /** 10 | * 11 | * @author ee 12 | * 2017年11月12日 下午11:23:27 13 | * 14 | */ 15 | public class SettlementInfoConfirmTidProcessor implements FtdcTidProcessor{ 16 | 17 | @Override 18 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 19 | if(Sequence.QrySettlementInfoConfirm.rspSequence() == ftdc.getSequence()) { 20 | //QrySettlementInfoConfirmRsp 21 | RspQrySettlementInfoConfirm qrySettlementInfoConfirm = new RspQrySettlementInfoConfirm().parseFrom(ftdc.ftdcBody(), error); 22 | spi.onRspQrySettlementInfoConfirm(qrySettlementInfoConfirm, (int)ftdc.getReqId(), true); 23 | }else if(Sequence.SettlementInfoConfirm.rspSequence() == ftdc.getSequence()){ 24 | RspSettlementInfoConfirm info = new RspSettlementInfoConfirm().parseFrom(ftdc.ftdcBody(), error); 25 | spi.onRspSettlementInfoConfirm(info, (int)ftdc.getReqId(), true); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/SettlementInfoTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspSettlementInfo; 5 | import com.ee.ctp.enums.ChainType; 6 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 7 | import com.ee.ctp.handler.FtdcTraderSpi; 8 | 9 | import io.netty.buffer.ByteBuf; 10 | /** 11 | * 12 | * @author ee 13 | * 2017年11月12日 下午11:23:35 14 | * 15 | */ 16 | public class SettlementInfoTidProcessor implements FtdcTidProcessor{ 17 | 18 | @Override 19 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 20 | ByteBuf ftdcBody = ftdc.ftdcBody(); 21 | boolean lastPacket = false; 22 | if(ChainType.END.chain() == ftdc.getChain()) { 23 | lastPacket = true; 24 | } 25 | for(int i = 0; i < ftdc.getNumData(); i++) { 26 | if(i != 0) { 27 | //每个数据域都是以TID开头 28 | if(ftdcBody.isReadable(4)) { 29 | ftdcBody.readInt(); 30 | }else { 31 | break; 32 | } 33 | } 34 | boolean isLast = lastPacket && (i == ftdc.getNumData() - 1); 35 | RspSettlementInfo rsinfo = new RspSettlementInfo().parseFrom(ftdcBody.readRetainedSlice(ftdc.getStructOfTidLen()), error); 36 | rsinfo.setSequenceNo(ftdc.getCurrentSequence()); 37 | spi.onRspSettlementInfo(rsinfo, (int)ftdc.getReqId(), isLast); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/TidProcessorException.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | /** 3 | * Processor 异常 4 | * @author ee 5 | * 2017年11月2日 下午5:47:57 6 | * 7 | */ 8 | public class TidProcessorException extends RuntimeException { 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 2L; 14 | 15 | public TidProcessorException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public TidProcessorException(String message) { 20 | super(message); 21 | } 22 | 23 | public TidProcessorException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/TidProcessorFactory.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | 5 | import com.ee.ctp.enums.TID; 6 | /** 7 | * TID processor 工厂 8 | * @author ee 9 | * 2017年11月12日 下午11:23:43 10 | * 11 | */ 12 | public class TidProcessorFactory { 13 | private static final ConcurrentHashMap tid_processors = new ConcurrentHashMap<>(); 14 | 15 | public static class Holder { 16 | public static final TidProcessorFactory INSTANCE = new TidProcessorFactory(); 17 | private Holder() {} 18 | } 19 | 20 | private TidProcessorFactory() { 21 | loadProcessors(); 22 | } 23 | 24 | private void loadProcessors() { 25 | processor(TID.UserLoginRsp, UserLoginTidProcessor.class); 26 | processor(TID.UserLogoutRsp, UserLogoutTidProcessor.class); 27 | processor(TID.SettlementInfoConfirmRsp, SettlementInfoConfirmTidProcessor.class); 28 | processor(TID.OrderInsertRsp, OrderInsertTidProcessor.class); 29 | processor(TID.OrderActionRsp, OrderActionTidProcessor.class); 30 | processor(TID.BankOrFutureRsp, BankOrFurureProcessor.class); 31 | processor(TID.UserPasswordUpdateRsp, UserPasswordUpdateTidProcessor.class); 32 | processor(TID.FundPasswordUpdateRsp, FundPasswordUpdateTidProcessor.class); 33 | processor(TID.SettlementInfoRsp, SettlementInfoTidProcessor.class); 34 | processor(TID.TradingAccountRsp, TradingAccountTidProcessor.class); 35 | processor(TID.RtnOrder, RtnOrderTidProcessor.class); 36 | processor(TID.RtnTrade, RtnTradeTidProcessor.class); 37 | processor(TID.InvestorPositionRsp, InvestorPoisitionTidProcessor.class); 38 | processor(TID.QryMarginRateRsp, QryMarginRateTidProcessor.class); 39 | processor(TID.QryCommissionRateRsp, QryCommissionRateTidProcessor.class); 40 | processor(TID.AccountRegisterRsp, AccountRegisterTidProcessor.class); 41 | processor(TID.ContractbankRsp, ContractbankTidProcessor.class); 42 | processor(TID.ErrRtnOrderAction, ErrRtnOrderActionTidProcessor.class); 43 | processor(TID.QryInstrumentRsp, QryInstrumentTidProcessor.class); 44 | processor(TID.QryTransferSerialRsp, QryTransferSerialTidProcessor.class); 45 | processor(TID.RtnBankOrFuture, RtnBankOrFutureTidProcessor.class); 46 | processor(TID.Auth, AuthTidProcessor.class); 47 | processor(TID.UNUSE, UnuseTidProcessor.class); 48 | processor(TID.BankOrFutureRsp1, IgnoreTidProcessor.class); 49 | processor(TID.BankOrFutureRsp2, IgnoreTidProcessor.class); 50 | 51 | } 52 | 53 | private void processor(TID tid, Class clazz) { 54 | try { 55 | FtdcTidProcessor ftdcTidProcessor = clazz.newInstance(); 56 | tid_processors.putIfAbsent(tid, ftdcTidProcessor); 57 | } catch (Exception e) { 58 | throw new TidProcessorException(e); 59 | } 60 | } 61 | 62 | public void replaceProcessor(TID tid, FtdcTidProcessor processor) { 63 | try { 64 | tid_processors.put(tid, processor); 65 | } catch (Exception e) { 66 | throw new TidProcessorException(e); 67 | } 68 | } 69 | 70 | public FtdcTidProcessor processor(TID tid) { 71 | FtdcTidProcessor tidProcessor = tid_processors.get(tid); 72 | if(tidProcessor == null) { 73 | throw new TidProcessorException("can not find processor of " + tid); 74 | } 75 | return tidProcessor; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/TradingAccountTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspTradingAccount; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:24:03 11 | * 12 | */ 13 | public class TradingAccountTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspTradingAccount tradingAccount = new RspTradingAccount().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspTradingAccount(tradingAccount, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/UnuseTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 5 | import com.ee.ctp.handler.FtdcTraderSpi; 6 | /** 7 | * 8 | * @author ee 9 | * 2017年11月12日 下午11:24:09 10 | * 11 | */ 12 | public class UnuseTidProcessor implements FtdcTidProcessor{ 13 | 14 | @Override 15 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 16 | spi.onRecieveUnUsedTid(String.valueOf(ftdc.getTid()), (int)ftdc.getReqId()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/UserLoginTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspUserLogin; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:24:15 11 | * 12 | */ 13 | public class UserLoginTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspUserLogin rspUserLogin = new RspUserLogin().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspUserLogin(rspUserLogin, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/UserLogoutTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspUserLogout; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:24:20 11 | * 12 | */ 13 | public class UserLogoutTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspUserLogout lout = new RspUserLogout().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspUserLogout(lout, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/ftdc/processor/UserPasswordUpdateTidProcessor.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc.processor; 2 | 3 | import com.ee.ctp.dto.RspError; 4 | import com.ee.ctp.dto.RspUserPasswordUpdate; 5 | import com.ee.ctp.ftdc.FtdcProtocol.Ftdc; 6 | import com.ee.ctp.handler.FtdcTraderSpi; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年11月12日 下午11:24:25 11 | * 12 | */ 13 | public class UserPasswordUpdateTidProcessor implements FtdcTidProcessor{ 14 | 15 | @Override 16 | public void process(Ftdc ftdc, FtdcTraderSpi spi, RspError error) { 17 | RspUserPasswordUpdate userPasswordUpdate = new RspUserPasswordUpdate().parseFrom(ftdc.ftdcBody(), error); 18 | spi.onRspUserPasswordUpdate(userPasswordUpdate, (int)ftdc.getReqId(), true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/handler/FtdcTraderApi.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.handler; 2 | 3 | import java.util.List; 4 | 5 | import com.ee.ctp.RequestIdentity; 6 | import com.ee.ctp.dto.FtdcReq; 7 | import com.ee.ctp.pool.FtdClientPool.ConnectAddrProperty; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:29:05 12 | * 13 | */ 14 | public interface FtdcTraderApi { 15 | /** 16 | * 注册ftd地址 17 | * @param sas 18 | */ 19 | void registerFront(List sas); 20 | /** 21 | * 注册消息处理器 22 | * @param requestIdentity 23 | * @param spi 24 | */ 25 | void registerSpi(RequestIdentity requestIdentity, FtdcTraderSpi spi); 26 | /** 27 | * 请求登录 28 | * @param requestIdentity 29 | * @param userLogin 30 | * @param spi 31 | */ 32 | void reqUserLogin(RequestIdentity requestIdentity, FtdcReq userLogin); 33 | /** 34 | * 请求登出 35 | * @param requestIdentity 36 | * @param userLogout 37 | */ 38 | void reqUserLogout(RequestIdentity requestIdentity, FtdcReq userLogout); 39 | /** 40 | * 请求结算单信息 41 | * @param requestIdentity 42 | * @param info 43 | */ 44 | void reqSettlementInfo(RequestIdentity requestIdentity, FtdcReq info); 45 | /** 46 | * 请求结算单确认 47 | * @param requestIdentity 48 | * @param info 49 | */ 50 | void reqSettlementInfoConfirm(RequestIdentity requestIdentity,FtdcReq info); 51 | /** 52 | * 请求查询结算单确认 53 | * @param requestIdentity 54 | * @param info 55 | */ 56 | void reqQrySettlementInfoConfirm(RequestIdentity requestIdentity,FtdcReq info); 57 | /** 58 | * 请求查询资金信息 59 | * @param requestIdentity 60 | * @param tradingAccount 61 | */ 62 | void reqTradingAccount(RequestIdentity requestIdentity,FtdcReq tradingAccount); 63 | /**O 64 | * 请求报单 65 | * @param requestIdentity 66 | * @param inputOrder 67 | */ 68 | void reqOrderInput(RequestIdentity requestIdentity,FtdcReq inputOrder); 69 | /** 70 | * 请求持仓 71 | * @param requestIdentity 72 | * @param investorPisition 73 | */ 74 | void reqInvestorPosition(RequestIdentity requestIdentity,FtdcReq investorPisition); 75 | /** 76 | * 请求查询保证金比例 77 | * @param requestIdentity 78 | * @param qryMarginRate 79 | */ 80 | void reqQryMarginRate(RequestIdentity requestIdentity,FtdcReq qryMarginRate); 81 | /** 82 | * 请求查询手续费 83 | * @param requestIdentity 84 | * @param qryCommissionRate 85 | */ 86 | void reqQryCommissionRate(RequestIdentity requestIdentity,FtdcReq qryCommissionRate); 87 | /** 88 | * 请求查询银期签约关系 89 | * @param requestIdentity 90 | * @param accountRegister 91 | */ 92 | void reqQryAccountRegister(RequestIdentity requestIdentity,FtdcReq accountRegister); 93 | /** 94 | * 请求查询签约银行 95 | * @param requestIdentity 96 | * @param contractBank 97 | */ 98 | void reqQryContractBank(RequestIdentity requestIdentity,FtdcReq contractBank); 99 | /** 100 | * 报单操作 101 | * @param requestIdentity 102 | * @param reqOrderAction 103 | */ 104 | void reqOrderAction(RequestIdentity requestIdentity,FtdcReq reqOrderAction); 105 | /** 106 | * 查询转账流水 107 | * @param requestIdentity 108 | * @param info 109 | */ 110 | void reqQryTransferSerial(RequestIdentity requestIdentity,FtdcReq info); 111 | /** 112 | * 查询合约 113 | * @param requestIdentity 114 | * @param info 115 | */ 116 | void reqQryInstrument(RequestIdentity requestIdentity,FtdcReq info); 117 | /** 118 | * 请求银行转期货 119 | * @param requestIdentity 120 | * @param info 121 | */ 122 | void reqFromBankToFuture(RequestIdentity requestIdentity,FtdcReq info); 123 | /** 124 | * 请求期货转银行 125 | * @param requestIdentity 126 | * @param info 127 | */ 128 | void reqFromFutureToBank(RequestIdentity requestIdentity,FtdcReq info); 129 | /** 130 | * 请求交易密码修改 131 | * @param requestIdentity 132 | * @param info 133 | */ 134 | void reqUserPasswordUpdate(RequestIdentity requestIdentity,FtdcReq info); 135 | /** 136 | * 请求报单查询 137 | * @param requestIdentity 138 | * @param info 139 | */ 140 | void reqQryOrder(RequestIdentity requestIdentity,FtdcReq info); 141 | /** 142 | * 成交查询 143 | * @param requestIdentity 144 | * @param info 145 | */ 146 | void reqQryTrade(RequestIdentity requestIdentity,FtdcReq info); 147 | /** 148 | * 请求资金密码修改 149 | * @param requestIdentity 150 | * @param info 151 | */ 152 | void reqFundPasswordUpdate(RequestIdentity requestIdentity,FtdcReq info); 153 | 154 | /** 155 | * 用户认证和登录 156 | * @param requestIdentity 157 | * @param userLogin 158 | * @param spi 159 | */ 160 | void reqAuthAndLogin(RequestIdentity requestIdentity, FtdcReq userLogin); 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/handler/task/RecieveMessageTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.handler.task; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.ee.ctp.ApplicationRuntime; 7 | import com.ee.ctp.RequestIdentity; 8 | import com.ee.ctp.dto.RspError; 9 | import com.ee.ctp.handler.FtdcTraderSpi; 10 | 11 | import io.netty.util.Timeout; 12 | import io.netty.util.TimerTask; 13 | /** 14 | * 15 | * @author ee 16 | * 2017年10月17日 下午8:43:41 17 | * 18 | */ 19 | public class RecieveMessageTimerTask implements TimerTask{ 20 | private static final Logger logger = LoggerFactory.getLogger(RecieveMessageTimerTask.class); 21 | private RequestIdentity requestIdentity; 22 | private FtdcTraderSpi spi; 23 | public RecieveMessageTimerTask(RequestIdentity requestIdentity, FtdcTraderSpi spi) { 24 | this.requestIdentity = requestIdentity; 25 | this.spi = spi; 26 | } 27 | @Override 28 | public void run(Timeout timeout) throws Exception { 29 | RequestIdentity ri = ApplicationRuntime.getRequestIdentity(requestIdentity.getBrokerId(), requestIdentity.getUserId(), requestIdentity.getReqId()); 30 | if(ri != null) { 31 | logger.warn("reqId {}, brokerid {}, uid {} timeouts", requestIdentity.getReqId(), requestIdentity.getBrokerId(), requestIdentity.getUserId()); 32 | RspError recieveMessageError = RspError.buildRecieveMessageError(); 33 | spi.onRspError(recieveMessageError, this.requestIdentity); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/pool/DefaultSocketAddressChooserFactory.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.pool; 2 | 3 | import java.net.SocketAddress; 4 | import java.util.List; 5 | import java.util.concurrent.atomic.AtomicInteger; 6 | 7 | import com.ee.ctp.pool.FtdClientPool.ConnectAddrProperty; 8 | /** 9 | * 10 | * @author ee 11 | * 2017年10月17日 下午8:44:26 12 | * 13 | */ 14 | public class DefaultSocketAddressChooserFactory implements SocketAddressChooserFactory { 15 | public static final DefaultSocketAddressChooserFactory INSTANCE = new DefaultSocketAddressChooserFactory(); 16 | private DefaultSocketAddressChooserFactory() {} 17 | @Override 18 | public SocketAddressChooser newChooser(int size) { 19 | if(isPowerOfTwo(size)) { 20 | return new PowerOfTwoSocketAddressChooser(); 21 | }else { 22 | return new GenericSocketAddressChooser(); 23 | } 24 | } 25 | 26 | static boolean isPowerOfTwo(int val) { 27 | return (val & -val) == val; 28 | } 29 | 30 | static final class PowerOfTwoSocketAddressChooser implements SocketAddressChooser{ 31 | private final AtomicInteger idx = new AtomicInteger(); 32 | 33 | @Override 34 | public SocketAddress next(List sas) { 35 | return sas.get(idx.getAndIncrement() & sas.size() - 1).getSocketAddress(); 36 | } 37 | 38 | } 39 | 40 | static final class GenericSocketAddressChooser implements SocketAddressChooser{ 41 | private final AtomicInteger idx = new AtomicInteger(); 42 | 43 | @Override 44 | public SocketAddress next(List sas) { 45 | return sas.get(Math.abs(idx.getAndIncrement() % sas.size())).getSocketAddress(); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/pool/SocketAddressChooserFactory.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.pool; 2 | 3 | import java.net.SocketAddress; 4 | import java.util.List; 5 | 6 | import com.ee.ctp.pool.FtdClientPool.ConnectAddrProperty; 7 | /** 8 | * 9 | * @author ee 10 | * 2017年10月17日 下午8:45:45 11 | * 12 | */ 13 | public interface SocketAddressChooserFactory { 14 | /** 15 | * 创建一个选择器 16 | * @param size 17 | * @return 18 | */ 19 | SocketAddressChooser newChooser(int size); 20 | 21 | interface SocketAddressChooser { 22 | /** 23 | * 获得下一个地址 24 | * @param sas 25 | * @return 26 | */ 27 | SocketAddress next(List sas); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/security/KAES.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.security; 2 | 3 | import javax.crypto.Cipher; 4 | import javax.crypto.spec.SecretKeySpec; 5 | 6 | /** 7 | * AES认证 8 | * 9 | * @author ee 2017年11月2日 下午5:32:34 10 | * 11 | */ 12 | public class KAES { 13 | public static final KAES DEFAULT_INSTANCE = new KAES(); 14 | private static final String ENCRYT_MODE = "AES/ECB/NoPadding"; 15 | private static final String ENCRYPT = "AES"; 16 | private static final int DIL = 0x85; 17 | private static final int SIGN_BLOCK = 0xff; 18 | private static final int BOUND_LOW = 0x9; 19 | private static final int BOUND_HIGH = 0x23; 20 | 21 | private static final int BOUND_MID_ADD = 0x57; 22 | private static final int BOUND_HIGH_ADD = 0x1d; 23 | private static final int BOUND_LOW_ADD = 0x30; 24 | 25 | /** 26 | * 认证 27 | * @param src 28 | * @param key 29 | * @return 30 | */ 31 | public byte[] encrypt(byte[] src, byte[] key) { 32 | byte[] aesEncrypt = aesEncrypt(src, key); 33 | return auth(aesEncrypt); 34 | } 35 | 36 | private byte[] aesEncrypt(byte[] src, byte[] key) { 37 | try { 38 | Cipher cipher = Cipher.getInstance(ENCRYT_MODE); 39 | SecretKeySpec skeySpec = new SecretKeySpec(key, ENCRYPT); 40 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec); 41 | return cipher.doFinal(src); 42 | } catch (Exception e) { 43 | throw new KAESException(e); 44 | } 45 | } 46 | 47 | private byte[] auth(byte[] aesData) { 48 | byte [] authData = new byte[aesData.length]; 49 | for (int i = 0; i < aesData.length; i++) { 50 | int unsignData = aesData[i] & SIGN_BLOCK; 51 | int edx = unsignData; 52 | edx >>= 1; 53 | int eax = edx; 54 | eax *= DIL; 55 | edx = eax >> 12; 56 | int ecx = edx * 2; 57 | edx <<= 6; 58 | edx -= ecx; 59 | unsignData -= edx; 60 | if(unsignData > BOUND_LOW && unsignData <= BOUND_HIGH) { 61 | unsignData += BOUND_MID_ADD; 62 | }else if(unsignData > BOUND_HIGH){ 63 | unsignData += BOUND_HIGH_ADD; 64 | }else { 65 | unsignData += BOUND_LOW_ADD; 66 | } 67 | authData[i] = (byte)unsignData; 68 | } 69 | return authData; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/ee/ctp/security/KAESException.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.security; 2 | /** 3 | * AES认证异常 4 | * @author ee 5 | * 2017年11月2日 下午5:47:57 6 | * 7 | */ 8 | public class KAESException extends RuntimeException { 9 | 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | 15 | public KAESException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public KAESException(String message) { 20 | super(message); 21 | } 22 | 23 | public KAESException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/resources/ThostFtdcUserApiDataType.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haoziwlh/ftdc/1635c369017b969e2bf4678087b5cd9f5e6a5ead/src/main/resources/ThostFtdcUserApiDataType.h -------------------------------------------------------------------------------- /src/main/resources/dto.req: -------------------------------------------------------------------------------- 1 | struct CThostFtdcUserPasswordUpdateField 2 | { 3 | ///经纪公司代码 4 | TThostFtdcBrokerIDType BrokerID; 5 | ///用户代码 6 | TThostFtdcUserIDType UserID; 7 | ///原来的口令 8 | TThostFtdcPasswordType OldPassword; 9 | ///新的口令 10 | TThostFtdcPasswordType NewPassword; 11 | }; -------------------------------------------------------------------------------- /src/main/resources/dto.rsp: -------------------------------------------------------------------------------- 1 | struct CThostFtdcUserPasswordUpdateField 2 | { 3 | ///经纪公司代码 4 | TThostFtdcBrokerIDType BrokerID; 5 | ///用户代码 6 | TThostFtdcUserIDType UserID; 7 | ///原来的口令 8 | TThostFtdcPasswordType OldPassword; 9 | ///新的口令 10 | TThostFtdcPasswordType NewPassword; 11 | }; -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/CodeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class CodeTest extends TestCase{ 6 | 7 | //191, 205, 187, 167, 182, 203 BFcdbb 8 | public void testCode() throws Exception { 9 | byte[] b1 = "客户端".getBytes("gbk"); 10 | byte[] btransfered = new byte[b1.length]; 11 | for (int i = 0; i < b1.length; i++) { 12 | byte b = b1[i]; 13 | btransfered[i] = (byte)(b & 0xff); 14 | } 15 | assertEquals("客户端", new String(btransfered, "gbk")); 16 | } 17 | 18 | public void testB() throws Exception { 19 | //d5fdc8b7 20 | byte b1 = (byte)(0xb6 & 0xff); 21 | byte b2 = (byte)(0xcb & 0xff); 22 | byte b3 = (byte)(0xc8 & 0xff); 23 | byte b4 = (byte)(0xcf & 0xff); 24 | byte[] b = new byte[]{b1,b2,b3,b4}; 25 | System.out.println(new String(b,"gbk")); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/TradeOrderActionTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.channel.Channel; 5 | import io.netty.channel.ChannelFuture; 6 | import io.netty.channel.ChannelFutureListener; 7 | 8 | import java.util.Random; 9 | 10 | import com.ee.ctp.ApplicationRuntime; 11 | import com.ee.ctp.CtpClient; 12 | import com.ee.ctp.dto.ReqOrderAction; 13 | import com.ee.ctp.dto.ReqUserLogin; 14 | import com.ee.ctp.dto.UserSession; 15 | import com.ee.ctp.enums.FtdType; 16 | import com.ee.ctp.enums.FtdcType; 17 | import com.ee.ctp.enums.Sequence; 18 | import com.ee.ctp.enums.TID; 19 | import com.ee.ctp.enums.business.FtdcActionFlagType; 20 | import com.ee.ctp.enums.business.FtdcExchange; 21 | import com.ee.ctp.ftdc.FtdcProtocol; 22 | import com.ee.ctp.handler.FtdcTraderSpi; 23 | import com.ee.ctp.handler.PrintResultHandler; 24 | 25 | import junit.framework.TestCase; 26 | 27 | /** 28 | * @author ee 29 | * 30 | */ 31 | public class TradeOrderActionTest extends TestCase{ 32 | 33 | private static final String USERID = "changeme"; 34 | private static final String PASSWD = "changeme"; 35 | private static final String BROKERID = "9999"; 36 | private static final String HOST = "180.168.146.187"; 37 | private static final int PORT = 10000; 38 | 39 | private static final long WATI_TIME = 1000 * 1000; 40 | 41 | public void testLogin() throws Exception { 42 | UserLoginReqhandler userLoginReqhandler = new UserLoginReqhandler(); 43 | CtpClient.ctp(HOST, PORT, userLoginReqhandler); 44 | Thread.sleep(WATI_TIME); 45 | } 46 | 47 | public void testLoginAndOrderAction() throws Exception { 48 | UserLoginReqhandler userLoginReqhandler = new UserLoginReqhandler(); 49 | CtpClient.ctp(HOST, PORT, userLoginReqhandler); 50 | 51 | Channel ftdcChannel = ApplicationRuntime.getFtdcChannel(BROKERID, USERID); 52 | while(ftdcChannel == null) { 53 | ftdcChannel = ApplicationRuntime.getFtdcChannel(BROKERID, USERID); 54 | Thread.sleep(1000); 55 | } 56 | 57 | ByteBuf buffer = ftdcChannel.alloc().buffer(); 58 | ReqOrderAction order = new ReqOrderAction(); 59 | 60 | UserSession userSession = ftdcChannel.attr(FtdcTraderSpi.USER_SESSION).get(); 61 | order.setSessionID(userSession.getSessionId()); 62 | 63 | // 需要修改参数>>>>>>>> 64 | order.setOrderRef("101"); 65 | // 需要修改参数<<<<<<<< 66 | 67 | order.setBrokerID(BROKERID); 68 | order.setInvestorID(USERID); 69 | 70 | order.setOrderActionRef(1); 71 | 72 | order.setRequestID(new Random().nextInt(9999)); 73 | 74 | order.setExchangeID(FtdcExchange.FTDC_SHFE); 75 | order.setInstrumentID("ag1712"); 76 | order.setIPAddress("122.40.123.44"); 77 | order.setMacAddress("98:01:A7:9E:92:d7"); 78 | order.setFrontID(1); 79 | order.setActionFlag(FtdcActionFlagType.THOST_FTDCAF_Delete);//0-删除 1-修改 80 | order.setUserID(USERID); 81 | order.write(buffer.retain()); 82 | FtdcProtocol ftdc = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(), 6971, TID.OrderActionReq.id(), Sequence.OrderAction); 83 | ftdcChannel.writeAndFlush(ftdc); 84 | 85 | Thread.sleep(WATI_TIME); 86 | } 87 | 88 | 89 | static class UserLoginReqhandler implements ChannelFutureListener { 90 | 91 | @Override 92 | public void operationComplete(ChannelFuture future) throws Exception { 93 | Channel channel = future.channel(); 94 | ReqUserLogin userLogin = new ReqUserLogin(); 95 | userLogin.setTradingDay("19800100"); 96 | userLogin.setBrokerID(BROKERID); 97 | userLogin.setUserId(USERID); 98 | userLogin.setPasswd(PASSWD); 99 | userLogin.setInterfaceProductInfo("THOST User"); 100 | userLogin.setProtocolInfo("FTDC 0"); 101 | userLogin.setMacAddress("99:01:A7:9E:92:d7"); 102 | ByteBuf buffer = channel.alloc().buffer(); 103 | userLogin.write(buffer.retain()); 104 | new PrintResultHandler().reqister(channel); 105 | FtdcProtocol ftdc = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(),6960, TID.UserLoginReq.id()); 106 | channel.writeAndFlush(ftdc); 107 | } 108 | 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/TradeUserPasswordUpdateTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp; 2 | 3 | import com.ee.ctp.ApplicationRuntime; 4 | import com.ee.ctp.CtpClient; 5 | import com.ee.ctp.dto.ReqUserLogin; 6 | import com.ee.ctp.dto.ReqUserPasswordUpdate; 7 | import com.ee.ctp.enums.FtdType; 8 | import com.ee.ctp.enums.FtdcType; 9 | import com.ee.ctp.enums.Sequence; 10 | import com.ee.ctp.enums.TID; 11 | import com.ee.ctp.ftdc.FtdcProtocol; 12 | import com.ee.ctp.handler.PrintResultHandler; 13 | 14 | import io.netty.buffer.ByteBuf; 15 | import io.netty.channel.Channel; 16 | import io.netty.channel.ChannelFuture; 17 | import io.netty.channel.ChannelFutureListener; 18 | import junit.framework.TestCase; 19 | 20 | /** 21 | * @author ee 22 | * 23 | */ 24 | public class TradeUserPasswordUpdateTest extends TestCase{ 25 | 26 | private static final String USERID = "changeme"; 27 | private static final String PASSWD = "changeme"; 28 | private static final String BROKERID = "9999"; 29 | private static final String HOST = "180.168.146.187"; 30 | private static final int PORT = 10000; 31 | 32 | private static final long WATI_TIME = 1000 * 1000; 33 | 34 | public void testLogin() throws Exception { 35 | UserLoginReqhandler userLoginReqhandler = new UserLoginReqhandler(); 36 | CtpClient.ctp(HOST, PORT, userLoginReqhandler); 37 | Thread.sleep(WATI_TIME); 38 | } 39 | 40 | public void testLoginAndUserPasswordUpdate() throws Exception { 41 | UserLoginReqhandler userLoginReqhandler = new UserLoginReqhandler(); 42 | CtpClient.ctp(HOST, PORT, userLoginReqhandler); 43 | 44 | Channel ftdcChannel = ApplicationRuntime.getFtdcChannel(BROKERID, USERID); 45 | while(ftdcChannel == null) { 46 | ftdcChannel = ApplicationRuntime.getFtdcChannel(BROKERID, USERID); 47 | Thread.sleep(1000); 48 | } 49 | 50 | ByteBuf buffer = ftdcChannel.alloc().buffer(); 51 | ReqUserPasswordUpdate order = new ReqUserPasswordUpdate(); 52 | order.setUserID(USERID); 53 | order.setOldPassword("890619ab"); 54 | order.setNewPassword("890619aa"); 55 | order.setBrokerID(BROKERID); 56 | order.write(buffer.retain()); 57 | FtdcProtocol ftdc = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(), 6972, TID.UserPasswordUpdateReq.id(), Sequence.UserPasswordUpdate); 58 | ftdcChannel.writeAndFlush(ftdc); 59 | 60 | Thread.sleep(WATI_TIME); 61 | } 62 | 63 | 64 | static class UserLoginReqhandler implements ChannelFutureListener { 65 | 66 | @Override 67 | public void operationComplete(ChannelFuture future) throws Exception { 68 | Channel channel = future.channel(); 69 | ReqUserLogin userLogin = new ReqUserLogin(); 70 | userLogin.setTradingDay("19800100"); 71 | userLogin.setBrokerID(BROKERID); 72 | userLogin.setUserId(USERID); 73 | userLogin.setPasswd(PASSWD); 74 | userLogin.setInterfaceProductInfo("THOST User"); 75 | userLogin.setProtocolInfo("FTDC 0"); 76 | userLogin.setMacAddress("99:01:A7:9E:92:d7"); 77 | ByteBuf buffer = channel.alloc().buffer(); 78 | userLogin.write(buffer.retain()); 79 | new PrintResultHandler().reqister(channel); 80 | FtdcProtocol ftdc = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(),6960, TID.UserLoginReq.id()); 81 | channel.writeAndFlush(ftdc); 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/CTPErrorCodeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | import com.ee.ctp.enums.CTPErrorCode; 4 | 5 | import junit.framework.TestCase; 6 | 7 | public class CTPErrorCodeTest extends TestCase{ 8 | 9 | public void testParseFrom() { 10 | assertEquals(CTPErrorCode.CTP_OK, CTPErrorCode.parseFrom(0)); 11 | assertEquals(CTPErrorCode.CTP_WEAK_PASSWORD, CTPErrorCode.parseFrom(131)); 12 | assertEquals(null, CTPErrorCode.parseFrom(100)); 13 | } 14 | 15 | public void testIsChannelAuthPassed() { 16 | assertEquals(true, CTPErrorCode.isChannelAuthPassed(CTPErrorCode.CTP_OK)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/FtdTagTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.FtdTagType; 8 | 9 | public class FtdTagTypeTest { 10 | 11 | @Test 12 | public void testParseFrom() { 13 | assertEquals(FtdTagType.FTDTagNone, FtdTagType.parseFrom(0)); 14 | } 15 | 16 | @Test(expected = IllegalArgumentException.class) 17 | public void testParseFromException() { 18 | assertEquals(FtdTagType.FTDTagNone, FtdTagType.parseFrom(10)); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/FtdTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.FtdType; 8 | 9 | public class FtdTypeTest { 10 | 11 | @Test 12 | public void testParseFrom() { 13 | assertEquals(FtdType.FTDTypeNone, FtdType.parseFrom(0)); 14 | assertEquals(FtdType.FTDTypeFTDC, FtdType.parseFrom(1)); 15 | assertEquals(FtdType.FTDTypeCompressed, FtdType.parseFrom(2)); 16 | } 17 | 18 | @Test(expected = IllegalArgumentException.class) 19 | public void testParseFromException() { 20 | assertEquals(FtdType.FTDTypeNone, FtdType.parseFrom(10)); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/SequenceTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.Sequence; 8 | 9 | public class SequenceTest { 10 | 11 | @Test 12 | public void testRspSequence() { 13 | Sequence[] values = Sequence.values(); 14 | for (Sequence sequence : values) { 15 | assertEquals(sequence.sequence() + 1, sequence.rspSequence()); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/TIDTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.FtdcType; 8 | import com.ee.ctp.enums.TID; 9 | 10 | public class TIDTest { 11 | 12 | @Test 13 | public void testParseFrom() { 14 | assertEquals(TID.AccountRegisterReq, TID.parseFrom(0x30110025, FtdcType.REQ)); 15 | assertEquals(TID.AccountRegisterRsp, TID.parseFrom(0x30120197, FtdcType.RSP)); 16 | assertEquals(TID.UNUSE, TID.parseFrom(0x90110025, FtdcType.REQ)); 17 | assertEquals(TID.UNUSE, TID.parseFrom(0x90110025, FtdcType.RSP)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/business/FtdcActionFlagTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.business.FtdcActionFlagType; 8 | 9 | public class FtdcActionFlagTypeTest { 10 | 11 | @Test 12 | public void testParseFrom() { 13 | assertEquals(FtdcActionFlagType.THOST_FTDCAF_Delete, FtdcActionFlagType.parseFrom("0")); 14 | assertEquals(null, FtdcActionFlagType.parseFrom("2")); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/business/FtdcAvailabilityFlagTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.business.FtdcAvailabilityFlagType; 8 | 9 | public class FtdcAvailabilityFlagTypeTest { 10 | 11 | @Test 12 | public void testParseFrom() { 13 | assertEquals(FtdcAvailabilityFlagType.THOST_FTDC_Valid, FtdcAvailabilityFlagType.parseFrom("1")); 14 | assertEquals(null, FtdcAvailabilityFlagType.parseFrom("3")); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/enums/business/FtdcBankAccTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.enums.business; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.enums.business.FtdcBankAccType; 8 | 9 | public class FtdcBankAccTypeTest { 10 | 11 | @Test 12 | public void testParseFrom() { 13 | assertEquals(FtdcBankAccType.THOST_FTDCBAT_BankBook, FtdcBankAccType.parseFrom("1")); 14 | assertEquals(null, FtdcBankAccType.parseFrom("0")); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/ftdc/FtdcDecoderTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNull; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | import org.junit.Test; 8 | 9 | import com.ee.ctp.enums.FtdType; 10 | import com.ee.ctp.ftdc.FtdcDecoder; 11 | import com.ee.ctp.ftdc.FtdcProtocol; 12 | 13 | import io.netty.buffer.ByteBuf; 14 | import io.netty.buffer.Unpooled; 15 | import io.netty.channel.embedded.EmbeddedChannel; 16 | import io.netty.handler.codec.TooLongFrameException; 17 | 18 | public class FtdcDecoderTest { 19 | 20 | @Test 21 | public void testNoExt() { 22 | ByteBuf buf = Unpooled.buffer(); 23 | buf.writeByte(2); 24 | buf.writeByte(0); 25 | buf.writeShort(22); 26 | buf.writeZero(22); 27 | EmbeddedChannel channel = new EmbeddedChannel(new FtdcDecoder()); 28 | channel.writeInbound(buf); 29 | 30 | assertTrue(channel.finish()); 31 | 32 | FtdcProtocol ftdcProtocol = channel.readInbound(); 33 | assertEquals(FtdType.FTDTypeCompressed, ftdcProtocol.getType()); 34 | assertEquals(22, ftdcProtocol.getBodyLength()); 35 | assertEquals(0, ftdcProtocol.getExtLength()); 36 | assertNull(channel.readInbound()); 37 | channel.finish(); 38 | } 39 | 40 | @Test 41 | public void testWithExt() { 42 | ByteBuf buf = Unpooled.buffer(); 43 | buf.writeByte(2); 44 | buf.writeByte(3); 45 | buf.writeShort(22); 46 | buf.writeByte(1); 47 | buf.writeByte(1); 48 | buf.writeByte(1); 49 | buf.writeZero(22); 50 | EmbeddedChannel channel = new EmbeddedChannel(new FtdcDecoder()); 51 | channel.writeInbound(buf); 52 | 53 | assertTrue(channel.finish()); 54 | 55 | FtdcProtocol ftdcProtocol = channel.readInbound(); 56 | assertEquals(FtdType.FTDTypeCompressed, ftdcProtocol.getType()); 57 | assertEquals(22, ftdcProtocol.getBodyLength()); 58 | assertEquals(3, ftdcProtocol.getExtLength()); 59 | assertEquals(1, ftdcProtocol.ext().getTagType()); 60 | 61 | assertNull(channel.readInbound()); 62 | channel.finish(); 63 | } 64 | 65 | @Test(expected = TooLongFrameException.class) 66 | public void testTooLongFrameException() { 67 | ByteBuf buf = Unpooled.buffer(); 68 | buf.writeByte(2); 69 | buf.writeByte(3); 70 | buf.writeShort(65535); 71 | buf.writeByte(1); 72 | buf.writeByte(1); 73 | buf.writeByte(1); 74 | buf.writeZero(65535); 75 | EmbeddedChannel channel = new EmbeddedChannel(new FtdcDecoder()); 76 | channel.writeInbound(buf); 77 | 78 | assertTrue(channel.finish()); 79 | 80 | FtdcProtocol ftdcProtocol = channel.readInbound(); 81 | assertEquals(FtdType.FTDTypeCompressed, ftdcProtocol.getType()); 82 | assertEquals(22, ftdcProtocol.getBodyLength()); 83 | assertEquals(0, ftdcProtocol.getExtLength()); 84 | assertNull(channel.readInbound()); 85 | channel.finish(); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/ftdc/FtdcEncoderTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNull; 5 | import static org.junit.Assert.assertTrue; 6 | 7 | import org.junit.Test; 8 | 9 | import com.ee.ctp.enums.FtdTagType; 10 | import com.ee.ctp.enums.FtdType; 11 | import com.ee.ctp.ftdc.FtdcEncoder; 12 | import com.ee.ctp.ftdc.FtdcProtocol; 13 | 14 | import io.netty.buffer.ByteBuf; 15 | import io.netty.channel.embedded.EmbeddedChannel; 16 | 17 | public class FtdcEncoderTest { 18 | 19 | @Test 20 | public void testEncoder() { 21 | FtdcProtocol protocol = new FtdcProtocol(FtdType.FTDTypeFTDC); 22 | FtdTagType tagType = FtdTagType.FTDTagKeepAlive; 23 | protocol.addExt(tagType.type(), tagType.length(), 0); 24 | EmbeddedChannel channel = new EmbeddedChannel(new FtdcEncoder()); 25 | channel.writeOutbound(protocol); 26 | 27 | assertTrue(channel.finish()); 28 | 29 | ByteBuf buf = channel.readOutbound(); 30 | assertEquals(1, buf.readByte()); 31 | assertEquals(2, buf.readByte()); 32 | assertEquals(0, buf.readShort()); 33 | assertEquals(0x05, buf.readByte()); 34 | assertEquals(0, buf.readByte()); 35 | assertTrue(!buf.isReadable()); 36 | assertNull(channel.readInbound()); 37 | channel.finish(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/ftdc/FtdcProtocolTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.ftdc; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | import org.junit.Test; 7 | 8 | import com.ee.ctp.dto.ReqUserLogin; 9 | import com.ee.ctp.enums.FtdTagType; 10 | import com.ee.ctp.enums.FtdType; 11 | import com.ee.ctp.enums.FtdcType; 12 | import com.ee.ctp.enums.Sequence; 13 | import com.ee.ctp.enums.TID; 14 | import com.ee.ctp.ftdc.FtdcProtocol; 15 | 16 | import io.netty.buffer.ByteBuf; 17 | import io.netty.buffer.Unpooled; 18 | 19 | public class FtdcProtocolTest { 20 | 21 | @Test 22 | public void testWrite() { 23 | ByteBuf buffer = Unpooled.buffer(); 24 | ReqUserLogin reqUserLogin = new ReqUserLogin(); 25 | reqUserLogin.setBrokerID("9999"); 26 | reqUserLogin.setPasswd("12345678"); 27 | reqUserLogin.write(buffer.retain()); 28 | 29 | FtdcProtocol ftdcProtocol = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(), 1, 30 | TID.UserLoginReq.id(), Sequence.UserLogin); 31 | 32 | ByteBuf buffer2 = Unpooled.buffer(); 33 | ftdcProtocol.write(buffer2.retain()); 34 | 35 | assertEquals(2, buffer2.readUnsignedByte()); 36 | assertEquals(0, buffer2.readUnsignedByte()); 37 | assertEquals(290, buffer2.readUnsignedShort()); 38 | } 39 | 40 | @Test 41 | public void testWriteAndRead() { 42 | ByteBuf buffer = Unpooled.buffer(); 43 | ReqUserLogin reqUserLogin = new ReqUserLogin(); 44 | reqUserLogin.setBrokerID("9999"); 45 | reqUserLogin.setPasswd("12345678"); 46 | reqUserLogin.setUserId("1"); 47 | reqUserLogin.write(buffer.retain()); 48 | 49 | FtdcProtocol ftdcProtocol = new FtdcProtocol(FtdType.FTDTypeCompressed, buffer, FtdcType.REQ.type(), 1, 50 | TID.UserLoginReq.id(), Sequence.UserLogin); 51 | 52 | ByteBuf buffer2 = Unpooled.buffer(); 53 | ftdcProtocol.write(buffer2.retain()); 54 | 55 | ByteBuf byteBuf = buffer2.slice(26 + 4, buffer2.readableBytes()); 56 | byte[] t1 = new byte[9]; 57 | byteBuf.readBytes(t1); 58 | assertEquals("", StringUtils.trimToEmpty(new String(t1))); 59 | byte[] t2 = new byte[11]; 60 | byteBuf.readBytes(t2); 61 | assertEquals("9999", StringUtils.trimToEmpty(new String(t2))); 62 | byte[] t3 = new byte[16]; 63 | byteBuf.readBytes(t3); 64 | assertEquals("1", StringUtils.trimToEmpty(new String(t3))); 65 | byte[] t4 = new byte[41]; 66 | byteBuf.readBytes(t4); 67 | assertEquals("12345678", StringUtils.trimToEmpty(new String(t4))); 68 | } 69 | 70 | @Test 71 | public void testAddExt() { 72 | FtdcProtocol ftdcProtocol = new FtdcProtocol(FtdType.FTDTypeNone); 73 | FtdTagType tagType = FtdTagType.FTDTagKeepAlive; 74 | ftdcProtocol.addExt(tagType.type(), tagType.length(), 0); 75 | 76 | assertEquals(tagType.type(), ftdcProtocol.ext().getTagType()); 77 | } 78 | 79 | @Test 80 | public void testCompress() { 81 | byte[] b = new byte[] {1, 3, 12, 76, 0, 0, 0, 0, 48, 1, 0, 0, 0, 1, 0, 1, 0, -11, 0, 0, 20, 122, 0, 0, 0, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 48, 49, 55, 48, 49, 48, 49, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 57, 57, 57, 57, 0, 0, 0, 0, 0, 0, 0, 48, 57, 49, 53, 56, 53, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 111, 99, 107, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 4, 106, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 49, 51, 58, 49, 50, 58, 49, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 82 | ByteBuf wrappedBuffer = Unpooled.wrappedBuffer(b); 83 | ByteBuf compress = compress(wrappedBuffer); 84 | ByteBuf uncompress = uncompress(compress); 85 | System.out.println(); 86 | assertEquals(b.length, uncompress.readableBytes()); 87 | } 88 | 89 | private ByteBuf uncompress(ByteBuf bodyBuf) { 90 | ByteBuf buffer = Unpooled.buffer(); 91 | for(;bodyBuf.readerIndex() < bodyBuf.writerIndex();) { 92 | short b = bodyBuf.readUnsignedByte(); 93 | if((b >> 4) != 14) { 94 | buffer.writeByte(b); 95 | }else { 96 | int size = b & 15; 97 | if(size == 0) { 98 | buffer.writeByte(bodyBuf.readByte()); 99 | } else { 100 | buffer.writeZero(size); 101 | } 102 | } 103 | } 104 | return buffer; 105 | } 106 | 107 | private ByteBuf compress(ByteBuf buf) { 108 | ByteBuf compressedBuffer = Unpooled.buffer(); 109 | for(;buf.readerIndex() < buf.writerIndex();) { 110 | short temp; 111 | int size = 0; 112 | while((temp = buf.readUnsignedByte()) == 0 && buf.readerIndex() < buf.writerIndex() && size < 0x0f) { 113 | size ++; 114 | } 115 | if(buf.readerIndex() >= buf.writerIndex()) { 116 | compressedBuffer.writeZero(1); 117 | } 118 | 119 | if(size == 0x0f) { 120 | buf.readerIndex(buf.readerIndex() - 1); 121 | } 122 | if(size != 0) { 123 | compressedBuffer.writeByte(0xe0 + (size & 0xff)); 124 | } 125 | if(temp != 0) { 126 | if((temp >> 4) == 14) { 127 | compressedBuffer.writeByte(0xe0); 128 | } 129 | compressedBuffer.writeByte(temp); 130 | } 131 | } 132 | return compressedBuffer; 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /src/test/java/com/ee/ctp/security/KAESTest.java: -------------------------------------------------------------------------------- 1 | package com.ee.ctp.security; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import org.junit.Test; 6 | 7 | import com.ee.ctp.security.KAES; 8 | 9 | public class KAESTest { 10 | 11 | @Test 12 | public void testEncrypt() { 13 | String key = "DAGET0Q2VRCT1B0J"; 14 | byte[] src = new byte[] { 15 | 0x79,0x4d,0x77,0x42,0x69,0x64,0x35,0x65,0x33,0x58,0x48,0x6b,0x69,0x4f,0x55,0x74, 16 | 0x4d,0x69,0x63,0x63,0x4b,0x30,0x78,0x74,0x38,0x4b,0x79,0x4f,0x31,0x48,0x6b,0x78, 17 | 0x74,0x50,0x36,0x4c,0x30,0x39,0x59,0x33,0x34,0x46,0x6f,0x6e,0x74,0x67,0x4f,0x66, 18 | 0x77,0x31,0x71,0x67,0x5a,0x58,0x48,0x37,0x46,0x66,0x54,0x45,0x57,0x65,0x62,0x6f, 19 | 0x31,0x66,0x37,0x31,0x6f,0x35,0x35,0x74,0x49,0x72,0x4f,0x61,0x48,0x43,0x6e,0x64, 20 | 0x42,0x4e,0x74,0x42,0x49,0x61,0x47,0x6c,0x70,0x41,0x5a,0x6b,0x4d,0x38,0x47,0x4e, 21 | 0x6e,0x4e,0x4f,0x4d,0x52,0x52,0x64,0x78,0x69,0x31,0x46,0x5a,0x42,0x33,0x63,0x64, 22 | 0x4f,0x44,0x4f,0x76,0x4c,0x73,0x51,0x39,0x32,0x51,0x74,0x4d,0x59,0x37,0x7a,0x6b 23 | }; 24 | 25 | byte[] result = new byte[] { 26 | 0x6f,0x50,0x36,0x4f,0x4c,0x49,0x44,0x4a,0x4f,0x53,0x50,0x6c,0x77,0x61,0x52,0x48, 27 | 0x69,0x31,0x75,0x48,0x6d,0x7a,0x65,0x4f,0x7a,0x77,0x7a,0x34,0x59,0x7a,0x52,0x55, 28 | 0x47,0x57,0x30,0x47,0x75,0x4e,0x79,0x51,0x39,0x6b,0x6e,0x56,0x52,0x52,0x56,0x38, 29 | 0x35,0x6f,0x54,0x55,0x76,0x75,0x50,0x38,0x47,0x39,0x34,0x54,0x6a,0x74,0x36,0x32, 30 | 0x6f,0x49,0x71,0x34,0x57,0x48,0x31,0x36,0x66,0x48,0x38,0x76,0x32,0x64,0x47,0x6d, 31 | 0x61,0x7a,0x52,0x42,0x37,0x35,0x51,0x62,0x5a,0x6f,0x62,0x34,0x77,0x5a,0x65,0x6f, 32 | 0x4d,0x75,0x4c,0x37,0x71,0x6d,0x5a,0x79,0x4a,0x38,0x4d,0x66,0x50,0x68,0x75,0x46, 33 | 0x36,0x71,0x74,0x5a,0x43,0x58,0x52,0x69,0x39,0x31,0x58,0x6e,0x78,0x51,0x30,0x62 34 | }; 35 | 36 | byte[] encrypt = KAES.DEFAULT_INSTANCE.encrypt(src, key.getBytes()); 37 | assertEquals(128, encrypt.length); 38 | assertEquals(new String(encrypt), new String(result)); 39 | } 40 | } 41 | --------------------------------------------------------------------------------