├── .gitignore ├── README.md ├── ScreenShots ├── flow.png ├── qrcode.png └── wechatqr.png ├── pom.xml └── src └── main ├── java └── com │ ├── okcoin │ └── commons │ │ └── okex │ │ └── open │ │ └── api │ │ ├── bean │ │ ├── account │ │ │ ├── param │ │ │ │ ├── Transfer.java │ │ │ │ └── Withdraw.java │ │ │ └── result │ │ │ │ ├── Currency.java │ │ │ │ ├── Ledger.java │ │ │ │ ├── Wallet.java │ │ │ │ └── WithdrawFee.java │ │ ├── ett │ │ │ ├── param │ │ │ │ └── EttCreateOrderParam.java │ │ │ └── result │ │ │ │ ├── CursorPager.java │ │ │ │ ├── EttAccount.java │ │ │ │ ├── EttCancelOrderResult.java │ │ │ │ ├── EttConstituents.java │ │ │ │ ├── EttConstituentsResult.java │ │ │ │ ├── EttCreateOrderResult.java │ │ │ │ ├── EttLedger.java │ │ │ │ ├── EttOrder.java │ │ │ │ └── EttSettlementDefinePrice.java │ │ ├── futures │ │ │ ├── CursorPageParams.java │ │ │ ├── HttpResult.java │ │ │ ├── param │ │ │ │ ├── CancelOrders.java │ │ │ │ ├── ClosePosition.java │ │ │ │ ├── Order.java │ │ │ │ ├── Orders.java │ │ │ │ └── OrdersItem.java │ │ │ └── result │ │ │ │ ├── Book.java │ │ │ │ ├── Currencies.java │ │ │ │ ├── EstimatedPrice.java │ │ │ │ ├── ExchangeRate.java │ │ │ │ ├── Holds.java │ │ │ │ ├── Index.java │ │ │ │ ├── Instruments.java │ │ │ │ ├── Liquidation.java │ │ │ │ ├── OrderResult.java │ │ │ │ ├── PriceLimit.java │ │ │ │ ├── ServerTime.java │ │ │ │ ├── Stats.java │ │ │ │ ├── Ticker.java │ │ │ │ └── Trades.java │ │ └── spot │ │ │ ├── param │ │ │ ├── LoanRequestDTO.java │ │ │ ├── MarginConfigRequestDTO.java │ │ │ ├── Order.java │ │ │ ├── OrderParamDto.java │ │ │ ├── PlaceOrderParam.java │ │ │ ├── RepayRequestDTO.java │ │ │ └── WithdrawalsParamDTO.java │ │ │ └── result │ │ │ ├── Account.java │ │ │ ├── BatchOrdersResult.java │ │ │ ├── Book.java │ │ │ ├── BorrowConfigDto.java │ │ │ ├── BorrowRequestDto.java │ │ │ ├── BorrowResult.java │ │ │ ├── Currency.java │ │ │ ├── CurrencyDto.java │ │ │ ├── Fills.java │ │ │ ├── KlineDto.java │ │ │ ├── Ledger.java │ │ │ ├── MarginAccountDetailDto.java │ │ │ ├── MarginAccountDto.java │ │ │ ├── MarginBorrowOrderDto.java │ │ │ ├── OrderInfo.java │ │ │ ├── OrderResult.java │ │ │ ├── Product.java │ │ │ ├── RepaymentRequestDto.java │ │ │ ├── RepaymentResult.java │ │ │ ├── ResponseResult.java │ │ │ ├── ServerTimeDto.java │ │ │ ├── Ticker.java │ │ │ ├── Trade.java │ │ │ └── UserMarginBillDto.java │ │ ├── client │ │ ├── APIClient.java │ │ ├── APICredentials.java │ │ ├── APIHttpClient.java │ │ ├── APIRetrofit.java │ │ └── ApiHttp.java │ │ ├── config │ │ └── APIConfiguration.java │ │ ├── constant │ │ └── APIConstants.java │ │ ├── enums │ │ ├── AlgorithmEnum.java │ │ ├── CharsetEnum.java │ │ ├── ContentTypeEnum.java │ │ ├── FuturesCurrenciesEnum.java │ │ ├── FuturesTransactionTypeEnum.java │ │ ├── HttpHeadersEnum.java │ │ ├── HttpMethodEnum.java │ │ ├── HttpStatusEnum.java │ │ └── I18nEnum.java │ │ ├── exception │ │ └── APIException.java │ │ ├── service │ │ ├── GeneralAPIService.java │ │ ├── account │ │ │ ├── AccountAPIService.java │ │ │ └── impl │ │ │ │ ├── AccountAPI.java │ │ │ │ └── AccountAPIServiceImpl.java │ │ ├── ett │ │ │ ├── EttAccountAPIService.java │ │ │ ├── EttOrderAPIService.java │ │ │ ├── EttProductAPIService.java │ │ │ └── impl │ │ │ │ ├── EttAccountAPI.java │ │ │ │ ├── EttAccountAPIServiceImpl.java │ │ │ │ ├── EttOrderAPI.java │ │ │ │ ├── EttOrderAPIServiceImpl.java │ │ │ │ ├── EttProductAPI.java │ │ │ │ └── EttProductAPIServiceImpl.java │ │ ├── futures │ │ │ ├── FuturesMarketAPIService.java │ │ │ ├── FuturesTradeAPIService.java │ │ │ └── impl │ │ │ │ ├── FuturesMarketAPI.java │ │ │ │ ├── FuturesMarketAPIServiceImpl.java │ │ │ │ ├── FuturesTradeAPI.java │ │ │ │ ├── FuturesTradeAPIServiceImpl.java │ │ │ │ └── GeneralAPIServiceImpl.java │ │ └── spot │ │ │ ├── MarginAccountAPIService.java │ │ │ ├── MarginOrderAPIService.java │ │ │ ├── SpotAccountAPIService.java │ │ │ ├── SpotOrderAPIServive.java │ │ │ ├── SpotProductAPIService.java │ │ │ └── impl │ │ │ ├── MarginAccountAPI.java │ │ │ ├── MarginAccountAPIServiceImpl.java │ │ │ ├── MarginOrderAPI.java │ │ │ ├── MarginOrderAPIServiceImpl.java │ │ │ ├── SpotAccountAPI.java │ │ │ ├── SpotAccountAPIServiceImpl.java │ │ │ ├── SpotOrderAPI.java │ │ │ ├── SpotOrderApiServiceImpl.java │ │ │ ├── SpotProductAPI.java │ │ │ └── SpotProductAPIServiceImpl.java │ │ └── utils │ │ ├── DateUtils.java │ │ ├── HmacSHA256Base64Utils.java │ │ ├── JsonUtils.java │ │ ├── NumberUtils.java │ │ └── OrderIdUtils.java │ ├── okex │ └── websocket │ │ ├── FutureAccount.java │ │ ├── FutureInstrument.java │ │ ├── FutureOrder.java │ │ ├── MD5Util.java │ │ ├── MoniterTask.java │ │ ├── OkexConstant.java │ │ ├── SpotInstrument.java │ │ ├── WebSocketBase.java │ │ └── WebSocketClientHandler.java │ └── xiang │ ├── controller │ ├── HedgingController.java │ ├── UserController.java │ └── XAuthToken.java │ ├── po │ └── User.java │ ├── service │ ├── BaseDataService.java │ ├── DepthService.java │ ├── FutureAccountService.java │ ├── FutureInstrumentService.java │ ├── HedgingDataService.java │ ├── HedgingService.java │ ├── Instrument.java │ ├── InstrumentService.java │ ├── InstrumentsDepthService.java │ ├── Level2Service.java │ ├── SpotInstrumentService.java │ ├── TradeApiService.java │ ├── WebSocketService.java │ └── impl │ │ ├── AccountConfig.java │ │ ├── ArrayDepthServiceImpl.java │ │ ├── BaseDataServiceImpl.java │ │ ├── Coin.java │ │ ├── CoinServiceImpl.java │ │ ├── FinishHedgingServiceImpl.java │ │ ├── FutureAccountServiceImpl.java │ │ ├── FutureInstrumentServiceImpl.java │ │ ├── Hedging.java │ │ ├── HedgingClient.java │ │ ├── HedgingConfig.java │ │ ├── HedgingConfigManager.java │ │ ├── HedgingContext.java │ │ ├── HedgingDataServiceImpl.java │ │ ├── HedgingManager.java │ │ ├── HedgingServiceImpl.java │ │ ├── HedgingTrade.java │ │ ├── HedgingTradeClient.java │ │ ├── InstrumentServiceImpl.java │ │ ├── InstrumentsDepth5ServiceImpl.java │ │ ├── InstrumentsDepthServiceImpl.java │ │ ├── Level2Bean.java │ │ ├── LoginServiceImpl.java │ │ ├── MsgCenterServiceImpl.java │ │ ├── SpotInstrumentServiceImpl.java │ │ ├── StartHedgingServiceImpl.java │ │ ├── StoreServiceImpl.java │ │ ├── SystemConfig.java │ │ ├── TradeApiServiceImpl.java │ │ ├── TradeManager.java │ │ ├── TradeServiceImpl.java │ │ ├── TreeDepthServiceImpl.java │ │ ├── VolumeManager.java │ │ └── WebSoketClient.java │ ├── shiro │ ├── JWTAuth.java │ ├── JWTCredentialsMatcher.java │ ├── JWTToken.java │ ├── JwtAuthFilter.java │ ├── JwtRealm.java │ ├── UserFormAuthenticationFilter.java │ └── UserRealm.java │ ├── spring │ ├── APIException.java │ ├── CorsFilter.java │ ├── ErrorCodes.java │ ├── FastJsonConfigExt.java │ ├── LogExecuteTime.java │ ├── LogTimeInterceptor.java │ ├── LoginToken.java │ ├── LoginTokenArgumentResolver.java │ ├── Response.java │ ├── ResponseAdvice.java │ └── SpringContextHolder.java │ ├── user │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ ├── util │ └── Constant.java │ └── vo │ └── UserVo.java ├── resources ├── development │ ├── ehcache.xml │ ├── system.properties │ └── user.properties ├── log4j2.xml ├── production │ ├── ehcache.xml │ ├── system.properties │ └── user.properties └── spring │ ├── spring-context-cache.xml │ ├── spring-context-config.xml │ ├── spring-context-shiro.xml │ └── springmvc.xml └── webapp ├── WEB-INF └── web.xml └── index.jsp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | #maven eclipse project 26 | target/ 27 | .project 28 | .classpath 29 | .settings 30 | .metadata -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OkexQuant 期货合约价差套利系统 2 | 3 | #### 项目介绍 4 | 本项目是在Okex平台提供的API v3基础上开发的一套数字货币期货合约套利系统,基本原理是当一个不同期的数字货币合约之间的价差产生异常比率,将进行同时开仓买入和开仓卖出交易,等待合约之间的价差回归正常比率,再进行同时的平仓卖出和平仓买入,从而产生利润。 5 | ##### 项目功能 6 | 1. 支持所有的okex合约币种 7 | 2. 支持多策略同时运行 8 | 3. 实时的合约行情 9 | 4. 不同用户的权限控制 10 | 11 | #### 项目github 12 | 1. 系统总共包括2个项目 13 | 2. [OkexQuant 后端服务 api](https://github.com/liudexiang3218/OkexQuant) 14 | 3. [OkexQuant_vue 前端界面项目](https://github.com/liudexiang3218/OkexQuant_vue) 15 | 16 | #### 软件架构 17 | 18 | 19 | 20 | #### 安装教程 21 | 22 | 1. 安装activeMQ 5的版本,到activeMQ bin目录,执行 activemq start 23 | 2. 下载项目 git clone https://github.com/liudexiang3218/OkexQuant.git 24 | 3. 导入eclipse 25 | 4. 修改配置文件system.properties 26 | 5. jetty:run项目 27 | 6. http://127.0.0.1:8088/index.jsp 28 | 29 | #### 使用说明 30 | 31 | 1. [在线demo](http://47.75.108.228) 香港阿里云服务器 32 | 2. 根据条件设置策略 33 | 3. 开启策略开始按钮 34 | 35 | #### 指数说明 36 | 37 | 1. 当周与次周指数 (当周委托买一价 - 次周委托卖一价 ) / 次周委托卖一价 *100 38 | 39 | #### system.properties配置说明 40 | 41 | 1. ``broker_url ``:activemq连接url 42 | 2. ``ok_websocket_url ``: okex ws连接url 43 | 3. ``ok_rest_url ``: okex api服务器连接 44 | 3. ``ok_api_key ``: 您的okex开发平台上申请的api key 45 | 4. ``ok_secret_key ``: 您的okex开发平台上申请的secret key 46 | 5. ``ok_passphrase ``: 您的okex开发平台上申请的passphrase 47 | 6. ``ok_coins ``: 配置项目支持的数字货币(例如:btc,ltc,eth,etc,btg,xrp,eos) 48 | 6. ``jwt_secret ``: JWT权限加密密钥 49 | 50 | #### user.properties系统用户配置 51 | 1. user=password 账号=密码 52 | 53 | #### 开发环境 54 | 55 | 1. eclipse-2018-12 56 | 2. maven 3.5.4 57 | 3. git 58 | 4. jetty 59 | 5. activeMQ 5.15.9 60 | 61 | #### 技术栈 62 | 1. springmvc 4.3.19 63 | 2. activemq 5.15.4 64 | 3. ehcache 2.10.6 65 | 4. java-jwt 3.4.1 66 | 5. shiro 1.4.0 67 | 68 | #### Donation 69 | If you find Element useful, you can buy us a cup of coffee 70 | 71 | donation 72 | 73 | #### 作者微信 74 | 75 | -------------------------------------------------------------------------------- /ScreenShots/flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liudexiang3218/OkexQuant/2e72f9e590c2e268a9ec6157c27565efb5eea83c/ScreenShots/flow.png -------------------------------------------------------------------------------- /ScreenShots/qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liudexiang3218/OkexQuant/2e72f9e590c2e268a9ec6157c27565efb5eea83c/ScreenShots/qrcode.png -------------------------------------------------------------------------------- /ScreenShots/wechatqr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liudexiang3218/OkexQuant/2e72f9e590c2e268a9ec6157c27565efb5eea83c/ScreenShots/wechatqr.png -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/param/Transfer.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.param; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Transfer { 6 | 7 | private String currency; 8 | 9 | private BigDecimal amount; 10 | 11 | private Integer from; 12 | 13 | private Integer to; 14 | 15 | private String sub_account; 16 | 17 | private Integer instrument_id; 18 | 19 | public String getCurrency() { 20 | return currency; 21 | } 22 | 23 | public void setCurrency(String currency) { 24 | this.currency = currency; 25 | } 26 | 27 | public BigDecimal getAmount() { 28 | return amount; 29 | } 30 | 31 | public void setAmount(BigDecimal amount) { 32 | this.amount = amount; 33 | } 34 | 35 | 36 | public String getSub_account() { 37 | return sub_account; 38 | } 39 | 40 | public void setSub_account(String sub_account) { 41 | this.sub_account = sub_account; 42 | } 43 | 44 | public Integer getFrom() { 45 | return from; 46 | } 47 | 48 | public void setFrom(Integer from) { 49 | this.from = from; 50 | } 51 | 52 | public Integer getTo() { 53 | return to; 54 | } 55 | 56 | public void setTo(Integer to) { 57 | this.to = to; 58 | } 59 | 60 | public Integer getInstrument_id() { 61 | return instrument_id; 62 | } 63 | 64 | public void setInstrument_id(Integer instrument_id) { 65 | this.instrument_id = instrument_id; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/param/Withdraw.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.param; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Withdraw { 6 | private BigDecimal amount; 7 | 8 | private String currency; 9 | 10 | private Integer destination; 11 | 12 | private String to_address; 13 | 14 | private String trade_pwd; 15 | 16 | private BigDecimal fee; 17 | 18 | private String tag; 19 | 20 | public BigDecimal getAmount() { 21 | return amount; 22 | } 23 | 24 | public void setAmount(BigDecimal amount) { 25 | this.amount = amount; 26 | } 27 | 28 | public String getCurrency() { 29 | return currency; 30 | } 31 | 32 | public void setCurrency(String currency) { 33 | this.currency = currency; 34 | } 35 | 36 | public String getTrade_pwd() { 37 | return trade_pwd; 38 | } 39 | 40 | public void setTrade_pwd(String trade_pwd) { 41 | this.trade_pwd = trade_pwd; 42 | } 43 | 44 | public BigDecimal getFee() { 45 | return fee; 46 | } 47 | 48 | public void setFee(BigDecimal fee) { 49 | this.fee = fee; 50 | } 51 | 52 | public Integer getDestination() { 53 | return destination; 54 | } 55 | 56 | public void setDestination(Integer destination) { 57 | this.destination = destination; 58 | } 59 | 60 | public String getTo_address() { 61 | return to_address; 62 | } 63 | 64 | public void setTo_address(String to_address) { 65 | this.to_address = to_address; 66 | } 67 | 68 | public String getTag() { 69 | return tag; 70 | } 71 | 72 | public void setTag(String tag) { 73 | this.tag = tag; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/result/Currency.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.result; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Currency { 6 | private String currency; 7 | 8 | private String name; 9 | 10 | private Integer can_withdraw; 11 | 12 | private Integer can_deposit; 13 | 14 | private BigDecimal min_withdrawal; 15 | 16 | public String getCurrency() { 17 | return currency; 18 | } 19 | 20 | public void setCurrency(String currency) { 21 | this.currency = currency; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Integer getCan_withdraw() { 33 | return can_withdraw; 34 | } 35 | 36 | public void setCan_withdraw(Integer can_withdraw) { 37 | this.can_withdraw = can_withdraw; 38 | } 39 | 40 | public Integer getCan_deposit() { 41 | return can_deposit; 42 | } 43 | 44 | public void setCan_deposit(Integer can_deposit) { 45 | this.can_deposit = can_deposit; 46 | } 47 | 48 | public BigDecimal getMin_withdrawal() { 49 | return min_withdrawal; 50 | } 51 | 52 | public void setMin_withdrawal(BigDecimal min_withdrawal) { 53 | this.min_withdrawal = min_withdrawal; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/result/Ledger.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.result; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Ledger { 6 | 7 | private Long ledger_id; 8 | 9 | private String currency; 10 | 11 | private BigDecimal balance; 12 | 13 | private BigDecimal amount; 14 | 15 | private BigDecimal fee; 16 | 17 | private String typeName; 18 | 19 | private String timestamp; 20 | 21 | 22 | public Long getLedger_id() { 23 | return ledger_id; 24 | } 25 | 26 | public void setLedger_id(Long ledger_id) { 27 | this.ledger_id = ledger_id; 28 | } 29 | 30 | public String getCurrency() { 31 | return currency; 32 | } 33 | 34 | public void setCurrency(String currency) { 35 | this.currency = currency; 36 | } 37 | 38 | public BigDecimal getBalance() { 39 | return balance; 40 | } 41 | 42 | public void setBalance(BigDecimal balance) { 43 | this.balance = balance; 44 | } 45 | 46 | public BigDecimal getAmount() { 47 | return amount; 48 | } 49 | 50 | public void setAmount(BigDecimal amount) { 51 | this.amount = amount; 52 | } 53 | 54 | public BigDecimal getFee() { 55 | return fee; 56 | } 57 | 58 | public void setFee(BigDecimal fee) { 59 | this.fee = fee; 60 | } 61 | 62 | public String getTypeName() { 63 | return typeName; 64 | } 65 | 66 | public void setTypeName(String typeName) { 67 | this.typeName = typeName; 68 | } 69 | 70 | public String getTimestamp() { 71 | return timestamp; 72 | } 73 | 74 | public void setTimestamp(String timestamp) { 75 | this.timestamp = timestamp; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/result/Wallet.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.result; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class Wallet { 6 | 7 | private String currency; 8 | 9 | private BigDecimal balance; 10 | 11 | private BigDecimal frozen; 12 | 13 | private BigDecimal available; 14 | 15 | public String getCurrency() { 16 | return currency; 17 | } 18 | 19 | public void setCurrency(String currency) { 20 | this.currency = currency; 21 | } 22 | 23 | public BigDecimal getBalance() { 24 | return balance; 25 | } 26 | 27 | public void setBalance(BigDecimal balance) { 28 | this.balance = balance; 29 | } 30 | 31 | public BigDecimal getFrozen() { 32 | return frozen; 33 | } 34 | 35 | public void setFrozen(BigDecimal frozen) { 36 | this.frozen = frozen; 37 | } 38 | 39 | public BigDecimal getAvailable() { 40 | return available; 41 | } 42 | 43 | public void setAvailable(BigDecimal available) { 44 | this.available = available; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/account/result/WithdrawFee.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.account.result; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class WithdrawFee { 6 | 7 | private BigDecimal min_fee; 8 | 9 | private BigDecimal max_fee; 10 | 11 | 12 | private String currency; 13 | 14 | public BigDecimal getMin_fee() { 15 | return min_fee; 16 | } 17 | 18 | public void setMin_fee(BigDecimal min_fee) { 19 | this.min_fee = min_fee; 20 | } 21 | 22 | public BigDecimal getMax_fee() { 23 | return max_fee; 24 | } 25 | 26 | public void setMax_fee(BigDecimal max_fee) { 27 | this.max_fee = max_fee; 28 | } 29 | 30 | public String getCurrency() { 31 | return currency; 32 | } 33 | 34 | public void setCurrency(String currency) { 35 | this.currency = currency; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/param/EttCreateOrderParam.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.param; 2 | 3 | import java.math.BigDecimal; 4 | 5 | /** 6 | * @author chuping.cui 7 | * @date 2018/7/5 8 | */ 9 | public class EttCreateOrderParam { 10 | private String ett; 11 | private Integer type; 12 | private BigDecimal amount; 13 | private BigDecimal size; 14 | private String clientOid; 15 | 16 | public String getEtt() { 17 | return ett; 18 | } 19 | 20 | public void setEtt(String ett) { 21 | this.ett = ett; 22 | } 23 | 24 | public Integer getType() { 25 | return type; 26 | } 27 | 28 | public void setType(Integer type) { 29 | this.type = type; 30 | } 31 | 32 | public BigDecimal getAmount() { 33 | return amount; 34 | } 35 | 36 | public void setAmount(BigDecimal amount) { 37 | this.amount = amount; 38 | } 39 | 40 | public BigDecimal getSize() { 41 | return size; 42 | } 43 | 44 | public void setSize(BigDecimal size) { 45 | this.size = size; 46 | } 47 | 48 | public String getClientOid() { 49 | return clientOid; 50 | } 51 | 52 | public void setClientOid(String clientOid) { 53 | this.clientOid = clientOid; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/CursorPager.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author chuping.cui 7 | * @date 2018/7/5 8 | */ 9 | public class CursorPager { 10 | 11 | private List data; 12 | private String before; 13 | private String after; 14 | private int limit; 15 | 16 | public List getData() { 17 | return data; 18 | } 19 | 20 | public void setData(List data) { 21 | this.data = data; 22 | } 23 | 24 | public String getBefore() { 25 | return before; 26 | } 27 | 28 | public void setBefore(String before) { 29 | this.before = before; 30 | } 31 | 32 | public String getAfter() { 33 | return after; 34 | } 35 | 36 | public void setAfter(String after) { 37 | this.after = after; 38 | } 39 | 40 | public int getLimit() { 41 | return limit; 42 | } 43 | 44 | public void setLimit(int limit) { 45 | this.limit = limit; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttAccount.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * @author chuping.cui 7 | * @date 2018/7/4 8 | */ 9 | public class EttAccount { 10 | 11 | private String currency; 12 | private String balance; 13 | private String holds; 14 | private String available; 15 | 16 | public String getCurrency() { 17 | return currency; 18 | } 19 | 20 | public void setCurrency(String currency) { 21 | this.currency = currency; 22 | } 23 | 24 | public String getBalance() { 25 | return balance; 26 | } 27 | 28 | public void setBalance(String balance) { 29 | this.balance = balance; 30 | } 31 | 32 | public String getHolds() { 33 | return holds; 34 | } 35 | 36 | public void setHolds(String holds) { 37 | this.holds = holds; 38 | } 39 | 40 | public String getAvailable() { 41 | return available; 42 | } 43 | 44 | public void setAvailable(String available) { 45 | this.available = available; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) { return true; } 51 | if (o == null || getClass() != o.getClass()) { return false; } 52 | EttAccount that = (EttAccount)o; 53 | return Objects.equals(currency, that.currency) && 54 | Objects.equals(balance, that.balance) && 55 | Objects.equals(holds, that.holds) && 56 | Objects.equals(available, that.available); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return Objects.hash(currency, balance, holds, available); 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "EttAccount{" + 67 | "currency='" + currency + '\'' + 68 | ", balance='" + balance + '\'' + 69 | ", holds='" + holds + '\'' + 70 | ", available='" + available + '\'' + 71 | '}'; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttCancelOrderResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | /** 4 | * @author chuping.cui 5 | * @date 2018/7/5 6 | */ 7 | public class EttCancelOrderResult { 8 | private Boolean result; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttConstituents.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Objects; 5 | 6 | /** 7 | * @author chuping.cui 8 | * @date 2018/7/5 9 | */ 10 | public class EttConstituents { 11 | 12 | private String currency; 13 | private BigDecimal amount; 14 | 15 | public String getCurrency() { 16 | return currency; 17 | } 18 | 19 | public void setCurrency(String currency) { 20 | this.currency = currency; 21 | } 22 | 23 | public BigDecimal getAmount() { 24 | return amount; 25 | } 26 | 27 | public void setAmount(BigDecimal amount) { 28 | this.amount = amount; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object o) { 33 | if (this == o) { return true; } 34 | if (o == null || getClass() != o.getClass()) { return false; } 35 | EttConstituents that = (EttConstituents)o; 36 | return Objects.equals(currency, that.currency) && 37 | Objects.equals(amount, that.amount); 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | return Objects.hash(currency, amount); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "EttConstituents{" + 48 | "currency='" + currency + '\'' + 49 | ", amount=" + amount + 50 | '}'; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttConstituentsResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | /** 8 | * @author chuping.cui 9 | * @date 2018/7/5 10 | */ 11 | public class EttConstituentsResult { 12 | private String ett; 13 | private BigDecimal net_value; 14 | private List constituents; 15 | 16 | public String getEtt() { 17 | return ett; 18 | } 19 | 20 | public void setEtt(String ett) { 21 | this.ett = ett; 22 | } 23 | 24 | public BigDecimal getNet_value() { 25 | return net_value; 26 | } 27 | 28 | public void setNet_value(BigDecimal net_value) { 29 | this.net_value = net_value; 30 | } 31 | 32 | public List getConstituents() { 33 | return constituents; 34 | } 35 | 36 | public void setConstituents(List constituents) { 37 | this.constituents = constituents; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) { return true; } 43 | if (o == null || getClass() != o.getClass()) { return false; } 44 | EttConstituentsResult that = (EttConstituentsResult)o; 45 | return Objects.equals(ett, that.ett) && 46 | Objects.equals(net_value, that.net_value) && 47 | Objects.equals(constituents, that.constituents); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return Objects.hash(ett, net_value, constituents); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "EttConstituentsResult{" + 58 | "ett='" + ett + '\'' + 59 | ", net_value=" + net_value + 60 | ", constituents=" + constituents + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttCreateOrderResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.util.Objects; 4 | 5 | /** 6 | * @author chuping.cui 7 | * @date 2018/7/5 8 | */ 9 | public class EttCreateOrderResult { 10 | 11 | private String order_id; 12 | private String client_oid; 13 | private Boolean result; 14 | 15 | public String getOrder_id() { 16 | return order_id; 17 | } 18 | 19 | public void setOrder_id(String order_id) { 20 | this.order_id = order_id; 21 | } 22 | 23 | public String getClient_oid() { 24 | return client_oid; 25 | } 26 | 27 | public void setClient_oid(String client_oid) { 28 | this.client_oid = client_oid; 29 | } 30 | 31 | public Boolean getResult() { 32 | return result; 33 | } 34 | 35 | public void setResult(Boolean result) { 36 | this.result = result; 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | if (this == o) { return true; } 42 | if (o == null || getClass() != o.getClass()) { return false; } 43 | EttCreateOrderResult that = (EttCreateOrderResult)o; 44 | return Objects.equals(order_id, that.order_id) && 45 | Objects.equals(client_oid, that.client_oid) && 46 | Objects.equals(result, that.result); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash(order_id, client_oid, result); 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "EttCreateOrderResult{" + 57 | "order_id='" + order_id + '\'' + 58 | ", client_oid='" + client_oid + '\'' + 59 | ", result=" + result + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/ett/result/EttSettlementDefinePrice.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.ett.result; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Objects; 5 | 6 | /** 7 | * @author chuping.cui 8 | * @date 2018/7/5 9 | */ 10 | public class EttSettlementDefinePrice { 11 | private String date; 12 | private BigDecimal price; 13 | 14 | public String getDate() { 15 | return date; 16 | } 17 | 18 | public void setDate(String date) { 19 | this.date = date; 20 | } 21 | 22 | public BigDecimal getPrice() { 23 | return price; 24 | } 25 | 26 | public void setPrice(BigDecimal price) { 27 | this.price = price; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object o) { 32 | if (this == o) { return true; } 33 | if (o == null || getClass() != o.getClass()) { return false; } 34 | EttSettlementDefinePrice that = (EttSettlementDefinePrice)o; 35 | return Objects.equals(date, that.date) && 36 | Objects.equals(price, that.price); 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return Objects.hash(date, price); 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "EttSettlementDefinePrice{" + 47 | "date=" + date + 48 | ", price=" + price + 49 | '}'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/CursorPageParams.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures; 2 | 3 | /** 4 | * Cursor pagination
5 | * Created by Tony Tian on 2018/2/26 19:55.
6 | */ 7 | public class CursorPageParams { 8 | /** 9 | * Request page before (newer) this pagination id. 10 | * eg: before=2, page number = 1. 11 | */ 12 | protected int before; 13 | /** 14 | * Request page after (older) this pagination id. 15 | * eg: after=2, page number = 3. 16 | */ 17 | protected int after; 18 | /** 19 | * Number of results per request. Maximum 100. (default 100) 20 | */ 21 | protected int limit; 22 | 23 | public int getBefore() { 24 | return before; 25 | } 26 | 27 | public void setBefore(int before) { 28 | this.before = before; 29 | } 30 | 31 | public int getAfter() { 32 | return after; 33 | } 34 | 35 | public void setAfter(int after) { 36 | this.after = after; 37 | } 38 | 39 | public int getLimit() { 40 | return limit; 41 | } 42 | 43 | public void setLimit(int limit) { 44 | this.limit = limit; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/HttpResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures; 2 | 3 | /** 4 | * Http Result 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 17/03/2018 11:36 9 | */ 10 | public class HttpResult { 11 | 12 | private int code; 13 | private String message; 14 | 15 | public int getCode() { 16 | return code; 17 | } 18 | 19 | public void setCode(int code) { 20 | this.code = code; 21 | } 22 | 23 | public String getMessage() { 24 | return message; 25 | } 26 | 27 | public void setMessage(String message) { 28 | this.message = message; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/param/CancelOrders.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.param; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Close Position 7 | * 8 | * @author wc.j 9 | * @version 1.0.0 10 | * @date 2018/10/19 16:54 11 | */ 12 | public class CancelOrders { 13 | 14 | public List getOrder_ids() { 15 | return order_ids; 16 | } 17 | 18 | public void setOrder_ids(List order_ids) { 19 | this.order_ids = order_ids; 20 | } 21 | 22 | List order_ids; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/param/ClosePosition.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.param; 2 | 3 | /** 4 | * Close Position 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/9 15:38 9 | */ 10 | public class ClosePosition { 11 | /** 12 | * The id of the futures, eg: BTC_USD_0331 13 | */ 14 | private String instrument_id; 15 | /** 16 | * The execution type {@link com.okcoin.commons.okex.open.api.enums.FuturesTransactionTypeEnum} 17 | */ 18 | private Integer type; 19 | 20 | public String getInstrument_id() { 21 | return instrument_id; 22 | } 23 | 24 | public void setInstrument_id(String instrument_id) { 25 | this.instrument_id = instrument_id; 26 | } 27 | 28 | public Integer getType() { 29 | return type; 30 | } 31 | 32 | public void setType(Integer type) { 33 | this.type = type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/param/Order.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.param; 2 | 3 | /** 4 | * New Order 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/9 15:38 9 | */ 10 | public class Order { 11 | /** 12 | * The id of the futures, eg: BTC-USD-180629 13 | */ 14 | protected String instrument_id; 15 | /** 16 | * lever, default 10. 17 | */ 18 | protected Double leverage; 19 | /** 20 | * You setting order id.(optional) 21 | */ 22 | private String client_oid; 23 | /** 24 | * The execution type {@link com.okcoin.commons.okex.open.api.enums.FuturesTransactionTypeEnum} 25 | */ 26 | private Integer type; 27 | /** 28 | * The order price: Maximum 1 million 29 | */ 30 | private Double price; 31 | /** 32 | * The order amount: Maximum 1 million 33 | */ 34 | private Integer size; 35 | /** 36 | * Match best counter party price (BBO)? 0: No 1: Yes If yes, the 'price' field is ignored 37 | */ 38 | private Integer match_price; 39 | 40 | public String getInstrument_id() { 41 | return instrument_id; 42 | } 43 | 44 | public void setinstrument_id(String instrument_id) { 45 | this.instrument_id = instrument_id; 46 | } 47 | 48 | 49 | public String getClient_oid() { 50 | return client_oid; 51 | } 52 | 53 | public void setClient_oid(String client_oid) { 54 | this.client_oid = client_oid; 55 | } 56 | public Double getLeverage() { 57 | return leverage; 58 | } 59 | 60 | public void setLeverage(Double leverage) { 61 | this.leverage = leverage; 62 | } 63 | 64 | public Integer getType() { 65 | return type; 66 | } 67 | 68 | public void setType(Integer type) { 69 | this.type = type; 70 | } 71 | 72 | public Double getPrice() { 73 | return price; 74 | } 75 | 76 | public void setPrice(Double price) { 77 | this.price = price; 78 | } 79 | 80 | public Integer getSize() { 81 | return size; 82 | } 83 | 84 | public void setSize(Integer size) { 85 | this.size = size; 86 | } 87 | 88 | public Integer getMatch_price() { 89 | return match_price; 90 | } 91 | 92 | public void setMatch_price(Integer match_price) { 93 | this.match_price = match_price; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/param/Orders.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.param; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * New Order 7 | * 8 | * @author Tony Tian 9 | * @version 1.0.0 10 | * @date 2018/3/9 15:38 11 | */ 12 | public class Orders { 13 | /** 14 | * The id of the futures, eg: BTC-USD-180629 15 | */ 16 | protected String instrument_id; 17 | 18 | 19 | /** 20 | * lever, default 10. 21 | */ 22 | protected Double leverage; 23 | 24 | /** 25 | * batch new order sub element 26 | */ 27 | List orders_data; 28 | 29 | public String getInstrument_id() { 30 | return instrument_id; 31 | } 32 | 33 | public void setinstrument_id(String instrument_id) { 34 | this.instrument_id = instrument_id; 35 | } 36 | 37 | public Double getLeverage() { 38 | return leverage; 39 | } 40 | 41 | public void setLeverage(Double leverage) { 42 | this.leverage = leverage; 43 | } 44 | 45 | public List getOrders_data() { 46 | return orders_data; 47 | } 48 | 49 | public void setOrders_data(List orders_data) { 50 | this.orders_data = orders_data; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/param/OrdersItem.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.param; 2 | 3 | /** 4 | * batch new order sub element
5 | * Created by Tony Tian on 2018/2/28 17:57.
6 | */ 7 | public class OrdersItem { 8 | /** 9 | * You setting order id. (optional) 10 | */ 11 | private String client_oid; 12 | /** 13 | * The execution type {@link com.okcoin.commons.okex.open.api.enums.FuturesTransactionTypeEnum} 14 | */ 15 | private Integer type; 16 | /** 17 | * The order price: Maximum 1 million 18 | */ 19 | private Double price; 20 | /** 21 | * The order amount: Maximum 1 million 22 | */ 23 | private Integer size; 24 | /** 25 | * Match best counter party price (BBO)? 0: No 1: Yes If yes, the 'price' field is ignored 26 | */ 27 | private Integer match_price; 28 | 29 | public String getClient_oid() { 30 | return client_oid; 31 | } 32 | 33 | public void setClient_oid(String client_oid) { 34 | this.client_oid = client_oid; 35 | } 36 | 37 | public Integer getType() { 38 | return type; 39 | } 40 | 41 | public void setType(Integer type) { 42 | this.type = type; 43 | } 44 | 45 | public Double getPrice() { 46 | return price; 47 | } 48 | 49 | public void setPrice(Double price) { 50 | this.price = price; 51 | } 52 | 53 | public Integer getSize() { 54 | return size; 55 | } 56 | 57 | public void setSize(Integer size) { 58 | this.size = size; 59 | } 60 | 61 | public Integer getMatch_price() { 62 | return match_price; 63 | } 64 | 65 | public void setMatch_price(Integer match_price) { 66 | this.match_price = match_price; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Book.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * futures contract product book 9 | * 10 | * @author Tony Tian 11 | * @version 1.0.0 12 | * @date 2018/3/12 15:14 13 | */ 14 | public class Book { 15 | 16 | /** 17 | * asks book 18 | */ 19 | JSONArray asks; 20 | /** 21 | * bids book 22 | */ 23 | JSONArray bids; 24 | /** 25 | * time 26 | */ 27 | String timestamp; 28 | 29 | public JSONArray getAsks() { return asks; } 30 | 31 | public void setAsks(JSONArray asks) { this.asks = asks; } 32 | 33 | public JSONArray getBids() { return bids; } 34 | 35 | public void setBids(JSONArray bids) { this.bids = bids; } 36 | 37 | public String getTimestamp() { return timestamp; } 38 | 39 | public void setTimestamp(String timestamp) { this.timestamp = timestamp; } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Currencies.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Contract currency
5 | * Created by Tony Tian on 2018/2/26 21:33.
6 | */ 7 | public class Currencies { 8 | /** 9 | * symbol 10 | */ 11 | private Integer id; 12 | /** 13 | * currency name 14 | */ 15 | private String name; 16 | /** 17 | * Minimum transaction quantity 18 | */ 19 | private Double min_size; 20 | 21 | public Integer getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Integer id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public Double getMin_size() { 38 | return min_size; 39 | } 40 | 41 | public void setMin_size(Double min_size) { 42 | this.min_size = min_size; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/EstimatedPrice.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Contract price estimate for delivery.
5 | * Created by Tony Tian on 2018/2/26 15:52.
6 | */ 7 | public class EstimatedPrice { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * Estimated price 14 | */ 15 | private Double settlement_price; 16 | /** 17 | * time 18 | */ 19 | private String timestamp; 20 | 21 | public String getTimestamp() { 22 | return timestamp; 23 | } 24 | 25 | public void setTimestamp(String timestamp) { 26 | this.timestamp = timestamp; 27 | } 28 | 29 | public String getInstrument_id() { return instrument_id; } 30 | 31 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 32 | 33 | public Double getSettlement_price() { return settlement_price; } 34 | 35 | public void setSettlement_price(Double settlement_price) { this.settlement_price = settlement_price; } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/ExchangeRate.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Exchange Rate 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/9 18:31 9 | */ 10 | public class ExchangeRate { 11 | /** 12 | * legal tender pairs 13 | */ 14 | private String product_id; 15 | /** 16 | * exchange rate 17 | */ 18 | private Double rate; 19 | 20 | public String getProduct_id() { 21 | return product_id; 22 | } 23 | 24 | public void setProduct_id(String product_id) { 25 | this.product_id = product_id; 26 | } 27 | 28 | public Double getRate() { 29 | return rate; 30 | } 31 | 32 | public void setRate(Double rate) { 33 | this.rate = rate; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Holds.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * All of contract position
5 | * Created by Tony Tian on 2018/2/26 16:14.
6 | */ 7 | public class Holds { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * all of position 14 | */ 15 | private Integer amount; 16 | 17 | private String timestamp; 18 | 19 | public String getInstrument_id() { return instrument_id; } 20 | 21 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 22 | 23 | public Integer getAmount() { 24 | return amount; 25 | } 26 | 27 | public void setAmount(Integer amount) { 28 | this.amount = amount; 29 | } 30 | 31 | public String getTimestamp() { 32 | return timestamp; 33 | } 34 | 35 | public void setTimestamp(String timestamp) { 36 | this.timestamp = timestamp; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Index.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * The index of futures contract product information
5 | * Created by Tony Tian on 2018/3/1 18:36.
6 | */ 7 | public class Index { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * index 14 | */ 15 | private Double index = 0.00D; 16 | /** 17 | * time 18 | */ 19 | private String timestamp; 20 | 21 | public String getInstrument_id() { return instrument_id; } 22 | 23 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 24 | 25 | public Double getIndex() { return index; } 26 | 27 | public void setIndex(Double index) { this.index = index; } 28 | 29 | public String getTimestamp() { 30 | return timestamp; 31 | } 32 | 33 | public void setTimestamp(String timestamp) { 34 | this.timestamp = timestamp; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Instruments.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * futures contract products
5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/2/26 10:49 9 | */ 10 | public class Instruments { 11 | /** 12 | * The id of the futures contract 13 | */ 14 | private String instrument_id; 15 | /** 16 | * Currency 17 | */ 18 | private String underlying_index; 19 | /** 20 | * Quote currency 21 | */ 22 | private String quote_currency; 23 | /** 24 | * Minimum amount: $ 25 | */ 26 | private Double tick_size; 27 | /** 28 | * Unit price per contract 29 | */ 30 | private Double contract_val; 31 | /** 32 | * Effect of time 33 | */ 34 | private String listing; 35 | /** 36 | * Settlement price 37 | */ 38 | private String delivery; 39 | /** 40 | * Minimum amount: cont 41 | */ 42 | private Double trade_increment; 43 | 44 | public String getInstrument_id() { return instrument_id; } 45 | 46 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 47 | 48 | 49 | public String getQuote_currency() { 50 | return quote_currency; 51 | } 52 | 53 | public void setQuote_currency(String quote_currency) { 54 | this.quote_currency = quote_currency; 55 | } 56 | 57 | public Double getTick_size() { return tick_size; } 58 | 59 | public void setTick_size(Double tick_size) { this.tick_size = tick_size; } 60 | 61 | public Double getContract_val() { 62 | return contract_val; 63 | } 64 | 65 | public void setContract_val(Double contract_val) { 66 | this.contract_val = contract_val; 67 | } 68 | 69 | public String getListing() { 70 | return listing; 71 | } 72 | 73 | public void setListing(String listing) { 74 | this.listing = listing; 75 | } 76 | 77 | public String getDelivery() { 78 | return delivery; 79 | } 80 | 81 | public void setDelivery(String delivery) { 82 | this.delivery = delivery; 83 | } 84 | 85 | public Double getTrade_increment() { 86 | return trade_increment; 87 | } 88 | 89 | public void setTrade_increment(Double trade_increment) { 90 | this.trade_increment = trade_increment; 91 | } 92 | 93 | public String getUnderlying_index() { return underlying_index; } 94 | 95 | public void setUnderlying_index(String underlying_index) { this.underlying_index = underlying_index; } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Liquidation.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * all of contract liquidation
5 | * Created by Tony Tian on 2018/2/26 16:36.
6 | */ 7 | public class Liquidation { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * order price 14 | */ 15 | private Double price; 16 | /** 17 | * order quantity(unit: contract) 18 | */ 19 | private Double size; 20 | /** 21 | * The execution type {@link com.okcoin.commons.okex.open.api.enums.FuturesTransactionTypeEnum} 22 | */ 23 | private Integer type; 24 | /** 25 | * user loss due to forced liquidation 26 | */ 27 | private Double loss; 28 | /** 29 | * create date 30 | */ 31 | private String created_at; 32 | 33 | public Double getPrice() { 34 | return price; 35 | } 36 | 37 | public void setPrice(Double price) { 38 | this.price = price; 39 | } 40 | 41 | public Integer getType() { 42 | return type; 43 | } 44 | 45 | public void setType(Integer type) { 46 | this.type = type; 47 | } 48 | 49 | public Double getLoss() { 50 | return loss; 51 | } 52 | 53 | public void setLoss(Double loss) { 54 | this.loss = loss; 55 | } 56 | 57 | public String getInstrument_id() { return instrument_id; } 58 | 59 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 60 | 61 | public Double getSize() { return size; } 62 | 63 | public void setSize(Double size) { this.size = size; } 64 | public String getCreated_at() { return created_at; } 65 | 66 | public void setCreated_at(String created_at) { this.created_at = created_at; } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/OrderResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * New Order Result 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/9 15:56 9 | */ 10 | public class OrderResult { 11 | /** 12 | * You setting order id. 13 | */ 14 | private String client_oid; 15 | /** 16 | * The order id provided by OKEx. 17 | */ 18 | private String order_id; 19 | /** 20 | * The Server processing results: true: successful, false: failure. 21 | */ 22 | private boolean result; 23 | 24 | private int error_code; 25 | private String error_message; 26 | 27 | public String getClient_oid() { 28 | return client_oid; 29 | } 30 | 31 | public void setClient_oid(String client_oid) { 32 | this.client_oid = client_oid; 33 | } 34 | 35 | public String getOrder_id() { 36 | return order_id; 37 | } 38 | 39 | public void setOrder_id(String order_id) { 40 | this.order_id = order_id; 41 | } 42 | 43 | public boolean isResult() { 44 | return result; 45 | } 46 | 47 | public void setResult(boolean result) { 48 | this.result = result; 49 | } 50 | 51 | public int getError_code() { 52 | return error_code; 53 | } 54 | 55 | public void setError_code(int error_code) { 56 | this.error_code = error_code; 57 | } 58 | 59 | public String getError_messsage() { 60 | return error_message; 61 | } 62 | 63 | public void setError_messsage(String error_messsage) { 64 | this.error_message = error_messsage; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/PriceLimit.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * The current limit of the contract.
5 | * Created by Tony Tian on 2018/2/26 16:21.
6 | */ 7 | public class PriceLimit { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * Highest price 14 | */ 15 | private Double highest; 16 | /** 17 | * Lowest price 18 | */ 19 | private Double lowest; 20 | 21 | private String timestamp; 22 | 23 | public String getInstrument_id() { 24 | return instrument_id; 25 | } 26 | 27 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 28 | 29 | public String getTimestamp() { return timestamp; } 30 | 31 | public void setTimestamp(String timestamp) { this.timestamp = timestamp; } 32 | 33 | public Double getHighest() { return highest; } 34 | 35 | public void setHighest(Double highest) { this.highest = highest; } 36 | 37 | public Double getLowest() { return lowest; } 38 | 39 | public void setLowest(Double lowest) { this.lowest = lowest; } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/ServerTime.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Time of the server running OKEX's REST API. 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/8 20:58 9 | */ 10 | public class ServerTime { 11 | private String iso; 12 | private String epoch; 13 | 14 | public String getIso() { 15 | return iso; 16 | } 17 | 18 | public void setIso(String iso) { 19 | this.iso = iso; 20 | } 21 | 22 | public String getEpoch() { 23 | return epoch; 24 | } 25 | 26 | public void setEpoch(String epoch) { 27 | this.epoch = epoch; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Stats.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Get 24 hours of contract data.
5 | * Created by Tony Tian on 2018/2/26 13:59.
6 | */ 7 | public class Stats { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String product_id; 12 | /** 13 | * Opening price 14 | */ 15 | private Double open; 16 | /** 17 | * 24 hours of highest price 18 | */ 19 | private Double high; 20 | /** 21 | * 24 hours of lowest price 22 | */ 23 | private Double low; 24 | /** 25 | * Volume of sheet 26 | */ 27 | private Double volume; 28 | 29 | public String getProduct_id() { 30 | return product_id; 31 | } 32 | 33 | public void setProduct_id(String product_id) { 34 | this.product_id = product_id; 35 | } 36 | 37 | public Double getOpen() { 38 | return open; 39 | } 40 | 41 | public void setOpen(Double open) { 42 | this.open = open; 43 | } 44 | 45 | public Double getHigh() { 46 | return high; 47 | } 48 | 49 | public void setHigh(Double high) { 50 | this.high = high; 51 | } 52 | 53 | public Double getLow() { 54 | return low; 55 | } 56 | 57 | public void setLow(Double low) { 58 | this.low = low; 59 | } 60 | 61 | public Double getVolume() { 62 | return volume; 63 | } 64 | 65 | public void setVolume(Double volume) { 66 | this.volume = volume; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Ticker.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * The latest data on the futures contract product
5 | * Created by Tony Tian on 2018/2/26 13;16.
6 | */ 7 | public class Ticker { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String instrument_id; 12 | /** 13 | * Buy first price 14 | */ 15 | private Double best_bid; 16 | /** 17 | * Sell first price 18 | */ 19 | private Double best_ask; 20 | /** 21 | * Highest price 22 | */ 23 | private Double high_24h; 24 | /** 25 | * Lowest price 26 | */ 27 | private Double low_24h; 28 | /** 29 | * Latest price 30 | */ 31 | private Double last; 32 | /** 33 | * Volume (recent 24 hours) 34 | */ 35 | private Double volume_24h; 36 | /** 37 | * timestamp 38 | */ 39 | private String timestamp; 40 | 41 | public String getInstrument_id() { return instrument_id; } 42 | 43 | public void setInstrument_id(String instrument_id) { this.instrument_id = instrument_id; } 44 | 45 | public Double getBest_bid() { 46 | return best_bid; 47 | } 48 | 49 | public void setBest_bid(Double best_bid) { 50 | this.best_bid = best_bid; 51 | } 52 | 53 | public Double getBest_ask() { 54 | return best_ask; 55 | } 56 | 57 | public void setBest_ask(Double best_ask) { 58 | this.best_ask = best_ask; 59 | } 60 | 61 | public Double getHigh_24h() { 62 | return high_24h; 63 | } 64 | 65 | public void setHigh_24h(Double high_24h) { 66 | this.high_24h = high_24h; 67 | } 68 | 69 | public Double getLow_24h() { 70 | return low_24h; 71 | } 72 | 73 | public void setLow_24h(Double low_24h) { 74 | this.low_24h = low_24h; 75 | } 76 | 77 | public Double getLast() { 78 | return last; 79 | } 80 | 81 | public void setLast(Double last) { 82 | this.last = last; 83 | } 84 | 85 | public Double getVolume_24h() { 86 | return volume_24h; 87 | } 88 | 89 | public void setVolume_24h(Double volume_24h) { 90 | this.volume_24h = volume_24h; 91 | } 92 | 93 | public String getTimestamp() { 94 | return timestamp; 95 | } 96 | 97 | public void setTimestamp(String timestamp) { 98 | this.timestamp = timestamp; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/futures/result/Trades.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.futures.result; 2 | 3 | /** 4 | * Get the latest transaction log information.
5 | * Created by Tony Tian on 2018/2/26 13:30.
6 | */ 7 | public class Trades { 8 | /** 9 | * The id of the futures contract 10 | */ 11 | private String trade_id; 12 | /** 13 | * Transaction type 14 | */ 15 | private String side; 16 | /** 17 | * Transaction price 18 | */ 19 | private Double price; 20 | /** 21 | * Transaction amount 22 | */ 23 | private Double qty; 24 | /** 25 | * Transaction date 26 | */ 27 | private String timestamp; 28 | 29 | 30 | 31 | public String getTrade_id() { return trade_id; } 32 | 33 | public void setTrade_id(String trade_id) { this.trade_id = trade_id; } 34 | 35 | public String getSide() { return side; } 36 | 37 | public void setSide(String side) { this.side = side; } 38 | 39 | 40 | public Double getPrice() { 41 | return price; 42 | } 43 | 44 | public void setPrice(Double price) { 45 | this.price = price; 46 | } 47 | 48 | public Double getQty() { 49 | return qty; 50 | } 51 | 52 | public void setQty(Double qty) { 53 | this.qty = qty; 54 | } 55 | 56 | public String getTimestamp() { return timestamp; } 57 | 58 | public void setTimestamp(String timestamp) { this.timestamp = timestamp; } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/LoanRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class LoanRequestDTO { 4 | private Integer productId; 5 | private Integer currencyId; 6 | private String amount; 7 | 8 | public Integer getProductId() { 9 | return this.productId; 10 | } 11 | 12 | public void setProductId(final Integer productId) { 13 | this.productId = productId; 14 | } 15 | 16 | public Integer getCurrencyId() { 17 | return this.currencyId; 18 | } 19 | 20 | public void setCurrencyId(final Integer currencyId) { 21 | this.currencyId = currencyId; 22 | } 23 | 24 | public String getAmount() { 25 | return this.amount; 26 | } 27 | 28 | public void setAmount(final String amount) { 29 | this.amount = amount; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/MarginConfigRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class MarginConfigRequestDTO { 4 | private Integer status; 5 | 6 | public Integer getStatus() { 7 | return this.status; 8 | } 9 | 10 | public void setStatus(final Integer status) { 11 | this.status = status; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/Order.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class Order { 4 | 5 | private String product_id; 6 | 7 | private String side; 8 | 9 | private String type; 10 | 11 | private String size; 12 | 13 | private String price; 14 | 15 | private String funds; 16 | 17 | private String client_oid; 18 | 19 | public String getClient_oid() { 20 | return client_oid; 21 | } 22 | 23 | public void setClient_oid(String client_oid) { 24 | this.client_oid = client_oid; 25 | } 26 | 27 | public String getProduct_id() { 28 | return product_id; 29 | } 30 | 31 | public void setProduct_id(String product_id) { 32 | this.product_id = product_id; 33 | } 34 | 35 | public String getSide() { 36 | return side; 37 | } 38 | 39 | public void setSide(String side) { 40 | this.side = side; 41 | } 42 | 43 | public String getType() { 44 | return type; 45 | } 46 | 47 | public void setType(String type) { 48 | this.type = type; 49 | } 50 | 51 | public String getSize() { 52 | return size; 53 | } 54 | 55 | public void setSize(String size) { 56 | this.size = size; 57 | } 58 | 59 | public String getPrice() { 60 | return price; 61 | } 62 | 63 | public void setPrice(String price) { 64 | this.price = price; 65 | } 66 | 67 | public String getFunds() { 68 | return funds; 69 | } 70 | 71 | public void setFunds(String funds) { 72 | this.funds = funds; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/OrderParamDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | import java.util.List; 4 | 5 | public class OrderParamDto { 6 | private String instrument_id; 7 | private List order_ids; 8 | 9 | public String getInstrument_id() { 10 | return this.instrument_id; 11 | } 12 | 13 | public void setInstrument_id(final String instrument_id) { 14 | this.instrument_id = instrument_id; 15 | } 16 | 17 | 18 | public List getOrder_ids() { 19 | return this.order_ids; 20 | } 21 | 22 | public void setOrder_ids(final List order_ids) { 23 | this.order_ids = order_ids; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/PlaceOrderParam.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class PlaceOrderParam { 4 | /** 5 | * 客户端下单 标示id 非必填 6 | */ 7 | private String client_oid; 8 | /** 9 | * 币对如 etc_eth 10 | */ 11 | private String instrument_id; 12 | /** 13 | * 买卖类型 buy/sell 14 | */ 15 | private String side; 16 | /** 17 | * 订单类型 限价单 limit 市价单 market 18 | */ 19 | private String type; 20 | /** 21 | * 交易数量 22 | */ 23 | private String size; 24 | /** 25 | * 限价单使用 价格 26 | */ 27 | private String price; 28 | /** 29 | * 市价单使用 价格 30 | */ 31 | private String notional; 32 | 33 | /** 34 | * 来源(web app ios android) 35 | */ 36 | private Byte source = 0; 37 | 38 | /** 39 | * 1币币交易 2杠杆交易 40 | */ 41 | private Byte margin_trading; 42 | 43 | public String getClient_oid() { 44 | return this.client_oid; 45 | } 46 | 47 | public void setClient_oid(final String client_oid) { 48 | this.client_oid = client_oid; 49 | } 50 | 51 | 52 | public String getInstrument_id() { 53 | return this.instrument_id; 54 | } 55 | 56 | public void setInstrument_id(final String instrument_id) { 57 | this.instrument_id = instrument_id; 58 | } 59 | 60 | public String getSide() { 61 | return this.side; 62 | } 63 | 64 | public void setSide(final String side) { 65 | this.side = side; 66 | } 67 | 68 | public String getType() { 69 | return this.type; 70 | } 71 | 72 | public void setType(final String type) { 73 | this.type = type; 74 | } 75 | 76 | public String getSize() { 77 | return this.size; 78 | } 79 | 80 | public void setSize(final String size) { 81 | this.size = size; 82 | } 83 | 84 | public String getPrice() { 85 | return this.price; 86 | } 87 | 88 | public void setPrice(final String price) { 89 | this.price = price; 90 | } 91 | 92 | 93 | public String getNotional() { 94 | return this.notional; 95 | } 96 | 97 | public void setNotional(final String notional) { 98 | this.notional = notional; 99 | } 100 | 101 | public Byte getSource() { 102 | return this.source; 103 | } 104 | 105 | public void setSource(final Byte source) { 106 | this.source = source; 107 | } 108 | 109 | 110 | public Byte getMargin_trading() { 111 | return this.margin_trading; 112 | } 113 | 114 | public void setMargin_trading(final Byte margin_trading) { 115 | this.margin_trading = margin_trading; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/RepayRequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class RepayRequestDTO { 4 | private Integer productId; 5 | private Integer currencyId; 6 | private String amount; 7 | private Long orderId; 8 | 9 | public Integer getProductId() { 10 | return this.productId; 11 | } 12 | 13 | public void setProductId(final Integer productId) { 14 | this.productId = productId; 15 | } 16 | 17 | public Integer getCurrencyId() { 18 | return this.currencyId; 19 | } 20 | 21 | public void setCurrencyId(final Integer currencyId) { 22 | this.currencyId = currencyId; 23 | } 24 | 25 | public String getAmount() { 26 | return this.amount; 27 | } 28 | 29 | public void setAmount(final String amount) { 30 | this.amount = amount; 31 | } 32 | 33 | public Long getOrderId() { 34 | return this.orderId; 35 | } 36 | 37 | public void setOrderId(final Long orderId) { 38 | this.orderId = orderId; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/param/WithdrawalsParamDTO.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.param; 2 | 3 | public class WithdrawalsParamDTO { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Account.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class Account { 4 | 5 | private String id; 6 | private String currency; 7 | private String balance; 8 | private String available; 9 | private String hold; 10 | 11 | public String getHold() { 12 | return this.hold; 13 | } 14 | 15 | public void setHold(final String hold) { 16 | this.hold = hold; 17 | } 18 | 19 | public String getId() { 20 | return this.id; 21 | } 22 | 23 | public void setId(final String id) { 24 | this.id = id; 25 | } 26 | 27 | public String getCurrency() { 28 | return this.currency; 29 | } 30 | 31 | public void setCurrency(final String currency) { 32 | this.currency = currency; 33 | } 34 | 35 | public String getBalance() { 36 | return this.balance; 37 | } 38 | 39 | public void setBalance(final String balance) { 40 | this.balance = balance; 41 | } 42 | 43 | public String getAvailable() { 44 | return this.available; 45 | } 46 | 47 | public void setAvailable(final String available) { 48 | this.available = available; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/BatchOrdersResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | import java.util.List; 4 | 5 | public class BatchOrdersResult { 6 | 7 | private boolean result; 8 | private List order_id; 9 | private String client_oid; 10 | 11 | public boolean isResult() { 12 | return this.result; 13 | } 14 | 15 | public void setResult(final boolean result) { 16 | this.result = result; 17 | } 18 | 19 | public List getOrder_id() { 20 | return this.order_id; 21 | } 22 | 23 | public void setOrder_id(final List order_id) { 24 | this.order_id = order_id; 25 | } 26 | 27 | public String getClient_oid() { 28 | return this.client_oid; 29 | } 30 | 31 | public void setClient_oid(final String client_oid) { 32 | this.client_oid = client_oid; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Book.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | import java.util.List; 4 | 5 | public class Book { 6 | private List asks; 7 | 8 | private List bids; 9 | 10 | public List getAsks() { 11 | return asks; 12 | } 13 | 14 | public void setAsks(List asks) { 15 | this.asks = asks; 16 | } 17 | 18 | public List getBids() { 19 | return bids; 20 | } 21 | 22 | public void setBids(List bids) { 23 | this.bids = bids; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/BorrowConfigDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class BorrowConfigDto { 4 | private String product_id; 5 | private String currency; 6 | private String available; 7 | private String rate; 8 | private String leverage_ratio; 9 | 10 | public String getProduct_id() { 11 | return this.product_id; 12 | } 13 | 14 | public void setProduct_id(final String product_id) { 15 | this.product_id = product_id; 16 | } 17 | 18 | public String getCurrency() { 19 | return this.currency; 20 | } 21 | 22 | public void setCurrency(final String currency) { 23 | this.currency = currency; 24 | } 25 | 26 | public String getAvailable() { 27 | return this.available; 28 | } 29 | 30 | public void setAvailable(final String available) { 31 | this.available = available; 32 | } 33 | 34 | public String getRate() { 35 | return this.rate; 36 | } 37 | 38 | public void setRate(final String rate) { 39 | this.rate = rate; 40 | } 41 | 42 | public String getLeverage_ratio() { 43 | return this.leverage_ratio; 44 | } 45 | 46 | public void setLeverage_ratio(final String leverage_ratio) { 47 | this.leverage_ratio = leverage_ratio; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/BorrowRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class BorrowRequestDto { 4 | private String instrument_id; 5 | private String currency; 6 | private String amount; 7 | 8 | public String getInstrument_id() { 9 | return this.instrument_id; 10 | } 11 | 12 | public void setInstrument_id(final String instrument_id) { 13 | this.instrument_id = instrument_id; 14 | } 15 | 16 | public String getCurrency() { 17 | return this.currency; 18 | } 19 | 20 | public void setCurrency(final String currency) { 21 | this.currency = currency; 22 | } 23 | 24 | public String getAmount() { 25 | return this.amount; 26 | } 27 | 28 | public void setAmount(final String amount) { 29 | this.amount = amount; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/BorrowResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | 4 | public class BorrowResult { 5 | 6 | private boolean result; 7 | private Long borrow_id; 8 | 9 | public boolean isResult() { 10 | return this.result; 11 | } 12 | 13 | public void setResult(final boolean result) { 14 | this.result = result; 15 | } 16 | 17 | public Long getBorrow_id() { 18 | return this.borrow_id; 19 | } 20 | 21 | public void setBorrow_id(final Long borrow_id) { 22 | this.borrow_id = borrow_id; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Currency.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class Currency { 4 | private String currency_id; 5 | private String name; 6 | 7 | public String getCurrency_id() { 8 | return this.currency_id; 9 | } 10 | 11 | public void setCurrency_id(final String currency_id) { 12 | this.currency_id = currency_id; 13 | } 14 | 15 | public String getName() { 16 | return this.name; 17 | } 18 | 19 | public void setName(final String name) { 20 | this.name = name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/CurrencyDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class CurrencyDto { 4 | private String currency_id; 5 | private String name; 6 | 7 | public String getCurrency_id() { 8 | return this.currency_id; 9 | } 10 | 11 | public void setCurrency_id(final String currency_id) { 12 | this.currency_id = currency_id; 13 | } 14 | 15 | public String getName() { 16 | return this.name; 17 | } 18 | 19 | public void setName(final String name) { 20 | this.name = name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/KlineDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class KlineDto { 4 | private String time; 5 | private String low; 6 | private String high; 7 | private String open; 8 | private String close; 9 | private String volume; 10 | 11 | public String getTime() { 12 | return this.time; 13 | } 14 | 15 | public void setTime(final String time) { 16 | this.time = time; 17 | } 18 | 19 | public String getLow() { 20 | return this.low; 21 | } 22 | 23 | public void setLow(final String low) { 24 | this.low = low; 25 | } 26 | 27 | public String getHigh() { 28 | return this.high; 29 | } 30 | 31 | public void setHigh(final String high) { 32 | this.high = high; 33 | } 34 | 35 | public String getOpen() { 36 | return this.open; 37 | } 38 | 39 | public void setOpen(final String open) { 40 | this.open = open; 41 | } 42 | 43 | public String getClose() { 44 | return this.close; 45 | } 46 | 47 | public void setClose(final String close) { 48 | this.close = close; 49 | } 50 | 51 | public String getVolume() { 52 | return this.volume; 53 | } 54 | 55 | public void setVolume(final String volume) { 56 | this.volume = volume; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Ledger.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class Ledger { 4 | 5 | private Long ledger_id; 6 | private String currency; 7 | private String amount; 8 | private String balance; 9 | private String type; 10 | private Details details; 11 | private String timestamp; 12 | 13 | public Long getLedger_id() { 14 | return this.ledger_id; 15 | } 16 | 17 | public void setLedger_id(final Long ledger_id) { 18 | this.ledger_id = ledger_id; 19 | } 20 | 21 | 22 | 23 | public String getCurrency() { 24 | return this.currency; 25 | } 26 | 27 | public void setCurrency(final String currency) { 28 | this.currency = currency; 29 | } 30 | 31 | public String getAmount() { 32 | return this.amount; 33 | } 34 | 35 | public void setAmount(final String amount) { 36 | this.amount = amount; 37 | } 38 | 39 | public String getBalance() { 40 | return this.balance; 41 | } 42 | 43 | public void setBalance(final String balance) { 44 | this.balance = balance; 45 | } 46 | 47 | public String getType() { 48 | return this.type; 49 | } 50 | 51 | public void setType(final String type) { 52 | this.type = type; 53 | } 54 | 55 | public Details getDetails() { 56 | return this.details; 57 | } 58 | 59 | public void setDetails(final Details details) { 60 | this.details = details; 61 | } 62 | 63 | public String getTimestamp() { 64 | return this.timestamp; 65 | } 66 | 67 | public void setTimestamp(final String timestamp) { 68 | this.timestamp = timestamp; 69 | } 70 | 71 | public static class Details { 72 | private Long order_id; 73 | private String instrument_id; 74 | 75 | public Long getOrder_id() { 76 | return this.order_id; 77 | } 78 | 79 | public void setOrder_id(final Long order_id) { 80 | this.order_id = order_id; 81 | } 82 | 83 | public String getInstrument_id() { 84 | return this.instrument_id; 85 | } 86 | 87 | public void setInstrument_id(final String instrument_id) { 88 | this.instrument_id = instrument_id; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/MarginAccountDetailDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class MarginAccountDetailDto { 4 | private String balance; 5 | private String available; 6 | private String holds; 7 | 8 | public String getBalance() { 9 | return this.balance; 10 | } 11 | 12 | public void setBalance(final String balance) { 13 | this.balance = balance; 14 | } 15 | 16 | public String getAvailable() { 17 | return this.available; 18 | } 19 | 20 | public void setAvailable(final String available) { 21 | this.available = available; 22 | } 23 | 24 | public String getHolds() { 25 | return this.holds; 26 | } 27 | 28 | public void setHolds(final String holds) { 29 | this.holds = holds; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/MarginAccountDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | import java.util.List; 4 | 5 | public class MarginAccountDto { 6 | private String product_id; 7 | private List detailDtos; 8 | 9 | public String getProduct_id() { 10 | return this.product_id; 11 | } 12 | 13 | public void setProduct_id(final String product_id) { 14 | this.product_id = product_id; 15 | } 16 | 17 | public List getDetailDtos() { 18 | return this.detailDtos; 19 | } 20 | 21 | public void setDetailDtos(final List detailDtos) { 22 | this.detailDtos = detailDtos; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/OrderResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class OrderResult { 4 | 5 | private boolean result; 6 | private Long order_id; 7 | private String client_oid; 8 | 9 | public String getClient_oid() { 10 | return this.client_oid; 11 | } 12 | 13 | public void setClient_oid(final String client_oid) { 14 | this.client_oid = client_oid; 15 | } 16 | 17 | public boolean isResult() { 18 | return this.result; 19 | } 20 | 21 | public void setResult(final boolean result) { 22 | this.result = result; 23 | } 24 | 25 | public Long getOrder_id() { 26 | return this.order_id; 27 | } 28 | 29 | public void setOrder_id(final Long order_id) { 30 | this.order_id = order_id; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Product.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class Product { 4 | 5 | private String product_id; 6 | private String base_currency; 7 | private String quote_currency; 8 | private String min_size; 9 | private String size_increment; 10 | private String tick_size; 11 | 12 | private String base_min_size; 13 | private String base_increment; 14 | private String quote_increment; 15 | private String instrument_id; 16 | 17 | public String getInstrument_id() { 18 | return this.instrument_id; 19 | } 20 | 21 | public void setInstrument_id(final String instrument_id) { 22 | this.instrument_id = instrument_id; 23 | } 24 | 25 | public String getMin_size() { 26 | return this.min_size; 27 | } 28 | 29 | public void setMin_size(final String min_size) { 30 | this.min_size = min_size; 31 | } 32 | 33 | public String getSize_increment() { 34 | return this.size_increment; 35 | } 36 | 37 | public void setSize_increment(final String size_increment) { 38 | this.size_increment = size_increment; 39 | } 40 | 41 | public String getTick_size() { 42 | return this.tick_size; 43 | } 44 | 45 | public void setTick_size(final String tick_size) { 46 | this.tick_size = tick_size; 47 | } 48 | 49 | public String getBase_increment() { 50 | return this.base_increment; 51 | } 52 | 53 | public void setBase_increment(final String base_increment) { 54 | this.base_increment = base_increment; 55 | } 56 | 57 | public String getProduct_id() { 58 | return this.product_id; 59 | } 60 | 61 | public void setProduct_id(final String product_id) { 62 | this.product_id = product_id; 63 | } 64 | 65 | public String getBase_currency() { 66 | return this.base_currency; 67 | } 68 | 69 | public void setBase_currency(final String base_currency) { 70 | this.base_currency = base_currency; 71 | } 72 | 73 | public String getQuote_currency() { 74 | return this.quote_currency; 75 | } 76 | 77 | public void setQuote_currency(final String quote_currency) { 78 | this.quote_currency = quote_currency; 79 | } 80 | 81 | public String getBase_min_size() { 82 | return this.base_min_size; 83 | } 84 | 85 | public void setBase_min_size(final String base_min_size) { 86 | this.base_min_size = base_min_size; 87 | } 88 | 89 | 90 | 91 | public String getQuote_increment() { 92 | return this.quote_increment; 93 | } 94 | 95 | public void setQuote_increment(final String quote_increment) { 96 | this.quote_increment = quote_increment; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/RepaymentRequestDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class RepaymentRequestDto { 4 | private String instrument_id; 5 | private String currency; 6 | private String amount; 7 | private String borrow_id; 8 | 9 | public String getInstrument_id() { 10 | return this.instrument_id; 11 | } 12 | 13 | public void setInstrument_id(final String instrument_id) { 14 | this.instrument_id = instrument_id; 15 | } 16 | 17 | public String getCurrency() { 18 | return this.currency; 19 | } 20 | 21 | public void setCurrency(final String currency) { 22 | this.currency = currency; 23 | } 24 | 25 | public String getAmount() { 26 | return this.amount; 27 | } 28 | 29 | public void setAmount(final String amount) { 30 | this.amount = amount; 31 | } 32 | 33 | public String getBorrow_id() { 34 | return this.borrow_id; 35 | } 36 | 37 | public void setBorrow_id(final String borrow_id) { 38 | this.borrow_id = borrow_id; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/RepaymentResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | 4 | public class RepaymentResult { 5 | 6 | private boolean result; 7 | private Long repayment_id; 8 | 9 | public boolean isResult() { 10 | return this.result; 11 | } 12 | 13 | public void setResult(final boolean result) { 14 | this.result = result; 15 | } 16 | 17 | public Long getRepayment_id() { 18 | return this.repayment_id; 19 | } 20 | 21 | public void setRepayment_id(final Long repayment_id) { 22 | this.repayment_id = repayment_id; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | import java.io.Serializable; 4 | 5 | public class ResponseResult implements Serializable { 6 | 7 | private final T data; 8 | 9 | private ResponseResult(final T data) { 10 | this.data = data; 11 | } 12 | 13 | public static ResponseResult success() { 14 | return ResponseResult.success(new Object()); 15 | } 16 | 17 | public static ResponseResult success(final T data) { 18 | return ResponseResult.build(data); 19 | } 20 | 21 | public static ResponseResult build(final T data) { 22 | return new ResponseResult(data); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/ServerTimeDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class ServerTimeDto { 4 | private Long epoch; 5 | private String iso; 6 | 7 | public Long getEpoch() { 8 | return epoch; 9 | } 10 | 11 | public void setEpoch(Long epoch) { 12 | this.epoch = epoch; 13 | } 14 | 15 | public String getIso() { 16 | return iso; 17 | } 18 | 19 | public void setIso(String iso) { 20 | this.iso = iso; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/Trade.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class Trade { 4 | private String timestamp; 5 | private Integer trade_id; 6 | private String price; 7 | private String size; 8 | private String side; 9 | private String time; 10 | 11 | public String getTimestamp() { 12 | return this.timestamp; 13 | } 14 | 15 | public void setTimestamp(final String timestamp) { 16 | this.timestamp = timestamp; 17 | } 18 | 19 | public Integer getTrade_id() { 20 | return this.trade_id; 21 | } 22 | 23 | public void setTrade_id(final Integer trade_id) { 24 | this.trade_id = trade_id; 25 | } 26 | 27 | public String getPrice() { 28 | return this.price; 29 | } 30 | 31 | public void setPrice(final String price) { 32 | this.price = price; 33 | } 34 | 35 | public String getSize() { 36 | return this.size; 37 | } 38 | 39 | public void setSize(final String size) { 40 | this.size = size; 41 | } 42 | 43 | public String getSide() { 44 | return this.side; 45 | } 46 | 47 | public void setSide(final String side) { 48 | this.side = side; 49 | } 50 | 51 | public String getTime() { 52 | return this.time; 53 | } 54 | 55 | public void setTime(final String time) { 56 | this.time = time; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/bean/spot/result/UserMarginBillDto.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.bean.spot.result; 2 | 3 | public class UserMarginBillDto { 4 | private Long ledger_id; 5 | private String timestamp; 6 | private String amount; 7 | private String balance; 8 | private String type; 9 | private UserMarginBillDto.Details details; 10 | 11 | public String getTimestamp() { 12 | return this.timestamp; 13 | } 14 | 15 | public void setTimestamp(final String timestamp) { 16 | this.timestamp = timestamp; 17 | } 18 | 19 | public Long getLedger_id() { 20 | return this.ledger_id; 21 | } 22 | 23 | public void setLedger_id(final Long ledger_id) { 24 | this.ledger_id = ledger_id; 25 | } 26 | 27 | 28 | public String getAmount() { 29 | return this.amount; 30 | } 31 | 32 | public void setAmount(final String amount) { 33 | this.amount = amount; 34 | } 35 | 36 | public String getBalance() { 37 | return this.balance; 38 | } 39 | 40 | public void setBalance(final String balance) { 41 | this.balance = balance; 42 | } 43 | 44 | public String getType() { 45 | return this.type; 46 | } 47 | 48 | public void setType(final String type) { 49 | this.type = type; 50 | } 51 | 52 | public UserMarginBillDto.Details getDetails() { 53 | return this.details; 54 | } 55 | 56 | public void setDetails(final UserMarginBillDto.Details details) { 57 | this.details = details; 58 | } 59 | 60 | public static class Details { 61 | private Long order_id; 62 | private String instrument_id; 63 | 64 | public Long getOrder_id() { 65 | return this.order_id; 66 | } 67 | 68 | public void setOrder_id(final Long order_id) { 69 | this.order_id = order_id; 70 | } 71 | 72 | public String getInstrument_id() { 73 | return this.instrument_id; 74 | } 75 | 76 | public void setInstrument_id(final String instrument_id) { 77 | this.instrument_id = instrument_id; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/client/APICredentials.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.client; 2 | 3 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 4 | 5 | /** 6 | * API Credentials.
7 | * The api key and secret key will be randomly generated and provided by okex.com. 8 | * 9 | * @author Tony Tian 10 | * @version 1.0.0 11 | * @date 2018/3/8 14:14 12 | */ 13 | public class APICredentials { 14 | /** 15 | * The user's secret key provided by OKEx. 16 | */ 17 | private String apiKey; 18 | /** 19 | * The private key used to sign your request data. 20 | */ 21 | private String secretKey; 22 | /** 23 | * The Passphrase will be provided by you to further secure your API access. 24 | */ 25 | private String passphrase; 26 | 27 | 28 | public APICredentials(APIConfiguration config) { 29 | super(); 30 | this.apiKey = config.getApiKey(); 31 | this.secretKey = config.getSecretKey(); 32 | this.passphrase = config.getPassphrase(); 33 | } 34 | 35 | public String getApiKey() { 36 | return apiKey; 37 | } 38 | 39 | public void setApiKey(String apiKey) { 40 | this.apiKey = apiKey; 41 | } 42 | 43 | public String getSecretKey() { 44 | return secretKey; 45 | } 46 | 47 | public void setSecretKey(String secretKey) { 48 | this.secretKey = secretKey; 49 | } 50 | 51 | public String getPassphrase() { 52 | return passphrase; 53 | } 54 | 55 | public void setPassphrase(String passphrase) { 56 | this.passphrase = passphrase; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/client/APIRetrofit.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.client; 2 | 3 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 4 | import okhttp3.OkHttpClient; 5 | import retrofit2.Retrofit; 6 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 7 | import retrofit2.converter.gson.GsonConverterFactory; 8 | import retrofit2.converter.scalars.ScalarsConverterFactory; 9 | 10 | /** 11 | * API Retrofit 12 | * 13 | * @author Tony Tian 14 | * @version 1.0.0 15 | * @date 2018/3/8 15:40 16 | */ 17 | public class APIRetrofit { 18 | 19 | 20 | private APIConfiguration config; 21 | private OkHttpClient client; 22 | 23 | public APIRetrofit(APIConfiguration config, OkHttpClient client) { 24 | this.config = config; 25 | this.client = client; 26 | } 27 | 28 | /** 29 | * Get a retrofit 2 object. 30 | */ 31 | public Retrofit retrofit() { 32 | Retrofit.Builder builder = new Retrofit.Builder(); 33 | builder.client(this.client); 34 | builder.addConverterFactory(ScalarsConverterFactory.create()); 35 | builder.addConverterFactory(GsonConverterFactory.create()); 36 | builder.addCallAdapterFactory(RxJavaCallAdapterFactory.create()); 37 | builder.baseUrl(this.config.getEndpoint()); 38 | return builder.build(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/AlgorithmEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Algorithm Name 5 | * 6 | * @author Tony Tian 7 | * @date Created in 2018/1/31 13:00 8 | */ 9 | public enum AlgorithmEnum { 10 | 11 | HMAC_SHA256("HmacSHA256"), 12 | MD5("MD5"),; 13 | 14 | private String algorithm; 15 | 16 | AlgorithmEnum(String algorithm) { 17 | this.algorithm = algorithm; 18 | } 19 | 20 | public String algorithm() { 21 | return algorithm; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/CharsetEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Charset Enum 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/2/5 21:22 9 | */ 10 | public enum CharsetEnum { 11 | 12 | UTF_8("UTF-8"), 13 | ISO_8859_1("ISO-8859-1"),; 14 | 15 | 16 | private String charset; 17 | 18 | CharsetEnum(String charset) { 19 | this.charset = charset; 20 | } 21 | 22 | public String charset() { 23 | return charset; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/ContentTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Content-Type Enum: MediaType: Internet Media Type 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/1/31 17:49 9 | */ 10 | public enum ContentTypeEnum { 11 | 12 | APPLICATION_JSON("application/json"), 13 | APPLICATION_JSON_UTF8("application/json; charset=UTF-8"), 14 | // The server does not support types 15 | APPLICATION_FORM("application/x-www-form-urlencoded; charset=UTF-8"),; 16 | 17 | 18 | private String contentType; 19 | 20 | ContentTypeEnum(String contentType) { 21 | this.contentType = contentType; 22 | } 23 | 24 | public String contentType() { 25 | return contentType; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/FuturesCurrenciesEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Futures Currencies (Updated on: 2018-03-13 17:39:09) 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/13 17:37 9 | */ 10 | public enum FuturesCurrenciesEnum { 11 | 12 | BTC(0), LTC(1), ETH(2), ETC(4), BCH(5), XRP(15), EOS(20), BTG(10); 13 | private int symbol; 14 | 15 | FuturesCurrenciesEnum(int symbol) { 16 | this.symbol = symbol; 17 | } 18 | 19 | public int getSymbol() { 20 | return symbol; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/FuturesTransactionTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Transaction type 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/9 15:49 9 | */ 10 | public enum FuturesTransactionTypeEnum { 11 | 12 | OPEN_LONG(1), OPEN_SHORT(2), CLOSE_LONG(3), CLOSE_SHORT(4),; 13 | 14 | private int code; 15 | 16 | FuturesTransactionTypeEnum(int code) { 17 | this.code = code; 18 | } 19 | 20 | public int code() { 21 | return code; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/HttpHeadersEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Http Headers Enum .
5 | * All REST requests must contain the following headers.
6 | * The api key and secret key will be randomly generated and provided by OKEX.
7 | * The Passphrase will be provided by you to further secure your API access.
8 | * OKEX stores the salted hash of your passphrase for verification, but cannot recover the passphrase if you forget it.
9 | * OKEX cursor pagination response headers.
10 | * Request page before (newer) and after (older) this pagination id, 11 | * and limit number of results per request. maximum 100. (default 100).
12 | * 13 | * @author Tony Tian 14 | * @version 1.0.0 15 | * @date 2018/2/5 20:45 16 | */ 17 | public enum HttpHeadersEnum { 18 | 19 | OK_ACCESS_KEY("OK-ACCESS-KEY"), 20 | OK_ACCESS_SIGN("OK-ACCESS-SIGN"), 21 | OK_ACCESS_TIMESTAMP("OK-ACCESS-TIMESTAMP"), 22 | OK_ACCESS_PASSPHRASE("OK-ACCESS-PASSPHRASE"), 23 | 24 | OK_BEFORE("OK-BEFORE"), 25 | OK_AFTER("OK-AFTER"), 26 | OK_LIMIT("OK-LIMIT"), 27 | OK_FROM("OK-FROM"), 28 | OK_TO("OK-TO"); 29 | 30 | private final String header; 31 | 32 | HttpHeadersEnum(final String header) { 33 | this.header = header; 34 | } 35 | 36 | public String header() { 37 | return this.header; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/HttpMethodEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Http Method Enum 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/8 13:53 9 | */ 10 | public enum HttpMethodEnum { 11 | GET, 12 | HEAD, 13 | POST, 14 | PUT, 15 | PATCH, 16 | DELETE, 17 | OPTIONS, 18 | TRACE; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/HttpStatusEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * Http Status
5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/2/5 20:38 9 | */ 10 | public enum HttpStatusEnum { 11 | 12 | OK(200, "OK", "The request is Successful."), 13 | BAD_REQUEST(400, "Bad Request", "Invalid request format."), 14 | UNAUTHORIZED(401, "Unauthorized", "Invalid authorization."), 15 | FORBIDDEN(403, "Forbidden", "You do not have access to the requested resource."), 16 | NOT_FOUND(404, "Not Found", "Request resource path error."), 17 | TOO_MANY_REQUESTS(429, "Too Many Requests", "When a rate limit is exceeded."), 18 | INTERNAL_SERVER_ERROR(500, "Internal Server Error", "We had a problem with our server."),; 19 | 20 | private int status; 21 | private String message; 22 | private String comment; 23 | 24 | HttpStatusEnum(int status, String message, String comment) { 25 | this.status = status; 26 | this.message = message; 27 | this.comment = comment; 28 | } 29 | 30 | public int status() { 31 | return status; 32 | } 33 | 34 | public String message() { 35 | return message; 36 | } 37 | 38 | public String comment() { 39 | return comment; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/enums/I18nEnum.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.enums; 2 | 3 | /** 4 | * internationalization 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/8 16:20 9 | */ 10 | public enum I18nEnum { 11 | ENGLISH("en_US"), 12 | SIMPLIFIED_CHINESE("zh_CN"), 13 | //zh_TW || zh_HK 14 | TRADITIONAL_CHINESE("zh_HK"),; 15 | 16 | private String i18n; 17 | 18 | I18nEnum(String i18n) { 19 | this.i18n = i18n; 20 | } 21 | 22 | public String i18n() { 23 | return i18n; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/exception/APIException.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.exception; 2 | 3 | /** 4 | * API Exception 5 | * 6 | * @author Tony Tian 7 | * @version 1.0.0 8 | * @date 2018/3/8 19:59 9 | */ 10 | public class APIException extends RuntimeException { 11 | 12 | private int code; 13 | 14 | public APIException(String message) { 15 | super(message); 16 | } 17 | 18 | public APIException(int code, String message) { 19 | super(message); 20 | this.code = code; 21 | } 22 | 23 | 24 | public APIException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public APIException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | 32 | @Override 33 | public String getMessage() { 34 | if (this.code != 0) { 35 | return this.code + " : " + super.getMessage(); 36 | } 37 | return super.getMessage(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/GeneralAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.futures.result.ExchangeRate; 4 | import com.okcoin.commons.okex.open.api.bean.futures.result.ServerTime; 5 | 6 | /** 7 | * OKEX general api 8 | * 9 | * @author Tony Tian 10 | * @version 1.0.0 11 | * @date 2018/3/9 16:06 12 | */ 13 | public interface GeneralAPIService { 14 | /** 15 | * Time of the server running OKEX's REST API. 16 | */ 17 | ServerTime getServerTime(); 18 | 19 | /** 20 | * The exchange rate of legal tender pairs 21 | */ 22 | ExchangeRate getExchangeRate(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/account/AccountAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.account; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.okcoin.commons.okex.open.api.bean.account.param.Transfer; 6 | import com.okcoin.commons.okex.open.api.bean.account.param.Withdraw; 7 | import com.okcoin.commons.okex.open.api.bean.account.result.Currency; 8 | import com.okcoin.commons.okex.open.api.bean.account.result.Ledger; 9 | import com.okcoin.commons.okex.open.api.bean.account.result.Wallet; 10 | import com.okcoin.commons.okex.open.api.bean.account.result.WithdrawFee; 11 | 12 | import java.math.BigDecimal; 13 | import java.util.List; 14 | 15 | 16 | public interface AccountAPIService { 17 | 18 | JSONObject transfer(Transfer transfer); 19 | 20 | JSONObject withdraw(Withdraw withdraw); 21 | 22 | List getCurrencies(); 23 | 24 | List getLedger(Integer type, String currency, Integer before, Integer after, int limit); 25 | 26 | List getWallet(); 27 | 28 | List getWallet(String currency); 29 | 30 | JSONArray getDepositAddress(String currency); 31 | 32 | List getWithdrawFee(String currency); 33 | 34 | JSONArray getOnHold(String currency); 35 | 36 | JSONObject lock(String currency, BigDecimal amount); 37 | 38 | JSONObject unlock(String currency, BigDecimal amount); 39 | 40 | JSONArray getDepositHistory(); 41 | 42 | JSONArray getDepositHistory(String currency); 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/account/impl/AccountAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.account.impl; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.okcoin.commons.okex.open.api.bean.account.result.Currency; 6 | import com.okcoin.commons.okex.open.api.bean.account.result.Ledger; 7 | import com.okcoin.commons.okex.open.api.bean.account.result.Wallet; 8 | import com.okcoin.commons.okex.open.api.bean.account.result.WithdrawFee; 9 | import retrofit2.Call; 10 | import retrofit2.http.*; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Account api 16 | * 17 | * @author hucj 18 | * @version 1.0.0 19 | * @date 2018/07/04 20:51 20 | */ 21 | public interface AccountAPI { 22 | 23 | 24 | @POST("/api/account/v3/transfer") 25 | Call transfer(@Body JSONObject jsonObject); 26 | 27 | 28 | @POST("/api/account/v3/withdrawal") 29 | Call withdraw(@Body JSONObject jsonObject); 30 | 31 | @GET("/api/account/v3/currencies") 32 | Call> getCurrencies(); 33 | 34 | @GET("/api/account/v3/ledger") 35 | Call> getLedger(@Query("txn_type") Integer type, @Query("currency") String currency, 36 | @Query("before") Integer before, @Query("after") Integer after, @Query("limit") int limit); 37 | 38 | @GET("/api/account/v3/wallet") 39 | Call> getWallet(); 40 | 41 | @GET("/api/account/v3/wallet/{currency}") 42 | Call> getWallet(@Path("currency") String currency); 43 | 44 | @GET("/api/account/v3/deposit/address") 45 | Call getDepositAddress(@Query("currency") String currency); 46 | 47 | @GET("/api/account/v3/withdrawal/fee") 48 | Call> getWithdrawFee(@Query("currency") String currency); 49 | 50 | @GET("/api/account/v3/onhold") 51 | Call getOnHold(@Query("currency") String currency); 52 | 53 | @POST("/api/account/v3/lock") 54 | Call lock(@Body JSONObject jsonObject); 55 | 56 | @POST("/api/account/v3/unlock") 57 | Call unlock(@Body JSONObject jsonObject); 58 | 59 | @GET("/api/account/v3/deposit/history") 60 | Call getDepositHistory(); 61 | 62 | @GET("/api/account/v3/deposit/history/{currency}") 63 | Call getDepositHistory(@Path("currency") String currency); 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/EttAccountAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.CursorPager; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttAccount; 5 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttLedger; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author chuping.cui 11 | * @date 2018/7/4 12 | */ 13 | public interface EttAccountAPIService { 14 | 15 | /** 16 | * Get all ett account list 17 | * 18 | * @return account info list 19 | */ 20 | List getAccount(); 21 | 22 | /** 23 | * Get ett currency account 24 | * 25 | * @param currency currency code 26 | * @return account info 27 | */ 28 | EttAccount getAccount(String currency); 29 | 30 | /** 31 | * Get ett account ledger list 32 | * 33 | * @param currency currency code 34 | * @param before before and after cursors are available via response headers OK-BEFORE and OK-AFTER. Your requests should use these cursor values when making requests for pages after the initial 35 | * request. {@link CursorPager} 36 | * @param after before and after cursors are available via response headers OK-BEFORE and OK-AFTER. Your requests should use these cursor values when making requests for pages after the initial 37 | * request. {@link CursorPager} 38 | * @param limit number of results per request. 39 | * @return 40 | */ 41 | CursorPager getLedger(String currency, String before, String after, int limit); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/EttOrderAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.CursorPager; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCancelOrderResult; 5 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCreateOrderResult; 6 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttOrder; 7 | 8 | import java.math.BigDecimal; 9 | 10 | /** 11 | * @author chuping.cui 12 | * @date 2018/7/4 13 | */ 14 | public interface EttOrderAPIService { 15 | 16 | /** 17 | * Create a ett order 18 | * 19 | * @param ett ett name 20 | * @param type order type. 1. usdt subscription 2. usdt redemption 3. underlying redemption 21 | * @param amount subscription usdt size 22 | * @param size redemption ett size 23 | * @param clientOid client order id 24 | * @return create order result 25 | */ 26 | EttCreateOrderResult createOrder(String ett, Integer type, BigDecimal amount, BigDecimal size, String clientOid); 27 | 28 | /** 29 | * Cancel order 30 | * 31 | * @param orderId order id 32 | * @return cancel order result 33 | */ 34 | EttCancelOrderResult cancelOrder(String orderId); 35 | 36 | /** 37 | * Get all of ett account order list 38 | * 39 | * @param ett ett name 40 | * @param type order type. 1. subscription 2. redemption 41 | * @param status order status. 0. all 1. waiting 2. done 3. canceled 42 | * @param before before and after cursors are available via response headers OK-BEFORE and OK-AFTER. Your requests should use these cursor values when making requests for pages after the initial 43 | * request. {@link CursorPager} 44 | * @param after before and after cursors are available via response headers OK-BEFORE and OK-AFTER. Your requests should use these cursor values when making requests for pages after the initial 45 | * request. {@link CursorPager} 46 | * @param limit Number of results per request. 47 | * @return order info list 48 | */ 49 | CursorPager getOrder(String ett, Integer type, Integer status, String before, String after, int limit); 50 | 51 | /** 52 | * Get the ett account order info 53 | * 54 | * @param orderId order id 55 | * @return order info 56 | */ 57 | EttOrder getOrder(String orderId); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/EttProductAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttConstituentsResult; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttSettlementDefinePrice; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author chuping.cui 10 | * @date 2018/7/4 11 | */ 12 | public interface EttProductAPIService { 13 | 14 | /** 15 | * Get ett constituents 16 | * 17 | * @param ett ett name 18 | * @return constituents 19 | */ 20 | EttConstituentsResult getConstituents(String ett); 21 | 22 | /** 23 | * Get ett settlement plan define price 24 | * 25 | * @param ett ett name 26 | * @return settlement plan define price list 27 | */ 28 | List getDefinePrice(String ett); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttAccountAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttAccount; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttLedger; 5 | import retrofit2.Call; 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | import retrofit2.http.Query; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author chuping.cui 14 | * @date 2018/7/5 15 | */ 16 | interface EttAccountAPI { 17 | 18 | @GET("/api/ett/v3/accounts") 19 | Call> getAccount(); 20 | 21 | @GET("/api/ett/v3/accounts/{currency}") 22 | Call getAccount(@Path("currency") String currency); 23 | 24 | @GET("/api/ett/v3/accounts/{currency}/ledger") 25 | Call> getLedger(@Path("currency") String currency, @Query("before") String before, @Query("after") String after, @Query("limit") int limit); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttAccountAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.CursorPager; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttAccount; 5 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttLedger; 6 | import com.okcoin.commons.okex.open.api.client.APIClient; 7 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 8 | import com.okcoin.commons.okex.open.api.service.ett.EttAccountAPIService; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author chuping.cui 14 | * @date 2018/7/5 15 | */ 16 | public class EttAccountAPIServiceImpl implements EttAccountAPIService { 17 | 18 | private final APIClient client; 19 | private final EttAccountAPI api; 20 | 21 | public EttAccountAPIServiceImpl(APIConfiguration config) { 22 | this.client = new APIClient(config); 23 | this.api = this.client.createService(EttAccountAPI.class); 24 | } 25 | 26 | @Override 27 | public List getAccount() { 28 | return this.client.executeSync(this.api.getAccount()); 29 | } 30 | 31 | @Override 32 | public EttAccount getAccount(String currency) { 33 | return this.client.executeSync(this.api.getAccount(currency)); 34 | } 35 | 36 | @Override 37 | public CursorPager getLedger(String currency, String before, String after, int limit) { 38 | return this.client.executeSyncCursorPager(this.api.getLedger(currency, before, after, limit)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttOrderAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.param.EttCreateOrderParam; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCancelOrderResult; 5 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCreateOrderResult; 6 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttOrder; 7 | import retrofit2.Call; 8 | import retrofit2.http.*; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author chuping.cui 14 | * @date 2018/7/5 15 | */ 16 | interface EttOrderAPI { 17 | 18 | @POST("/api/ett/v3/orders") 19 | Call createOrder(@Body EttCreateOrderParam param); 20 | 21 | @DELETE("/api/ett/v3/orders/{orderId}") 22 | Call cancelOrder(@Path("orderId") String orderId); 23 | 24 | @GET("/api/ett/v3/orders") 25 | Call> getOrder(@Query("ett") String ett, @Query("type") Integer type, @Query("status") Integer status, @Query("before") String before, @Query("after") String after, 26 | @Query("limit") int limit); 27 | 28 | @GET("/api/ett/v3/orders/{orderId}") 29 | Call getOrder(@Path("orderId") String orderId); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttOrderAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.param.EttCreateOrderParam; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.CursorPager; 5 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCancelOrderResult; 6 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttCreateOrderResult; 7 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttOrder; 8 | import com.okcoin.commons.okex.open.api.client.APIClient; 9 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 10 | import com.okcoin.commons.okex.open.api.service.ett.EttOrderAPIService; 11 | 12 | import java.math.BigDecimal; 13 | 14 | /** 15 | * @author chuping.cui 16 | * @date 2018/7/5 17 | */ 18 | public class EttOrderAPIServiceImpl implements EttOrderAPIService { 19 | 20 | private final APIClient client; 21 | private final EttOrderAPI api; 22 | 23 | public EttOrderAPIServiceImpl(APIConfiguration config) { 24 | this.client = new APIClient(config); 25 | this.api = this.client.createService(EttOrderAPI.class); 26 | } 27 | 28 | @Override 29 | public EttCreateOrderResult createOrder(String ett, Integer type, BigDecimal amount, BigDecimal size, String clientOid) { 30 | EttCreateOrderParam param = new EttCreateOrderParam(); 31 | param.setEtt(ett); 32 | param.setType(type); 33 | param.setAmount(amount); 34 | param.setSize(size); 35 | param.setClientOid(clientOid); 36 | return this.client.executeSync(this.api.createOrder(param)); 37 | } 38 | 39 | @Override 40 | public EttCancelOrderResult cancelOrder(String orderId) { 41 | return this.client.executeSync(this.api.cancelOrder(orderId)); 42 | } 43 | 44 | @Override 45 | public CursorPager getOrder(String ett, Integer type, Integer status, String before, String after, int limit) { 46 | return this.client.executeSyncCursorPager(this.api.getOrder(ett, type, status, before, after, limit)); 47 | } 48 | 49 | @Override 50 | public EttOrder getOrder(String orderId) { 51 | return this.client.executeSync(this.api.getOrder(orderId)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttProductAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttConstituentsResult; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttSettlementDefinePrice; 5 | import retrofit2.Call; 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author chuping.cui 13 | * @date 2018/7/5 14 | */ 15 | interface EttProductAPI { 16 | 17 | @GET("/api/ett/v3/constituents/{ett}") 18 | Call getConstituents(@Path("ett") String ett); 19 | 20 | @GET("/api/ett/v3/define-price/{ett}") 21 | Call> getDefinePrice(@Path("ett") String ett); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/ett/impl/EttProductAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.ett.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttConstituentsResult; 4 | import com.okcoin.commons.okex.open.api.bean.ett.result.EttSettlementDefinePrice; 5 | import com.okcoin.commons.okex.open.api.client.APIClient; 6 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 7 | import com.okcoin.commons.okex.open.api.service.ett.EttProductAPIService; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author chuping.cui 13 | * @date 2018/7/5 14 | */ 15 | public class EttProductAPIServiceImpl implements EttProductAPIService { 16 | 17 | private final APIClient client; 18 | private final EttProductAPI api; 19 | 20 | public EttProductAPIServiceImpl(APIConfiguration config) { 21 | this.client = new APIClient(config); 22 | this.api = this.client.createService(EttProductAPI.class); 23 | } 24 | 25 | @Override 26 | public EttConstituentsResult getConstituents(String ett) { 27 | return this.client.executeSync(this.api.getConstituents(ett)); 28 | } 29 | 30 | @Override 31 | public List getDefinePrice(String ett) { 32 | return this.client.executeSync(this.api.getDefinePrice(ett)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/futures/impl/GeneralAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.futures.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.futures.result.ExchangeRate; 4 | import com.okcoin.commons.okex.open.api.bean.futures.result.ServerTime; 5 | import com.okcoin.commons.okex.open.api.client.APIClient; 6 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 7 | import com.okcoin.commons.okex.open.api.service.GeneralAPIService; 8 | 9 | /** 10 | * General api 11 | * 12 | * @author Tony Tian 13 | * @version 1.0.0 14 | * @date 10/03/2018 19:28 15 | */ 16 | public class GeneralAPIServiceImpl implements GeneralAPIService { 17 | 18 | private APIClient client; 19 | private FuturesMarketAPI api; 20 | 21 | public GeneralAPIServiceImpl(APIConfiguration config) { 22 | this.client = new APIClient(config); 23 | this.api = client.createService(FuturesMarketAPI.class); 24 | } 25 | 26 | @Override 27 | public ServerTime getServerTime() { 28 | return this.client.executeSync(this.api.getServerTime()); 29 | } 30 | 31 | @Override 32 | public ExchangeRate getExchangeRate() { 33 | return this.client.executeSync(this.api.getExchangeRate()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/MarginOrderAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.okcoin.commons.okex.open.api.bean.spot.param.OrderParamDto; 5 | import com.okcoin.commons.okex.open.api.bean.spot.param.PlaceOrderParam; 6 | import com.okcoin.commons.okex.open.api.bean.spot.result.Fills; 7 | import com.okcoin.commons.okex.open.api.bean.spot.result.OrderInfo; 8 | import com.okcoin.commons.okex.open.api.bean.spot.result.OrderResult; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * 杠杆订单相关接口 15 | */ 16 | public interface MarginOrderAPIService { 17 | /** 18 | * 添加订单 19 | * 20 | * @param order 21 | * @return 22 | */ 23 | OrderResult addOrder(PlaceOrderParam order); 24 | 25 | /** 26 | * 批量下单 27 | * 28 | * @param order 29 | * @return 30 | */ 31 | Map> addOrders(List order); 32 | 33 | /** 34 | * 取消指定的订单 delete协议 35 | * 36 | * @param orderId 37 | */ 38 | OrderResult cancleOrderByOrderId(final PlaceOrderParam order, String orderId); 39 | 40 | /** 41 | * 取消指定的订单 post协议 42 | * 43 | * @param orderId 44 | */ 45 | OrderResult cancleOrderByOrderId_post(final PlaceOrderParam order, String orderId); 46 | 47 | /** 48 | * 批量取消订单 delete协议 49 | * 50 | * @param cancleOrders 51 | * @return 52 | */ 53 | Map cancleOrders(final List cancleOrders); 54 | 55 | /** 56 | * 批量取消订单 post协议 57 | * 58 | * @param cancleOrders 59 | * @return 60 | */ 61 | Map cancleOrders_post(final List cancleOrders); 62 | 63 | /** 64 | * 查询订单 65 | * 66 | * @param instrumentId 67 | * @param orderId 68 | * @return 69 | */ 70 | OrderInfo getOrderByProductIdAndOrderId(String instrumentId, String orderId); 71 | 72 | /** 73 | * 订单列表 74 | * 75 | * @param instrumentId 76 | * @param status 77 | * @param from 78 | * @param to 79 | * @param limit 80 | * @return 81 | */ 82 | List getOrders(String instrumentId, String status, String from, String to, String limit); 83 | 84 | /** 85 | * /* 订单列表 86 | * 87 | * @param from 88 | * @param to 89 | * @param limit 90 | * @return 91 | */ 92 | List getPendingOrders(String from, String to, String limit, String instrument_id); 93 | 94 | /** 95 | * 账单列表 96 | * 97 | * @param orderId 98 | * @param instrumentId 99 | * @param from 100 | * @param to 101 | * @param limit 102 | * @return 103 | */ 104 | List getFills(String orderId, String instrumentId, String from, String to, String limit); 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/SpotAccountAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.Account; 4 | import com.okcoin.commons.okex.open.api.bean.spot.result.Ledger; 5 | import com.okcoin.commons.okex.open.api.bean.spot.result.ServerTimeDto; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * 币币资产相关接口 12 | */ 13 | public interface SpotAccountAPIService { 14 | 15 | /** 16 | * 系统时间 17 | * 18 | * @return 19 | */ 20 | ServerTimeDto time(); 21 | 22 | /** 23 | * 挖矿相关数据 24 | * 25 | * @return 26 | */ 27 | Map getMiningData(); 28 | 29 | 30 | /** 31 | * 账户资产列表 32 | * 33 | * @return 34 | */ 35 | List getAccounts(); 36 | 37 | /** 38 | * 账单列表 39 | * 40 | * @param currency 41 | * @param from 42 | * @param to 43 | * @param limit 44 | * @return 45 | */ 46 | List getLedgersByCurrency(String currency, String from, String to, String limit); 47 | 48 | /** 49 | * 单币资产 50 | * 51 | * @param currency 52 | * @return 53 | */ 54 | Account getAccountByCurrency(final String currency); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/SpotProductAPIService.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.*; 4 | 5 | import java.math.BigDecimal; 6 | import java.util.List; 7 | 8 | public interface SpotProductAPIService { 9 | 10 | /** 11 | * 单个币对行情 12 | * 13 | * @param product 14 | * @return 15 | */ 16 | Ticker getTickerByProductId(String product); 17 | 18 | /** 19 | * 行情列表 20 | * 21 | * @return 22 | */ 23 | List getTickers(); 24 | 25 | /** 26 | * @param product 27 | * @param size 28 | * @param depth 29 | * @return 30 | */ 31 | Book bookProductsByProductId(String product, String size, BigDecimal depth); 32 | 33 | /** 34 | * 币对列表 35 | * 36 | * @return 37 | */ 38 | List getProducts(); 39 | 40 | /** 41 | * 交易列表 42 | * 43 | * @param product 44 | * @param from 45 | * @param to 46 | * @param limit 47 | * @return 48 | */ 49 | List getTrades(String product, String from, String to, String limit); 50 | 51 | /** 52 | * @param product 53 | * @param granularity 54 | * @param start 55 | * @param end 56 | * @return 57 | */ 58 | List getCandles(String product, String granularity, String start, String end); 59 | 60 | List getCandles_1(String product, String granularity, String start, String end); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/impl/MarginAccountAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.*; 4 | import com.okcoin.commons.okex.open.api.client.APIClient; 5 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 6 | import com.okcoin.commons.okex.open.api.service.spot.MarginAccountAPIService; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * 13 | */ 14 | public class MarginAccountAPIServiceImpl implements MarginAccountAPIService { 15 | 16 | private final APIClient client; 17 | private final MarginAccountAPI api; 18 | 19 | public MarginAccountAPIServiceImpl(final APIConfiguration config) { 20 | this.client = new APIClient(config); 21 | this.api = this.client.createService(MarginAccountAPI.class); 22 | } 23 | 24 | 25 | @Override 26 | public List> getAccounts() { 27 | return this.client.executeSync(this.api.getAccounts()); 28 | } 29 | 30 | @Override 31 | public Map getAccountsByProductId(final String product) { 32 | return this.client.executeSync(this.api.getAccountsByProductId(product)); 33 | } 34 | 35 | @Override 36 | public List getLedger(final String product, final String type, final String from, final String to, final String limit) { 37 | return this.client.executeSync(this.api.getLedger(product, type, from, to, limit)); 38 | } 39 | 40 | @Override 41 | public List> getAvailability() { 42 | return this.client.executeSync(this.api.getAvailability()); 43 | } 44 | 45 | @Override 46 | public List> getAvailabilityByProductId(final String product) { 47 | return this.client.executeSync(this.api.getAvailabilityByProductId(product)); 48 | } 49 | 50 | @Override 51 | public List getBorrowedAccounts(final String status, final String from, final String to, final String limit) { 52 | return this.client.executeSync(this.api.getBorrowedAccounts(status, from, to, limit)); 53 | } 54 | 55 | @Override 56 | public List getBorrowedAccountsByProductId(final String product, final String from, final String to, final String limit, final String status) { 57 | return this.client.executeSync(this.api.getBorrowedAccountsByProductId(product, from, to, limit, status)); 58 | } 59 | 60 | @Override 61 | public BorrowResult borrow_1(final BorrowRequestDto order) { 62 | return this.client.executeSync(this.api.borrow_1(order)); 63 | } 64 | 65 | @Override 66 | public RepaymentResult repayment_1(final RepaymentRequestDto order) { 67 | return this.client.executeSync(this.api.repayment_1(order)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/impl/SpotAccountAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.Account; 4 | import com.okcoin.commons.okex.open.api.bean.spot.result.Ledger; 5 | import com.okcoin.commons.okex.open.api.bean.spot.result.ServerTimeDto; 6 | import retrofit2.Call; 7 | import retrofit2.http.GET; 8 | import retrofit2.http.Path; 9 | import retrofit2.http.Query; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | public interface SpotAccountAPI { 15 | 16 | /** 17 | * 获取系统时间 18 | * 19 | * @return 20 | */ 21 | @GET("api/spot/v3/time") 22 | Call time(); 23 | 24 | /** 25 | * 挖矿相关数据 26 | * 27 | * @return 28 | */ 29 | @GET("api/spot/v3/miningdata") 30 | Call> getMiningdata(); 31 | 32 | /** 33 | * 币币资产 34 | * 35 | * @return 36 | */ 37 | @GET("api/spot/v3/accounts") 38 | Call> getAccounts(); 39 | 40 | /** 41 | * 币币指定币资产 42 | * 43 | * @param currency 44 | * @return 45 | */ 46 | @GET("api/spot/v3/accounts/{currency}") 47 | Call getAccountByCurrency(@Path("currency") String currency); 48 | 49 | /** 50 | * 币币账单列表 51 | * 52 | * @param currency 53 | * @param from 54 | * @param to 55 | * @param limit 56 | * @return 57 | */ 58 | @GET("api/spot/v3/accounts/{currency}/ledger") 59 | Call> getLedgersByCurrency(@Path("currency") String currency, 60 | @Query("from") String from, 61 | @Query("to") String to, 62 | @Query("limit") String limit); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/impl/SpotAccountAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.Account; 4 | import com.okcoin.commons.okex.open.api.bean.spot.result.Ledger; 5 | import com.okcoin.commons.okex.open.api.bean.spot.result.ServerTimeDto; 6 | import com.okcoin.commons.okex.open.api.client.APIClient; 7 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 8 | import com.okcoin.commons.okex.open.api.service.spot.SpotAccountAPIService; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public class SpotAccountAPIServiceImpl implements SpotAccountAPIService { 14 | 15 | private final APIClient client; 16 | private final SpotAccountAPI api; 17 | 18 | public SpotAccountAPIServiceImpl(final APIConfiguration config) { 19 | this.client = new APIClient(config); 20 | this.api = this.client.createService(SpotAccountAPI.class); 21 | } 22 | 23 | @Override 24 | public ServerTimeDto time() { 25 | return this.client.executeSync(this.api.time()); 26 | } 27 | 28 | @Override 29 | public Map getMiningData() { 30 | return this.client.executeSync(this.api.getMiningdata()); 31 | } 32 | 33 | @Override 34 | public List getAccounts() { 35 | return this.client.executeSync(this.api.getAccounts()); 36 | } 37 | 38 | @Override 39 | public List getLedgersByCurrency(final String currency, final String from, final String to, final String limit) { 40 | return this.client.executeSync(this.api.getLedgersByCurrency(currency, from, to, limit)); 41 | } 42 | 43 | @Override 44 | public Account getAccountByCurrency(final String currency) { 45 | return this.client.executeSync(this.api.getAccountByCurrency(currency)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/impl/SpotProductAPI.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.*; 4 | import retrofit2.Call; 5 | import retrofit2.http.GET; 6 | import retrofit2.http.Path; 7 | import retrofit2.http.Query; 8 | 9 | import java.math.BigDecimal; 10 | import java.util.List; 11 | 12 | public interface SpotProductAPI { 13 | 14 | @GET("/api/spot/v3/instruments") 15 | Call> getProducts(); 16 | 17 | @GET("/api/spot/v3/instruments/{instrument_id}/book") 18 | Call bookProductsByProductId(@Path("instrument_id") String product, 19 | @Query("size") String size, 20 | @Query("depth") BigDecimal depth); 21 | 22 | @GET("/api/spot/v3/instruments/ticker") 23 | Call> getTickers(); 24 | 25 | @GET("/api/spot/v3/instruments/{instrument_id}/ticker") 26 | Call getTickerByProductId(@Path("instrument_id") String product); 27 | 28 | 29 | @GET("/api/spot/v3/instruments/{instrument_id}/trades") 30 | Call> getTrades(@Path("instrument_id") String product, 31 | @Query("from") String from, 32 | @Query("to") String to, 33 | @Query("limit") String limit); 34 | 35 | @GET("/api/spot/v3/instruments/{instrument_id}/candles") 36 | Call> getCandles(@Path("instrument_id") String product, 37 | @Query("granularity") String type, 38 | @Query("start") String start, 39 | @Query("end") String end); 40 | 41 | @GET("/api/spot/v3/instruments/{instrument_id}/candles") 42 | Call> getCandles_1(@Path("instrument_id") String product, 43 | @Query("granularity") String type, 44 | @Query("start") String start, 45 | @Query("end") String end); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/service/spot/impl/SpotProductAPIServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.service.spot.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.*; 4 | import com.okcoin.commons.okex.open.api.client.APIClient; 5 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 6 | import com.okcoin.commons.okex.open.api.service.spot.SpotProductAPIService; 7 | 8 | import java.math.BigDecimal; 9 | import java.util.List; 10 | 11 | /** 12 | * 公共数据相关接口 13 | * 14 | **/ 15 | public class SpotProductAPIServiceImpl implements SpotProductAPIService { 16 | 17 | private final APIClient client; 18 | private final SpotProductAPI spotProductAPI; 19 | 20 | public SpotProductAPIServiceImpl(final APIConfiguration config) { 21 | this.client = new APIClient(config); 22 | this.spotProductAPI = this.client.createService(SpotProductAPI.class); 23 | } 24 | 25 | 26 | @Override 27 | public Ticker getTickerByProductId(final String product) { 28 | return this.client.executeSync(this.spotProductAPI.getTickerByProductId(product)); 29 | } 30 | 31 | @Override 32 | public List getTickers() { 33 | return this.client.executeSync(this.spotProductAPI.getTickers()); 34 | } 35 | 36 | @Override 37 | public Book bookProductsByProductId(final String product, final String size, final BigDecimal depth) { 38 | return this.client.executeSync(this.spotProductAPI.bookProductsByProductId(product, size, depth)); 39 | } 40 | 41 | @Override 42 | public List getProducts() { 43 | return this.client.executeSync(this.spotProductAPI.getProducts()); 44 | } 45 | 46 | @Override 47 | public List getTrades(final String product, final String from, final String to, final String limit) { 48 | return this.client.executeSync(this.spotProductAPI.getTrades(product, from, to, limit)); 49 | } 50 | 51 | @Override 52 | public List getCandles(final String product, final String granularity, final String start, final String end) { 53 | return this.client.executeSync(this.spotProductAPI.getCandles(product, granularity, start, end)); 54 | } 55 | 56 | @Override 57 | public List getCandles_1(final String product, final String granularity, final String start, final String end) { 58 | return this.client.executeSync(this.spotProductAPI.getCandles_1(product, granularity, start, end)); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/okcoin/commons/okex/open/api/utils/OrderIdUtils.java: -------------------------------------------------------------------------------- 1 | package com.okcoin.commons.okex.open.api.utils; 2 | 3 | import com.okcoin.commons.okex.open.api.constant.APIConstants; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * Order Id Utils 9 | * 10 | * @author Tony Tian 11 | * @version 1.0.0 12 | * @date 2018/3/14 10:02 13 | */ 14 | public class OrderIdUtils { 15 | 16 | /** 17 | * The order ids, use uuid and remove the line dividing line.
18 | * id length = 32 19 | * 20 | * @return String eg: 39360db0a45e41309511f4fba658b01c 21 | */ 22 | public static String generator() { 23 | return UUID.randomUUID().toString().toLowerCase().replace(APIConstants.HLINE, APIConstants.EMPTY); 24 | } 25 | 26 | public static void main(String[] args) { 27 | System.out.println(generator()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/FutureAccount.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | /** 4 | * 账户权益 5 | * @author xiang 6 | * 7 | */ 8 | public class FutureAccount { 9 | private String currency;//币种,如:btc 10 | private String marginMode;// 账户类型:全仓 crossed 11 | private double equity;// 账户权益 12 | private double totalAvailBalance;//账户余额 13 | private double margin;// 保证金(挂单冻结+持仓已用) 14 | private double realizedPnl;//已实现盈亏 15 | private double unrealizedPnl;//未实现盈亏 16 | private float marginRatio;//保证金率 17 | public String getCurrency() { 18 | return currency; 19 | } 20 | public void setCurrency(String currency) { 21 | this.currency = currency; 22 | } 23 | public String getMarginMode() { 24 | return marginMode; 25 | } 26 | public void setMarginMode(String marginMode) { 27 | this.marginMode = marginMode; 28 | } 29 | public double getEquity() { 30 | return equity; 31 | } 32 | public void setEquity(double equity) { 33 | this.equity = equity; 34 | } 35 | public double getTotalAvailBalance() { 36 | return totalAvailBalance; 37 | } 38 | public void setTotalAvailBalance(double totalAvailBalance) { 39 | this.totalAvailBalance = totalAvailBalance; 40 | } 41 | public double getMargin() { 42 | return margin; 43 | } 44 | public void setMargin(double margin) { 45 | this.margin = margin; 46 | } 47 | public double getRealizedPnl() { 48 | return realizedPnl; 49 | } 50 | public void setRealizedPnl(double realizedPnl) { 51 | this.realizedPnl = realizedPnl; 52 | } 53 | public double getUnrealizedPnl() { 54 | return unrealizedPnl; 55 | } 56 | public void setUnrealizedPnl(double unrealizedPnl) { 57 | this.unrealizedPnl = unrealizedPnl; 58 | } 59 | public float getMarginRatio() { 60 | return marginRatio; 61 | } 62 | public void setMarginRatio(float marginRatio) { 63 | this.marginRatio = marginRatio; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/FutureInstrument.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.futures.result.Instruments; 4 | import com.xiang.service.Instrument; 5 | 6 | /** 7 | * 期货合约ID 8 | * @author xiang 9 | * @createDate 2018年12月27日 上午11:30:41 10 | */ 11 | public class FutureInstrument extends Instruments implements Instrument{ 12 | 13 | /** 14 | * 合约类型 this_week,next_week,quarter 15 | */ 16 | private String contractType; 17 | 18 | public String getContractType() { 19 | return contractType; 20 | } 21 | 22 | public void setContractType(String contractType) { 23 | this.contractType = contractType; 24 | } 25 | private long deliveryTime; 26 | 27 | public long getDeliveryTime() { 28 | return deliveryTime; 29 | } 30 | 31 | public void setDeliveryTime(long deliveryTime) { 32 | this.deliveryTime = deliveryTime; 33 | } 34 | 35 | public String getCoin() 36 | { 37 | return getUnderlying_index(); 38 | } 39 | public String getInstrumentId() 40 | { 41 | return getInstrument_id(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/FutureOrder.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 期货交易订单 7 | * @author xiang 8 | * 9 | */ 10 | public class FutureOrder implements Serializable{ 11 | private static final long serialVersionUID = 1L; 12 | private String instrumentId;// String 合约ID,如BTC-USDT-180213 13 | private int size;// String 数量 14 | private String timestamp; // String 委托时间 15 | private int filledQty;// String 成交数量 16 | private double fee; //String 手续费 17 | private String orderId; // String 订单ID 18 | private float price; //String 订单价格 19 | private float priceAvg; // String 平均价格 20 | private int status; // String 订单状态(-1.撤单成功;0:等待成交 1:部分成交 2:全部成交 6:未完成(等待成交+部分成交)7:已完成(撤单成功+全部成交)) 21 | private int type; //String 订单类型(1:开多 2:开空 3:平多 4:平空) 22 | private int contractVal; //String 合约面值 23 | private int leverage; //String 杠杆倍数 value:10/20 默认10 24 | private String clientOid; 25 | public String getInstrumentId() { 26 | return instrumentId; 27 | } 28 | public void setInstrumentId(String instrumentId) { 29 | this.instrumentId = instrumentId; 30 | } 31 | public int getSize() { 32 | return size; 33 | } 34 | public String getClientOid() { 35 | return clientOid; 36 | } 37 | public void setClientOid(String clientOid) { 38 | this.clientOid = clientOid; 39 | } 40 | public void setSize(int size) { 41 | this.size = size; 42 | } 43 | public String getTimestamp() { 44 | return timestamp; 45 | } 46 | public void setTimestamp(String timestamp) { 47 | this.timestamp = timestamp; 48 | } 49 | public int getFilledQty() { 50 | return filledQty; 51 | } 52 | public void setFilledQty(int filledQty) { 53 | this.filledQty = filledQty; 54 | } 55 | public double getFee() { 56 | return fee; 57 | } 58 | public void setFee(double fee) { 59 | this.fee = fee; 60 | } 61 | public String getOrderId() { 62 | return orderId; 63 | } 64 | public void setOrderId(String orderId) { 65 | this.orderId = orderId; 66 | } 67 | public float getPrice() { 68 | return price; 69 | } 70 | public void setPrice(float price) { 71 | this.price = price; 72 | } 73 | public float getPriceAvg() { 74 | return priceAvg; 75 | } 76 | public void setPriceAvg(float priceAvg) { 77 | this.priceAvg = priceAvg; 78 | } 79 | public int getStatus() { 80 | return status; 81 | } 82 | public void setStatus(int status) { 83 | this.status = status; 84 | } 85 | public int getType() { 86 | return type; 87 | } 88 | public void setType(int type) { 89 | this.type = type; 90 | } 91 | 92 | public int getContractVal() { 93 | return contractVal; 94 | } 95 | public void setContractVal(int contractVal) { 96 | this.contractVal = contractVal; 97 | } 98 | public int getLeverage() { 99 | return leverage; 100 | } 101 | public void setLeverage(int leverage) { 102 | this.leverage = leverage; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/MD5Util.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.util.ArrayList; 6 | import java.util.Collections; 7 | import java.util.List; 8 | import java.util.Map; 9 | import java.util.Map.Entry; 10 | 11 | public class MD5Util { 12 | 13 | public static String buildMysignV1(Map sArray, 14 | String secretKey) { 15 | String mysign = ""; 16 | try { 17 | String prestr = createLinkString(sArray); 18 | prestr = prestr + "&secret_key=" + secretKey; 19 | System.out.println("prestr "+prestr); 20 | mysign = getMD5String(prestr); 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | } 24 | return mysign; 25 | } 26 | 27 | public static String createLinkString(Map params) { 28 | 29 | List keys = new ArrayList(params.keySet()); 30 | Collections.sort(keys); 31 | String prestr = ""; 32 | for (int i = 0; i < keys.size(); i++) { 33 | String key = keys.get(i); 34 | String value = params.get(key); 35 | if (i == keys.size() - 1) { 36 | prestr = prestr + key + "=" + value; 37 | } else { 38 | prestr = prestr + key + "=" + value + "&"; 39 | } 40 | } 41 | return prestr; 42 | } 43 | 44 | /** 45 | * 生成32位大写MD5值 46 | */ 47 | private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', 48 | '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 49 | 50 | public static String getMD5String(String str) { 51 | try { 52 | if (str == null || str.trim().length() == 0) { 53 | return ""; 54 | } 55 | byte[] bytes = str.getBytes(); 56 | MessageDigest messageDigest = MessageDigest.getInstance("MD5"); 57 | messageDigest.update(bytes); 58 | bytes = messageDigest.digest(); 59 | StringBuilder sb = new StringBuilder(); 60 | for (int i = 0; i < bytes.length; i++) { 61 | sb.append(HEX_DIGITS[(bytes[i] & 0xf0) >> 4] + "" 62 | + HEX_DIGITS[bytes[i] & 0xf]); 63 | } 64 | return sb.toString(); 65 | } catch (NoSuchAlgorithmException e) { 66 | e.printStackTrace(); 67 | } 68 | return ""; 69 | } 70 | public static String getParams(Map map){ 71 | StringBuilder params = new StringBuilder("{"); 72 | for(Entry param:map.entrySet()){ 73 | params.append("'").append(param.getKey()).append("':'").append(param.getValue()).append("',"); 74 | } 75 | params.replace(params.length()-1,params.length(),"}"); 76 | return params.toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/MoniterTask.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | import java.util.TimerTask; 4 | 5 | /** 6 | * ws定时监控连线 7 | * @author xiang 8 | * 9 | */ 10 | public class MoniterTask extends TimerTask{ 11 | 12 | private long startTime = System.currentTimeMillis(); 13 | private int checkTime = 5000; 14 | private WebSocketBase client = null; 15 | 16 | public void updateTime() { 17 | startTime = System.currentTimeMillis(); 18 | } 19 | 20 | public MoniterTask(WebSocketBase client) { 21 | this.client = client; 22 | } 23 | 24 | public void run() { 25 | long deadTime = System.currentTimeMillis() - startTime; 26 | if (deadTime > checkTime) { 27 | System.out.println("timeout " + (System.currentTimeMillis() - startTime)); 28 | client.setStatus(false); 29 | client.reConnect(); 30 | } 31 | client.sentPing(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/OkexConstant.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | public class OkexConstant { 4 | 5 | public static final String TABLE="table"; 6 | public static final String DATA="data"; 7 | public static final String INSTRUMENT_ID="instrument_id"; 8 | public static final String PARTIAL_ACTION="partial"; 9 | public static final String FUTURES_DEPTH5="futures/depth5"; 10 | public static final String FUTURES_DEPTH="futures/depth"; 11 | public static final String SPOT_DEPTH5="spot/depth5"; 12 | public static final String SPOT_DEPTH="spot/depth"; 13 | public static final String ASKS="asks"; 14 | public static final String BIDS="bids"; 15 | public static final String COLON = ":"; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/SpotInstrument.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | import com.okcoin.commons.okex.open.api.bean.spot.result.Product; 4 | import com.xiang.service.Instrument; 5 | 6 | /** 7 | * 现货合约ID 8 | * @author xiang 9 | * 10 | */ 11 | public class SpotInstrument extends Product implements Instrument { 12 | private String contractType; 13 | 14 | public String getContractType() { 15 | return contractType; 16 | } 17 | 18 | public void setContractType(String contractType) { 19 | this.contractType = contractType; 20 | } 21 | 22 | public String getCoin() { 23 | return getBase_currency(); 24 | } 25 | 26 | public long getDeliveryTime() { 27 | return Long.MAX_VALUE; 28 | } 29 | 30 | public String getInstrumentId() { 31 | return getInstrument_id(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/okex/websocket/WebSocketBase.java: -------------------------------------------------------------------------------- 1 | package com.okex.websocket; 2 | 3 | public interface WebSocketBase { 4 | public void setStatus(boolean status); 5 | public void reConnect(); 6 | public void sentPing(); 7 | public void stop(); 8 | public void start(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.xiang.controller; 2 | 3 | import javax.annotation.Resource; 4 | import javax.validation.constraints.NotNull; 5 | 6 | import org.apache.shiro.SecurityUtils; 7 | import org.apache.shiro.authc.UsernamePasswordToken; 8 | import org.apache.shiro.subject.Subject; 9 | import org.springframework.web.bind.annotation.CrossOrigin; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RequestMethod; 13 | import org.springframework.web.bind.annotation.RequestParam; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import com.xiang.po.User; 17 | import com.xiang.spring.APIException; 18 | import com.xiang.spring.ErrorCodes; 19 | import com.xiang.user.service.UserService; 20 | import com.xiang.vo.UserVo; 21 | 22 | /** 23 | * @author xiang 24 | * 25 | */ 26 | @CrossOrigin 27 | @RestController 28 | @RequestMapping(value = "/user") 29 | public class UserController { 30 | @Resource 31 | private UserService userService; 32 | 33 | @RequestMapping(value = "/login") 34 | public UserVo login(@RequestParam("userName") @NotNull(message = "userName不能为空") String userName, 35 | @RequestParam("password") @NotNull(message = "password不能为空") String password) { 36 | User user = new User(); 37 | user.setUserName(userName); 38 | user.setPassword(password); 39 | return login(user); 40 | } 41 | 42 | @RequestMapping(value = "/login", method = RequestMethod.POST) 43 | public UserVo login(@RequestBody User user) { 44 | Subject subject = SecurityUtils.getSubject(); 45 | UsernamePasswordToken token = new UsernamePasswordToken(user.getUserName(), user.getPassword()); 46 | try { 47 | subject.login(token); 48 | if (subject.isAuthenticated()) { 49 | return (UserVo)subject.getPrincipal(); 50 | } 51 | } catch (Exception ex) { 52 | throw new APIException(ErrorCodes.AUTH); 53 | } 54 | throw new APIException(ErrorCodes.AUTH); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/controller/XAuthToken.java: -------------------------------------------------------------------------------- 1 | package com.xiang.controller; 2 | 3 | import java.util.Date; 4 | 5 | public class XAuthToken { 6 | private String token; 7 | private String userName; 8 | private Date expireAt; 9 | public String getToken() { 10 | return token; 11 | } 12 | public void setToken(String token) { 13 | this.token = token; 14 | } 15 | public String getUserName() { 16 | return userName; 17 | } 18 | public void setUserName(String userName) { 19 | this.userName = userName; 20 | } 21 | public Date getExpireAt() { 22 | return expireAt; 23 | } 24 | public void setExpireAt(Date expireAt) { 25 | this.expireAt = expireAt; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/po/User.java: -------------------------------------------------------------------------------- 1 | package com.xiang.po; 2 | /** 3 | * @author xiang 4 | * @createDate 2018年12月20日 下午2:12:19 5 | */ 6 | public class User { 7 | 8 | private String userName; 9 | private String password; 10 | private String role; 11 | private String permission; 12 | public String getUserName() { 13 | return userName; 14 | } 15 | public void setUserName(String userName) { 16 | this.userName = userName; 17 | } 18 | public String getPassword() { 19 | return password; 20 | } 21 | public void setPassword(String password) { 22 | this.password = password; 23 | } 24 | public String getRole() { 25 | return role; 26 | } 27 | public void setRole(String role) { 28 | this.role = role; 29 | } 30 | public String getPermission() { 31 | return permission; 32 | } 33 | public void setPermission(String permission) { 34 | this.permission = permission; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/BaseDataService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | /** 4 | * @author xiang 5 | * @createDate 2018年12月11日 下午2:55:20 6 | */ 7 | public interface BaseDataService { 8 | public boolean addData(Object obj); 9 | public void process(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/DepthService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年12月24日 下午5:19:08 8 | */ 9 | public interface DepthService extends Level2Service{ 10 | public void processData(String table,String action,JSONObject data); 11 | public boolean validateChecksum(long checksum); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/FutureAccountService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import com.okex.websocket.FutureAccount; 4 | 5 | public interface FutureAccountService { 6 | public FutureAccount getFutureAccount(String coin); 7 | public int getAvailableVolume(String coin,float price,int leverRate); 8 | public int getAvailableVolume(String coin,double availableMargin,float price,int leverRate); 9 | public double getAvailableMargin(String coin); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/FutureInstrumentService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.List; 4 | 5 | import com.okex.websocket.FutureInstrument; 6 | 7 | /** 8 | * @author xiang 9 | * @createDate 2018年12月27日 上午11:00:48 10 | */ 11 | public interface FutureInstrumentService { 12 | public FutureInstrument getFutureInstrument(String instrumentId); 13 | public FutureInstrument getFutureInstrument(String coin,String contractType); 14 | public List getSubscribes(); 15 | public void refresh(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/HedgingDataService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Map; 5 | 6 | import com.xiang.service.impl.HedgingContext; 7 | 8 | /** 9 | * @author xiang 10 | * @createDate 2018年12月11日 下午2:55:20 11 | */ 12 | public interface HedgingDataService{ 13 | public HedgingContext getHedgingContext(String coin); 14 | /** 15 | * 获取临时缓存图表数据 16 | * @param coin 17 | * @param type tn,tq,nq 18 | * @return 19 | */ 20 | public LinkedList> getHedgingData(String coin,String type); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/HedgingService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeoutException; 5 | 6 | import com.xiang.service.impl.Hedging; 7 | import com.xiang.service.impl.HedgingConfig; 8 | 9 | /** 10 | * @author xiang 11 | * @createDate 2018年11月5日 上午9:48:06 12 | */ 13 | public interface HedgingService { 14 | public void removeHedgingConfig(String configId); 15 | public List getHedgings(); 16 | public List getConfigs(String coin, String type); 17 | public HedgingConfig newHedgingConfig(String coin, String type); 18 | public HedgingConfig getHedgingConfig(String configId); 19 | public void addHedgingConfig(HedgingConfig config); 20 | //强制平仓 21 | public void liquidHedging(String hedgingId); 22 | public void liquidAllHedging(); 23 | //修复交易(修复实际已成交,但未收到订单信息的对冲交易) 24 | public Hedging repairHedging(String hedgingId) throws TimeoutException; 25 | //修复对冲(修复实际已成交,但未收到订单信息的对冲交易) 26 | public Hedging repairHedging(Hedging hedging) throws TimeoutException; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/Instrument.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | public interface Instrument { 4 | public String getContractType(); 5 | public String getCoin(); 6 | public long getDeliveryTime(); 7 | public String getInstrumentId(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/InstrumentService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年12月27日 上午11:00:48 8 | */ 9 | public interface InstrumentService { 10 | public Instrument getInstrument(String instrumentId); 11 | public Instrument getInstrument(String table,String instrumentId); 12 | public Instrument getInstrument(String table,String coin,String contractType); 13 | public List getSubscribes(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/InstrumentsDepthService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import com.xiang.service.impl.Level2Bean; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年11月27日 上午9:51:01 8 | */ 9 | public interface InstrumentsDepthService{ 10 | public Level2Bean getSellLevel2Postion(String instrumentId,int pos);//卖几价,从1开始 11 | public Level2Bean getBuyLevel2Postion(String instrumentId,int pos);//卖几价,从1开始 12 | public Level2Bean getSellFirst(String instrumentId);//卖一价 13 | public Level2Bean getBuyFirst(String instrumentId);//买一价 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/Level2Service.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import com.xiang.service.impl.Level2Bean; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年11月27日 上午9:51:01 8 | */ 9 | public interface Level2Service { 10 | public Level2Bean getSellLevel2Postion(int pos);//卖几价,从1开始 11 | public Level2Bean getBuyLevel2Postion(int pos);//卖几价,从1开始 12 | public Level2Bean getSellFirst();//卖一价 13 | public Level2Bean getBuyFirst();//买一价 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/SpotInstrumentService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.List; 4 | 5 | import com.okex.websocket.SpotInstrument; 6 | 7 | /** 8 | * @author xiang 9 | * @createDate 2018年12月27日 上午11:00:48 10 | */ 11 | public interface SpotInstrumentService { 12 | public SpotInstrument getSpotInstrument(String instrumentId); 13 | public SpotInstrument getSpotInstrument(String base, String quote); 14 | public List getSubscribes(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/TradeApiService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.TimeoutException; 5 | 6 | import com.xiang.service.impl.HedgingTrade; 7 | 8 | /** 9 | * @author xiang 10 | * @createDate 2018年12月28日 上午10:43:39 11 | */ 12 | public interface TradeApiService { 13 | public void batchOrders(List trades) throws TimeoutException; 14 | public void repairHedgingTrade(HedgingTrade trade) throws TimeoutException; 15 | public void order(HedgingTrade trade) throws TimeoutException; 16 | public void cancelHedgingTrade(HedgingTrade trade) throws TimeoutException; 17 | public void batchCancel(List trades) throws TimeoutException; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/WebSocketService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service; 2 | 3 | public interface WebSocketService { 4 | public void onReceive(Object obj); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/AccountConfig.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年11月29日 下午2:55:50 8 | */ 9 | @Service("accountConfig") 10 | public class AccountConfig { 11 | /** 12 | * 合约开仓手续费率 13 | */ 14 | private float buyFeeRate = 0.0003f;//万分之三 15 | /** 16 | * 合约平仓手续费率 17 | */ 18 | private float sellFeeRate = 0.0003f;//万分之三 19 | 20 | public float getBuyFeeRate() { 21 | return buyFeeRate; 22 | } 23 | public void setBuyFeeRate(float buyFeeRate) { 24 | this.buyFeeRate = buyFeeRate; 25 | } 26 | public float getSellFeeRate() { 27 | return sellFeeRate; 28 | } 29 | public void setSellFeeRate(float sellFeeRate) { 30 | this.sellFeeRate = sellFeeRate; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/BaseDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.Map; 6 | 7 | /** 8 | * @author xiang 9 | * @createDate 2018年12月24日 上午10:14:45 10 | */ 11 | public abstract class BaseDataServiceImpl{ 12 | protected Map HedgingContexts = new HashMap(); 13 | public HedgingContext getHedgingContext(String coin) { 14 | coin=coin.toLowerCase(); 15 | if(!HedgingContexts.containsKey(coin)) 16 | { 17 | HedgingContexts.put(coin, new HedgingContext(coin)); 18 | } 19 | return HedgingContexts.get(coin); 20 | } 21 | /** 22 | * @param coin 23 | * @param type tn,tq,nq 24 | * @return 25 | */ 26 | public LinkedList> getHedgingData(String coin, String type) { 27 | HedgingContext hc = getHedgingContext(coin); 28 | if (hc != null) { 29 | return hc.getHedgingData(type); 30 | } 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/Coin.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | /** 3 | * @author xiang 4 | * @createDate 2018年12月14日 上午10:28:58 5 | */ 6 | public class Coin { 7 | public Coin(String symbol,String type,String base) 8 | { 9 | this.symbol=symbol; 10 | this.type=type; 11 | this.base=base; 12 | } 13 | private String symbol;//btc_usd 14 | private String type;//btc 15 | private String base;//f_usd_btc 16 | public String getSymbol() { 17 | return symbol; 18 | } 19 | public void setSymbol(String symbol) { 20 | this.symbol = symbol; 21 | } 22 | public String getType() { 23 | return type; 24 | } 25 | public void setType(String type) { 26 | this.type = type; 27 | } 28 | public String getBase() { 29 | return base; 30 | } 31 | public void setBase(String base) { 32 | this.base = base; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/CoinServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年12月27日 下午3:51:19 8 | */ 9 | @Service("coinService") 10 | public class CoinServiceImpl { 11 | 12 | /** 13 | * 获取虚拟币单张合约美元价值 14 | * @param coin 15 | * @return 16 | */ 17 | public int getUnitAmount(String coin) 18 | { 19 | if ("btc".equals(coin.toLowerCase())) 20 | return 100; 21 | return 10; 22 | } 23 | /** 24 | * @param coin 虚拟币 25 | * @param price 价格 26 | * @param leverRate 杠杆 27 | * @param amount 合约张数 28 | * @return 计算需要占用的保证金 29 | */ 30 | public double getMargin(String coin, float price, int leverRate,int amount) 31 | { 32 | return getUnitAmount(coin)*amount/price/leverRate; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/HedgingConfigManager.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import net.sf.ehcache.Cache; 7 | import net.sf.ehcache.CacheManager; 8 | import net.sf.ehcache.Element; 9 | 10 | /** 11 | * 套利策略管理 12 | * 13 | * @author xiang 14 | * @createDate 2018年12月7日 下午2:56:01 15 | */ 16 | public class HedgingConfigManager { 17 | private HedgingConfigManager() {}; 18 | 19 | public static HedgingConfigManager getInstance() { 20 | return SingletonHolder.instance; 21 | } 22 | 23 | /** 24 | * @param coin 25 | * BTC,ETC... 26 | * @param type 27 | * tn,tq,nq 28 | * @return 29 | */ 30 | public List getConfigs(String coin, String type) { 31 | List result = new LinkedList(); 32 | CacheManager manager = CacheManager.getInstance(); 33 | Cache cache = manager.getCache("hedgingConfigCache"); 34 | List list = cache.getKeys(); 35 | if (list != null) { 36 | for (Object key : list) { 37 | Element e = cache.get(key); 38 | HedgingConfig hc = (HedgingConfig) e.getObjectValue(); 39 | if (hc.getCoin().equalsIgnoreCase(coin) && hc.getType().equalsIgnoreCase(type)) 40 | result.add(hc); 41 | } 42 | } 43 | return result; 44 | } 45 | 46 | 47 | public HedgingConfig getHedgingConfig(String configId) { 48 | 49 | CacheManager manager = CacheManager.getInstance(); 50 | Cache cache = manager.getCache("hedgingConfigCache"); 51 | Element e = cache.get(configId); 52 | if (e != null) { 53 | return (HedgingConfig) e.getObjectValue(); 54 | } 55 | return null; 56 | } 57 | 58 | 59 | public void save(HedgingConfig config) { 60 | update(config); 61 | } 62 | 63 | public void delete(String configId) { 64 | CacheManager manager = CacheManager.getInstance(); 65 | Cache cache = manager.getCache("hedgingConfigCache"); 66 | cache.remove(configId); 67 | cache.flush(); 68 | } 69 | 70 | public void update(HedgingConfig config) { 71 | CacheManager manager = CacheManager.getInstance(); 72 | Cache cache = manager.getCache("hedgingConfigCache"); 73 | Element e = new Element(config.getConfigId(), config, true); 74 | cache.put(e); 75 | cache.flush(); 76 | } 77 | 78 | private static class SingletonHolder { 79 | private static final HedgingConfigManager instance = new HedgingConfigManager(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/HedgingContext.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.HashMap; 4 | import java.util.LinkedList; 5 | import java.util.Map; 6 | 7 | /** 8 | * 套利价差数据存储 9 | * @author xiang 10 | * @createDate 2018年12月10日 下午2:41:31 11 | */ 12 | public class HedgingContext { 13 | /** 14 | * btc,eos... 15 | */ 16 | private String coin; 17 | private static int cacheSize = 4000; 18 | /** 19 | * key (tt,tn,tq,nq) 20 | */ 21 | private Map>> dataCaches = new HashMap>>(); 22 | 23 | public String getCoin() { 24 | return coin; 25 | } 26 | 27 | public void setCoin(String coin) { 28 | this.coin = coin; 29 | } 30 | 31 | public HedgingContext(String coin) { 32 | this.coin = coin; 33 | } 34 | 35 | /** 36 | * @param type tt,tn,tq,nq 37 | * @return 38 | */ 39 | public LinkedList> getHedgingData(String type) { 40 | return dataCaches.get(type); 41 | } 42 | 43 | public void addHedgingData(Map map) { 44 | //tt,tn,tq,nq 45 | String type = (String) map.get("type"); 46 | LinkedList> dataCache = getHedgingData(type); 47 | if (dataCache == null) { 48 | dataCache = new LinkedList>(); 49 | dataCaches.put(type, dataCache); 50 | } 51 | dataCache.add(map); 52 | if (dataCache.size() > cacheSize) { 53 | dataCache.removeFirst(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/HedgingManager.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import net.sf.ehcache.CacheManager; 7 | 8 | /** 9 | * 合约库存管理 保存已被占用的合约张数 10 | * 11 | * @author xiang 12 | * @createDate 2018年12月7日 下午2:56:01 13 | */ 14 | public class HedgingManager { 15 | private HedgingManager() { 16 | 17 | }; 18 | 19 | private List hedgings = new LinkedList(); 20 | public void initHedgings(List list) 21 | { 22 | hedgings=list; 23 | } 24 | public List getHedgings() { 25 | return hedgings; 26 | } 27 | 28 | public void addHedging(Hedging hedging) { 29 | hedgings.add(hedging); 30 | } 31 | 32 | public static HedgingManager getInstance() { 33 | return SingletonHolder.instance; 34 | } 35 | 36 | public void liquidHedging(String hedgingId) { 37 | for (Hedging hedging : hedgings) { 38 | if (hedgingId.equals(hedging.getHedgingId())) { 39 | hedging.setLiquid(true); 40 | return; 41 | } 42 | } 43 | } 44 | 45 | private static class SingletonHolder { 46 | private static final HedgingManager instance = new HedgingManager(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/HedgingTradeClient.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.concurrent.TimeoutException; 9 | 10 | import com.xiang.service.TradeApiService; 11 | 12 | /** 13 | * 每笔交易代理类,集中处理一次性提交所有的交易 14 | * @author xiang 15 | * @createDate 2018年12月28日 上午8:59:25 16 | */ 17 | public class HedgingTradeClient { 18 | private TradeApiService tradeApiService; 19 | 20 | public HedgingTradeClient(TradeApiService tradeApiService) { 21 | this.tradeApiService = tradeApiService; 22 | } 23 | 24 | private List trades = new LinkedList(); 25 | 26 | public void start() { 27 | } 28 | 29 | public synchronized void addHedgingTrade(HedgingTrade trade) { 30 | if (trade != null) { 31 | trades.add(trade); 32 | } 33 | } 34 | 35 | private String getBatchOrdersKey(HedgingTrade trade) { 36 | return trade.getInstrumentId() + "-" + trade.getLeverRate(); 37 | } 38 | 39 | /** 40 | * 将可以一起批量提交的交易进行归并 41 | * 42 | * @param trade 43 | * @param sortTradesMap 44 | * @return 返回可以一起批量提交的交易目前有多少个 45 | */ 46 | private int sortTrade(HedgingTrade trade, Map> sortTradesMap) { 47 | List batchOrders = null; 48 | String key = getBatchOrdersKey(trade); 49 | if (!sortTradesMap.containsKey(key)) { 50 | batchOrders = new ArrayList<>(); 51 | sortTradesMap.put(key, batchOrders); 52 | } else { 53 | batchOrders = sortTradesMap.get(key); 54 | } 55 | batchOrders.add(trade); 56 | return batchOrders.size(); 57 | } 58 | 59 | private void cancelFinish(Map> sortTradesMap) throws TimeoutException { 60 | for (List batchOrders : sortTradesMap.values()) { 61 | if (!batchOrders.isEmpty()) { 62 | cancelFinish(batchOrders); 63 | } 64 | } 65 | } 66 | 67 | private void cancelFinish(List batchOrders) throws TimeoutException { 68 | if (!batchOrders.isEmpty()) { 69 | tradeApiService.batchCancel(batchOrders); 70 | tradeCount++; 71 | batchOrders.clear(); 72 | } 73 | } 74 | 75 | private int tradeCount = 0; 76 | 77 | public void cancelFinish() throws TimeoutException { 78 | tradeCount = 0; 79 | Map> sortTradesMap = new HashMap<>(); 80 | for (HedgingTrade trade : trades) { 81 | if (tradeCount >= 20) { 82 | // 超过了每2秒20次的请求限制 83 | 84 | } else { 85 | int currentCount = sortTrade(trade, sortTradesMap); 86 | if (currentCount == 20) {//每次最多撤销20张单 87 | cancelFinish(sortTradesMap.get(getBatchOrdersKey(trade))); 88 | } 89 | } 90 | } 91 | cancelFinish(sortTradesMap); 92 | trades.clear(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/InstrumentServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.okex.websocket.OkexConstant; 9 | import com.xiang.service.FutureInstrumentService; 10 | import com.xiang.service.Instrument; 11 | import com.xiang.service.InstrumentService; 12 | import com.xiang.service.SpotInstrumentService; 13 | 14 | /** 15 | * 获取现货和期货合约ID服务类 16 | * @author Administrator 17 | * 18 | */ 19 | @Service("instrumentService") 20 | public class InstrumentServiceImpl implements InstrumentService { 21 | @Autowired 22 | FutureInstrumentService futureInstrumentService; 23 | @Autowired 24 | SpotInstrumentService spotInstrumentService; 25 | 26 | @Override 27 | public Instrument getInstrument(String table, String instrumentId) { 28 | switch (table) { 29 | case OkexConstant.FUTURES_DEPTH5: 30 | case OkexConstant.FUTURES_DEPTH: 31 | Instrument instrument = futureInstrumentService.getFutureInstrument(instrumentId); 32 | if (instrument == null) { 33 | futureInstrumentService.refresh(); 34 | } 35 | return instrument; 36 | case OkexConstant.SPOT_DEPTH5: 37 | case OkexConstant.SPOT_DEPTH: 38 | instrument = spotInstrumentService.getSpotInstrument(instrumentId); 39 | if (instrument == null) { 40 | futureInstrumentService.refresh(); 41 | } 42 | return instrument; 43 | } 44 | return null; 45 | } 46 | 47 | @Override 48 | public Instrument getInstrument(String table, String coin, String contractType) { 49 | switch (table) { 50 | case OkexConstant.FUTURES_DEPTH5: 51 | case OkexConstant.FUTURES_DEPTH: 52 | Instrument instrument = futureInstrumentService.getFutureInstrument(coin,contractType); 53 | if (instrument == null) { 54 | System.out.println(coin+" "+contractType); 55 | futureInstrumentService.refresh(); 56 | } 57 | return instrument; 58 | case OkexConstant.SPOT_DEPTH5: 59 | case OkexConstant.SPOT_DEPTH: 60 | instrument = spotInstrumentService.getSpotInstrument(coin,"USDT"); 61 | if (instrument == null) { 62 | futureInstrumentService.refresh(); 63 | } 64 | return instrument; 65 | } 66 | return null; 67 | } 68 | 69 | @Override 70 | public List getSubscribes() { 71 | return null; 72 | } 73 | 74 | @Override 75 | public Instrument getInstrument(String instrumentId) { 76 | Instrument instrument = futureInstrumentService.getFutureInstrument(instrumentId); 77 | if (instrument == null) { 78 | instrument=spotInstrumentService.getSpotInstrument(instrumentId); 79 | } 80 | return instrument; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/Level2Bean.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.math.BigDecimal; 4 | import java.text.NumberFormat; 5 | import java.text.ParseException; 6 | 7 | public class Level2Bean { 8 | private String instrumentId; 9 | private BigDecimal price; 10 | private String volume; 11 | private long time; 12 | private String table; 13 | public String getTable() { 14 | return table; 15 | } 16 | public void setTable(String table) { 17 | this.table = table; 18 | } 19 | public BigDecimal getPrice() { 20 | return price; 21 | } 22 | public float getFloatPrice() 23 | { 24 | return price.floatValue(); 25 | } 26 | public void setPrice(BigDecimal price) { 27 | this.price = price; 28 | } 29 | 30 | public String getVolume() { 31 | return volume; 32 | } 33 | 34 | public void setVolume(String volume) { 35 | this.volume = volume; 36 | } 37 | 38 | public long getTime() { 39 | return time; 40 | } 41 | 42 | public void setTime(long time) { 43 | this.time = time; 44 | } 45 | 46 | public String getInstrumentId() { 47 | return instrumentId; 48 | } 49 | 50 | public void setInstrumentId(String instrumentId) { 51 | this.instrumentId = instrumentId; 52 | } 53 | 54 | public int getIntVolume() { 55 | try { 56 | return NumberFormat.getInstance().parse(volume).intValue(); 57 | } catch (ParseException e) { 58 | // TODO Auto-generated catch block 59 | e.printStackTrace(); 60 | } 61 | return 0; 62 | } 63 | 64 | public double getDoubleVolume() { 65 | try { 66 | return NumberFormat.getInstance().parse(volume).doubleValue(); 67 | } catch (ParseException e) { 68 | // TODO Auto-generated catch block 69 | e.printStackTrace(); 70 | } 71 | return 0; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/LoginServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.alibaba.fastjson.JSONObject; 8 | import com.xiang.service.WebSocketService; 9 | 10 | /** 11 | * 接受ws推送的登录消息处理 12 | * @author xiang 13 | * @createDate 2018年12月26日 下午4:26:14 14 | */ 15 | @Service("loginService") 16 | public class LoginServiceImpl implements WebSocketService { 17 | @Resource(name="webSoketClient") 18 | private WebSoketClient client; 19 | 20 | @Override 21 | public void onReceive(Object obj) { 22 | if (obj instanceof JSONObject) { 23 | JSONObject root = (JSONObject) obj; 24 | String event = root.getString("event"); 25 | if ("login".equals(event)) { 26 | System.out.println(obj); 27 | boolean success = root.getBoolean("success"); 28 | if (success) { 29 | client.setLogin(true); 30 | client.reLoginAddChannel(); 31 | } 32 | } else if ("error".equals(event)) { 33 | System.out.println(obj); 34 | String errorCode = root.getString("errorCode"); 35 | switch (errorCode) { 36 | case "30001": 37 | case "30002": 38 | case "30004": 39 | case "30006": 40 | case "30012": 41 | case "30013": 42 | case "30027": 43 | case "30041": 44 | client.setLogin(false); 45 | break; 46 | } 47 | }else if ("subscribe".equals(event)) { 48 | System.out.println(obj); 49 | } 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/MsgCenterServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.xiang.service.WebSocketService; 8 | import com.xiang.spring.LogExecuteTime; 9 | 10 | /** 11 | * 接收ws推送的消息处理服务 12 | * @author xiang 13 | * 14 | */ 15 | @Service("msgCenterService") 16 | public class MsgCenterServiceImpl implements WebSocketService { 17 | 18 | @Resource(name="loginService") 19 | private WebSocketService loginService; 20 | 21 | @Resource(name="tradeService") 22 | private WebSocketService tradeService; 23 | 24 | @Resource(name="instrumentsDepthService") 25 | private WebSocketService instrumentsDepthService; 26 | 27 | @Resource(name="storeService") 28 | private WebSocketService storeService; 29 | 30 | @Resource(name="startHedgingService") 31 | private WebSocketService startHedgingService; 32 | 33 | @Resource(name="futureAccountService") 34 | private WebSocketService futureAccountService; 35 | @LogExecuteTime 36 | @Override 37 | public void onReceive(Object obj) { 38 | loginService.onReceive(obj);//处理登录与登出 39 | futureAccountService.onReceive(obj);//处理账户权益数据 40 | instrumentsDepthService.onReceive(obj);//处理深度委托数据s 41 | tradeService.onReceive(obj);//处理交易数据 42 | startHedgingService.onReceive(obj);//策略套利监控购买,如果需要实时实现结束策略套利监控,可以在这里开启finishHedgingService服务,目前结束策略套利监控只是使用200毫秒采集监控一次 43 | storeService.onReceive(obj);//数据存储服务 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/StoreServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.alibaba.fastjson.JSON; 10 | import com.xiang.service.WebSocketService; 11 | 12 | /** 13 | * @author xiang 14 | * @createDate 2018年12月26日 下午3:43:24 15 | */ 16 | @Service("storeService") 17 | public class StoreServiceImpl implements WebSocketService{ 18 | private Logger depthLogger = LogManager.getLogger("depth"); 19 | @Override 20 | public void onReceive(Object obj) { 21 | // TODO Auto-generated method stub 22 | depthLogger.info(JSON.toJSONString(obj)); 23 | } 24 | @PreDestroy 25 | public void destroy() { 26 | depthLogger.traceExit(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/SystemConfig.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import com.okcoin.commons.okex.open.api.config.APIConfiguration; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年11月20日 下午6:54:45 8 | */ 9 | public class SystemConfig extends APIConfiguration{ 10 | private String okWebSocketURL; 11 | private String coins; 12 | private String signKey; 13 | public String getSignKey() { 14 | return signKey; 15 | } 16 | 17 | public void setSignKey(String signKey) { 18 | this.signKey = signKey; 19 | } 20 | 21 | public String getOkWebSocketURL() { 22 | return okWebSocketURL; 23 | } 24 | 25 | public void setOkWebSocketURL(String okWebSocketURL) { 26 | this.okWebSocketURL = okWebSocketURL; 27 | } 28 | 29 | public String getCoins() { 30 | return coins; 31 | } 32 | 33 | public void setCoins(String coins) { 34 | this.coins = coins; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/TradeServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.Iterator; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.alibaba.fastjson.JSON; 8 | import com.alibaba.fastjson.JSONArray; 9 | import com.alibaba.fastjson.JSONObject; 10 | import com.okex.websocket.FutureOrder; 11 | import com.xiang.service.WebSocketService; 12 | 13 | /** 14 | * 交易数据服务类 15 | * @author xiang 16 | * @createDate 2018年12月26日 下午3:48:38 17 | */ 18 | @Service("tradeService") 19 | public class TradeServiceImpl implements WebSocketService{ 20 | TradeManager tradeManager=TradeManager.getInstance(); 21 | @Override 22 | public void onReceive(Object obj) { 23 | if (obj instanceof JSONObject) { 24 | JSONObject root = (JSONObject) obj; 25 | if (root.containsKey("table")) { 26 | String table = root.getString("table"); 27 | if ("futures/order".equals(table)) { 28 | if (root.containsKey("data")) { 29 | System.out.println(obj); 30 | JSONArray data = root.getJSONArray("data"); 31 | Iterator it = data.iterator(); 32 | while (it.hasNext()) { 33 | Object order = it.next(); 34 | if (order instanceof JSONObject) { 35 | JSONObject orderJSON = (JSONObject) order; 36 | FutureOrder futuresOrder=JSON.toJavaObject(orderJSON, FutureOrder.class); 37 | tradeManager.updateFuturesOrder(futuresOrder); 38 | } 39 | } 40 | } 41 | } 42 | } 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/service/impl/VolumeManager.java: -------------------------------------------------------------------------------- 1 | package com.xiang.service.impl; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import org.springframework.util.ObjectUtils; 7 | 8 | /** 9 | * 合约库存管理 保存已被占用的合约张数 10 | * 11 | * @author xiang 12 | * @createDate 2018年12月7日 下午2:56:01 13 | */ 14 | public class VolumeManager { 15 | private VolumeManager() { 16 | }; 17 | 18 | public static VolumeManager getInstance() { 19 | return SingletonHolder.instance; 20 | } 21 | 22 | public void init(List list) { 23 | if (ObjectUtils.isEmpty(list)) { 24 | for (Hedging hedging : list) { 25 | getSetVolume(hedging.getHedgingConfig(), hedging.getAmount()); 26 | } 27 | } 28 | } 29 | 30 | ConcurrentHashMap usedVolumesMap = new ConcurrentHashMap(); 31 | 32 | public synchronized int getVolume(HedgingConfig config) { 33 | if (!usedVolumesMap.containsKey(config.getConfigId())) 34 | usedVolumesMap.put(config.getConfigId(), 0); 35 | int volume = config.getVolume() - usedVolumesMap.get(config.getConfigId()); 36 | return volume; 37 | } 38 | 39 | /** 40 | * 占用合约张数,如果要的合约张数超过库存,将占用失败返回0 41 | * 42 | * @param config 43 | * @param volume 44 | * @return 45 | */ 46 | public synchronized int getSetVolume(HedgingConfig config, int volume) { 47 | if (volume < 0) 48 | return 0; 49 | int usedVolume = 0; 50 | if (usedVolumesMap.containsKey(config.getConfigId())) 51 | usedVolume = usedVolumesMap.get(config.getConfigId()); 52 | int preVolume = volume + usedVolume;// 操作后预期合约张数 53 | if (preVolume > config.getVolume()) 54 | return 0; 55 | usedVolumesMap.put(config.getConfigId(), preVolume); 56 | return volume; 57 | } 58 | 59 | /** 60 | * 释放合约张数 61 | * 62 | * @param config 63 | * @param volume 64 | * @return 65 | */ 66 | public synchronized void releaseVolume(HedgingConfig config, int volume) { 67 | int usedVolume = 0; 68 | if (usedVolumesMap.containsKey(config.getConfigId())) 69 | usedVolume = usedVolumesMap.get(config.getConfigId()); 70 | int preVolume = usedVolume - volume;// 操作后预期合约张数 71 | if (preVolume < 0) 72 | preVolume = 0; 73 | usedVolumesMap.put(config.getConfigId(), preVolume); 74 | } 75 | 76 | private static class SingletonHolder { 77 | private static final VolumeManager instance = new VolumeManager(); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/shiro/JWTCredentialsMatcher.java: -------------------------------------------------------------------------------- 1 | package com.xiang.shiro; 2 | 3 | import java.util.Map; 4 | 5 | import org.apache.shiro.authc.AuthenticationInfo; 6 | import org.apache.shiro.authc.AuthenticationToken; 7 | import org.apache.shiro.authc.credential.CredentialsMatcher; 8 | 9 | public class JWTCredentialsMatcher implements CredentialsMatcher{ 10 | 11 | @Override 12 | public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) { 13 | String token = (String) authenticationToken.getCredentials(); 14 | Map userMap = JWTAuth.verifyToken(token); 15 | if (userMap.containsKey(JWTAuth.USERNAME)) { 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/shiro/JWTToken.java: -------------------------------------------------------------------------------- 1 | package com.xiang.shiro; 2 | 3 | import org.apache.shiro.authc.HostAuthenticationToken; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年12月20日 下午2:41:25 8 | */ 9 | public class JWTToken implements HostAuthenticationToken { 10 | 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 1L; 15 | private String token; 16 | private String host; 17 | 18 | public JWTToken(String token) { 19 | this(token, null); 20 | } 21 | public JWTToken(String token, String host) { 22 | this.token = token; 23 | this.host = host; 24 | } 25 | public String getToken(){ 26 | return this.token; 27 | } 28 | /* @return username 29 | */ 30 | @Override 31 | public Object getPrincipal() { 32 | return token; 33 | } 34 | 35 | /* @return password 36 | */ 37 | @Override 38 | public Object getCredentials() { 39 | return token; 40 | } 41 | 42 | @Override 43 | public String getHost() { 44 | return host; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/shiro/JwtRealm.java: -------------------------------------------------------------------------------- 1 | package com.xiang.shiro; 2 | 3 | import java.util.Map; 4 | 5 | import javax.annotation.Resource; 6 | 7 | import org.apache.shiro.authc.AuthenticationInfo; 8 | import org.apache.shiro.authc.AuthenticationToken; 9 | import org.apache.shiro.authc.SimpleAuthenticationInfo; 10 | import org.apache.shiro.authz.AuthorizationInfo; 11 | import org.apache.shiro.authz.SimpleAuthorizationInfo; 12 | import org.apache.shiro.realm.AuthorizingRealm; 13 | import org.apache.shiro.subject.PrincipalCollection; 14 | 15 | import com.xiang.user.service.UserService; 16 | import com.xiang.vo.UserVo; 17 | 18 | /** 19 | * @author xiang 20 | * @createDate 2018年12月20日 上午11:56:45 21 | */ 22 | public class JwtRealm extends AuthorizingRealm { 23 | 24 | @Resource 25 | private UserService userService; 26 | /* 27 | * 认证 28 | */ 29 | @Override 30 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken principals) { 31 | JWTToken jwtToken = (JWTToken) principals; 32 | String token=jwtToken.getToken(); 33 | SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(token, token, "jwtRealm"); 34 | return authenticationInfo; 35 | } 36 | 37 | @Override 38 | public boolean supports(AuthenticationToken token) { 39 | return token instanceof JWTToken; 40 | } 41 | 42 | /* 43 | * 权限 44 | */ 45 | @Override 46 | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { 47 | String token = (String) super.getAvailablePrincipal(principals); 48 | Map userMap = JWTAuth.verifyToken(token); 49 | String userName = userMap.get(JWTAuth.USERNAME); 50 | UserVo user = userService.login(userName); 51 | SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); 52 | simpleAuthorizationInfo.addRole(user.getRole()); 53 | return simpleAuthorizationInfo; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/xiang/shiro/UserFormAuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.xiang.shiro; 2 | 3 | import javax.servlet.ServletRequest; 4 | import javax.servlet.ServletResponse; 5 | import javax.servlet.http.HttpServletResponse; 6 | 7 | import org.apache.shiro.authc.AuthenticationException; 8 | import org.apache.shiro.authc.AuthenticationToken; 9 | import org.apache.shiro.subject.Subject; 10 | import org.apache.shiro.web.filter.authc.FormAuthenticationFilter; 11 | 12 | import com.alibaba.fastjson.JSONObject; 13 | import com.xiang.spring.ErrorCodes; 14 | import com.xiang.spring.Response; 15 | 16 | public class UserFormAuthenticationFilter extends FormAuthenticationFilter { 17 | 18 | @Override 19 | protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception { 20 | HttpServletResponse httpServletResponse = (HttpServletResponse) response; 21 | httpServletResponse.setCharacterEncoding("UTF-8"); 22 | httpServletResponse.setContentType("application/json"); 23 | Response res = new Response(null, ErrorCodes.LOGIN); 24 | httpServletResponse.getWriter().write(JSONObject.toJSON(res).toString()); 25 | return false; 26 | } 27 | 28 | @Override 29 | protected boolean isLoginSubmission(ServletRequest request, ServletResponse response) { 30 | return super.isLoginSubmission(request, response); 31 | } 32 | 33 | @Override 34 | protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, 35 | ServletResponse response) throws Exception { 36 | return super.onLoginSuccess(token, subject, request, response); 37 | } 38 | 39 | @Override 40 | protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request, 41 | ServletResponse response) { 42 | return super.onLoginFailure(token, e, request, response); 43 | } 44 | 45 | @Override 46 | protected boolean executeLogin(ServletRequest request, ServletResponse response) throws Exception { 47 | return super.executeLogin(request, response); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/shiro/UserRealm.java: -------------------------------------------------------------------------------- 1 | package com.xiang.shiro; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.apache.shiro.authc.AuthenticationInfo; 6 | import org.apache.shiro.authc.AuthenticationToken; 7 | import org.apache.shiro.authc.SimpleAuthenticationInfo; 8 | import org.apache.shiro.authc.UsernamePasswordToken; 9 | import org.apache.shiro.authz.AuthorizationInfo; 10 | import org.apache.shiro.authz.SimpleAuthorizationInfo; 11 | import org.apache.shiro.realm.AuthorizingRealm; 12 | import org.apache.shiro.subject.PrincipalCollection; 13 | import org.springframework.util.ObjectUtils; 14 | 15 | import com.xiang.spring.APIException; 16 | import com.xiang.spring.ErrorCodes; 17 | import com.xiang.user.service.UserService; 18 | import com.xiang.vo.UserVo; 19 | 20 | /** 21 | * @author xiang 22 | * @createDate 2018年12月20日 上午11:56:45 23 | */ 24 | public class UserRealm extends AuthorizingRealm { 25 | 26 | @Resource 27 | private UserService userService; 28 | 29 | /* 30 | * 认证 31 | */ 32 | @Override 33 | protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken principals) { 34 | UsernamePasswordToken token = (UsernamePasswordToken) principals; 35 | String userName =token.getUsername(); 36 | UserVo user = userService.login(userName); 37 | if (ObjectUtils.isEmpty(user)) { 38 | throw new APIException(ErrorCodes.AUTH); 39 | } 40 | return new SimpleAuthenticationInfo(user, user.getPassword(), "userRealm"); 41 | } 42 | 43 | @Override 44 | public boolean supports(AuthenticationToken token) { 45 | return token instanceof UsernamePasswordToken; 46 | } 47 | 48 | /* 49 | * 权限 50 | */ 51 | @Override 52 | protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) { 53 | String userName = (String) super.getAvailablePrincipal(principals); 54 | UserVo user = userService.login(userName); 55 | SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo(); 56 | simpleAuthorizationInfo.addRole(user.getRole()); 57 | return simpleAuthorizationInfo; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/APIException.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | /** 4 | * API Exception 5 | * 6 | * @author xiang 7 | * @version 1.0.0 8 | * @date 2018/11/22 19:59 9 | */ 10 | public class APIException extends RuntimeException { 11 | 12 | private ErrorCodes err; 13 | 14 | public APIException(ErrorCodes err) { 15 | super(err.getErrorMessage()); 16 | this.err = err; 17 | } 18 | 19 | public ErrorCodes getErr() { 20 | return err; 21 | } 22 | 23 | public void setErr(ErrorCodes err) { 24 | this.err = err; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.Filter; 6 | import javax.servlet.FilterChain; 7 | import javax.servlet.FilterConfig; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.ServletRequest; 10 | import javax.servlet.ServletResponse; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.xiang.shiro.JWTAuth; 14 | 15 | public class CorsFilter implements Filter{ 16 | @Override 17 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 18 | HttpServletResponse response = (HttpServletResponse) servletResponse; 19 | response.setHeader("Access-Control-Allow-Origin", "*"); 20 | response.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,PUT,HEAD,PATCH"); 21 | response.setHeader("Access-Control-Allow-Headers", "content-type,"+JWTAuth.TOKENHEADER); 22 | response.setHeader("Access-Control-Expose-Headers", JWTAuth.TOKENHEADER); 23 | response.setHeader("Access-Control-Allow-Credentials", "true"); 24 | filterChain.doFilter(servletRequest, servletResponse); 25 | } 26 | 27 | @Override 28 | public void init(FilterConfig filterConfig) throws ServletException { 29 | // TODO Auto-generated method stub 30 | 31 | } 32 | 33 | @Override 34 | public void destroy() { 35 | // TODO Auto-generated method stub 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/ErrorCodes.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | /** 4 | * @author xiang 5 | * @createDate 2018年10月19日 上午11:00:47 6 | */ 7 | public enum ErrorCodes { 8 | OK(0, ""), ERROR_PARAM(1, "参数错误"), TIME_OUT(2, "请求交易所API超时"), LOGIN(3, "请先登录,再进行操作!"), ERROR(4, "系统错误"), AUTH(5, "账号或者密码错误!"); 9 | private int errorCode; 10 | private String errorMessage; 11 | 12 | public static ErrorCodes createErrorCode(String errorMessage) { 13 | ERROR.setErrorMessage(errorMessage); 14 | return ERROR; 15 | } 16 | 17 | private ErrorCodes(int errorCode, String errorMessage) { 18 | 19 | this.errorCode = errorCode; 20 | 21 | this.errorMessage = errorMessage; 22 | 23 | } 24 | 25 | public int getErrorCode() { 26 | 27 | return errorCode; 28 | 29 | } 30 | 31 | public void setErrorCode(int errorCode) { 32 | 33 | this.errorCode = errorCode; 34 | 35 | } 36 | 37 | public String getErrorMessage() { 38 | return errorMessage; 39 | } 40 | 41 | public void setErrorMessage(String errorMessage) { 42 | 43 | this.errorMessage = errorMessage; 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/FastJsonConfigExt.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.BigInteger; 5 | 6 | import com.alibaba.fastjson.serializer.SerializeConfig; 7 | import com.alibaba.fastjson.serializer.ToStringSerializer; 8 | import com.alibaba.fastjson.support.config.FastJsonConfig; 9 | 10 | /** 11 | * @author xiang 解决js long 精度丢失问题,统一大数类型使用string输出 12 | */ 13 | public class FastJsonConfigExt extends FastJsonConfig { 14 | public FastJsonConfigExt() { 15 | super(); 16 | SerializeConfig serializeConfig = SerializeConfig.globalInstance; 17 | serializeConfig.put(BigInteger.class, ToStringSerializer.instance); 18 | serializeConfig.put(BigDecimal.class, ToStringSerializer.instance); 19 | serializeConfig.put(Long.class, ToStringSerializer.instance); 20 | serializeConfig.put(Long.TYPE, ToStringSerializer.instance); 21 | this.setSerializeConfig(serializeConfig); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/LogExecuteTime.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author xiang 10 | * @createDate 2018年12月5日 上午9:56:48 11 | */ 12 | @Target({java.lang.annotation.ElementType.METHOD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Documented 15 | public @interface LogExecuteTime { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/LogTimeInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.annotation.Around; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.aspectj.lang.annotation.Pointcut; 7 | import org.springframework.context.annotation.Profile; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * @author xiang 12 | * @createDate 2018年12月5日 上午9:57:36 13 | */ 14 | @Aspect 15 | @Component 16 | @Profile("!test") 17 | public class LogTimeInterceptor { 18 | @Pointcut("@annotation(com.xiang.spring.LogExecuteTime)") 19 | public void logTimeMethodPointcut() { 20 | 21 | } 22 | 23 | @Around("logTimeMethodPointcut()") 24 | public Object interceptor(ProceedingJoinPoint pjp) { 25 | long startTime = System.currentTimeMillis(); 26 | Object result = null; 27 | try { 28 | result = pjp.proceed(); 29 | } catch (Throwable e) { 30 | throw new RuntimeException(e); 31 | } 32 | long time=System.currentTimeMillis() - startTime; 33 | if(time>50) 34 | System.out.println(pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName() + " spend " 35 | + time + "ms"); 36 | 37 | return result; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/LoginToken.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.PARAMETER) 10 | public @interface LoginToken { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/LoginTokenArgumentResolver.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | import org.springframework.core.MethodParameter; 8 | import org.springframework.web.bind.support.WebDataBinderFactory; 9 | import org.springframework.web.context.request.NativeWebRequest; 10 | import org.springframework.web.method.support.HandlerMethodArgumentResolver; 11 | import org.springframework.web.method.support.ModelAndViewContainer; 12 | 13 | import com.xiang.controller.XAuthToken; 14 | import com.xiang.shiro.JWTAuth; 15 | 16 | public class LoginTokenArgumentResolver implements HandlerMethodArgumentResolver { 17 | @Override 18 | public boolean supportsParameter(MethodParameter parameter) { 19 | if (parameter.getParameterAnnotation(LoginToken.class) != null 20 | && parameter.getParameterType() == XAuthToken.class) { 21 | return true; 22 | } 23 | return false; 24 | } 25 | 26 | @Override 27 | public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, 28 | NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { 29 | HttpServletRequest httpServletRequest = (HttpServletRequest) webRequest.getNativeRequest(); 30 | String token = httpServletRequest.getHeader(JWTAuth.TOKENHEADER); 31 | Map claims =JWTAuth.verifyToken(token); 32 | XAuthToken xAuthToken=JWTAuth.getXAuthToken(claims); 33 | xAuthToken.setToken(token); 34 | return xAuthToken; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/Response.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.util.Date; 4 | 5 | import org.apache.commons.codec.digest.DigestUtils; 6 | 7 | import com.xiang.util.Constant; 8 | 9 | /** 10 | * @author xiang 11 | * @createDate 2018年10月19日 上午10:51:15 12 | */ 13 | public class Response { 14 | public Response() { 15 | this.timestamp=new Date(); 16 | } 17 | public Response( ErrorCodes errorCode) { 18 | this(null,errorCode); 19 | } 20 | public Response(Object data, ErrorCodes errorCode) { 21 | this.timestamp=new Date(); 22 | this.data = data; 23 | this.errorCode = errorCode.getErrorCode(); 24 | this.message = errorCode.getErrorMessage(); 25 | if (this.errorCode == ErrorCodes.OK.getErrorCode()) { 26 | success = true; 27 | } else { 28 | success = false; 29 | } 30 | } 31 | private Object data; 32 | private int errorCode; 33 | private String message; 34 | private boolean success; 35 | private Date timestamp; 36 | public Date getTimestamp() { 37 | return timestamp; 38 | } 39 | 40 | public void setTimestamp(Date timestamp) { 41 | this.timestamp = timestamp; 42 | } 43 | 44 | public String getSign() { 45 | return DigestUtils.md5Hex(timestamp.getTime()+Constant.SIGNKEY); 46 | } 47 | 48 | public Object getData() { 49 | return data; 50 | } 51 | public void setData(Object data) { 52 | this.data = data; 53 | } 54 | public int getErrorCode() { 55 | return errorCode; 56 | } 57 | public void setErrorCode(int errorCode) { 58 | this.errorCode = errorCode; 59 | } 60 | public String getMessage() { 61 | return message; 62 | } 63 | public void setMessage(String message) { 64 | this.message = message; 65 | } 66 | public boolean isSuccess() { 67 | return success; 68 | } 69 | public void setSuccess(boolean success) { 70 | this.success = success; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/ResponseAdvice.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import java.util.concurrent.TimeoutException; 4 | 5 | import org.apache.shiro.authc.AuthenticationException; 6 | import org.springframework.core.MethodParameter; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.converter.HttpMessageConverter; 9 | import org.springframework.http.server.ServerHttpRequest; 10 | import org.springframework.http.server.ServerHttpResponse; 11 | import org.springframework.web.bind.annotation.ControllerAdvice; 12 | import org.springframework.web.bind.annotation.ExceptionHandler; 13 | import org.springframework.web.bind.annotation.ResponseBody; 14 | import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; 15 | 16 | /** 17 | * @author xiang 18 | * @createDate 2018年10月19日 上午10:41:01 19 | */ 20 | @ControllerAdvice 21 | public class ResponseAdvice implements ResponseBodyAdvice { 22 | 23 | @Override 24 | public boolean supports(MethodParameter returnType, Class> converterType) { 25 | // TODO Auto-generated method stub 26 | return com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter.class.isAssignableFrom(converterType); 27 | } 28 | 29 | @ExceptionHandler(APIException.class) 30 | @ResponseBody 31 | public Object exceptionHander(APIException exception) { 32 | return exception.getErr(); 33 | } 34 | 35 | @ExceptionHandler(TimeoutException.class) 36 | @ResponseBody 37 | public Object exceptionHander(TimeoutException exception) { 38 | return ErrorCodes.TIME_OUT; 39 | } 40 | 41 | @ExceptionHandler(Exception.class) 42 | @ResponseBody 43 | public ErrorCodes exceptionHandler(Exception e) { 44 | e.printStackTrace(); 45 | if (e instanceof APIException) { // 自定义异常,直接返回 46 | APIException APIException = (APIException) e; 47 | return APIException.getErr(); 48 | } else if (e instanceof AuthenticationException) {// 认证错误是用户名,密码不正确 49 | return ErrorCodes.AUTH; 50 | } 51 | return ErrorCodes.ERROR; // 其他异常,返回"系统错误" 52 | } 53 | 54 | @Override 55 | public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, 56 | Class> selectedConverterType, ServerHttpRequest request, 57 | ServerHttpResponse response) { 58 | if (body == null) 59 | return null; 60 | Response res = null; 61 | if (body instanceof ErrorCodes) { 62 | res = new Response(null, (ErrorCodes) body); 63 | } else { 64 | res = new Response(body, ErrorCodes.OK); 65 | } 66 | return res; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/spring/SpringContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.xiang.spring; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.util.ObjectUtils; 8 | 9 | @Component 10 | public class SpringContextHolder implements ApplicationContextAware { 11 | public static ApplicationContext applicationContext; 12 | 13 | @Override 14 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 15 | SpringContextHolder.applicationContext = applicationContext; 16 | System.out.println("setApplicationContext" + " " + getActiveProfile()); 17 | } 18 | 19 | public static String getActiveProfile() { 20 | String[] activeProfiles = applicationContext.getEnvironment().getActiveProfiles(); 21 | if (ObjectUtils.isEmpty(activeProfiles)) { 22 | activeProfiles = applicationContext.getEnvironment().getDefaultProfiles(); 23 | } 24 | return activeProfiles[0]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/user/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.xiang.user.service; 2 | 3 | import com.xiang.vo.UserVo; 4 | 5 | /** 6 | * @author xiang 7 | * @createDate 2018年12月20日 下午2:18:00 8 | */ 9 | public interface UserService { 10 | public UserVo login(String userName,String password); 11 | public UserVo login(String userName); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/user/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.xiang.user.service.impl; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Objects; 6 | import java.util.Properties; 7 | 8 | import javax.annotation.Resource; 9 | 10 | import org.apache.commons.codec.digest.DigestUtils; 11 | import org.springframework.beans.BeanUtils; 12 | import org.springframework.stereotype.Service; 13 | 14 | import com.xiang.po.User; 15 | import com.xiang.shiro.JWTAuth; 16 | import com.xiang.spring.APIException; 17 | import com.xiang.spring.ErrorCodes; 18 | import com.xiang.user.service.UserService; 19 | import com.xiang.vo.UserVo; 20 | 21 | /** 22 | * @author xiang 23 | * @createDate 2018年12月20日 下午2:18:51 24 | */ 25 | @Service("userService") 26 | public class UserServiceImpl implements UserService { 27 | @Resource 28 | Properties users; 29 | public User getQueryUser(String userName) { 30 | // 实现自己的用户逻辑 31 | if (users.containsKey(userName)) { 32 | User user = new User(); 33 | user.setUserName(userName); 34 | String plainPwd=users.getProperty(userName); 35 | user.setPassword(DigestUtils.md5Hex(plainPwd)); 36 | user.setPermission("admin"); 37 | user.setRole("admin"); 38 | return user; 39 | } 40 | throw new APIException(ErrorCodes.AUTH); 41 | } 42 | 43 | @Override 44 | public UserVo login(String userName, String password) { 45 | // TODO Auto-generated method stub 46 | String passwordSercet = DigestUtils.md5Hex(password); 47 | User user = getQueryUser(userName); 48 | if (!Objects.isNull(user)) { 49 | if (passwordSercet.equals(user.getPassword())) { 50 | return getUserVo(user); 51 | } 52 | } 53 | throw new APIException(ErrorCodes.AUTH); 54 | } 55 | 56 | public UserVo getUserVo(User user) { 57 | UserVo vo = new UserVo(); 58 | BeanUtils.copyProperties(user, vo); 59 | Map claims = new HashMap(); 60 | claims.put(JWTAuth.USERNAME, vo.getUserName()); 61 | vo.setToken(JWTAuth.createToken(claims)); 62 | return vo; 63 | } 64 | 65 | @Override 66 | public UserVo login(String userName) { 67 | return getUserVo(getQueryUser(userName)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/util/Constant.java: -------------------------------------------------------------------------------- 1 | package com.xiang.util; 2 | 3 | public class Constant { 4 | 5 | public static String SIGNKEY="dfgfdgrets@3434k$rr"; 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/xiang/vo/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.xiang.vo; 2 | 3 | import com.xiang.po.User; 4 | 5 | public class UserVo extends User{ 6 | private String token; 7 | 8 | public String getToken() { 9 | return token; 10 | } 11 | 12 | public void setToken(String token) { 13 | this.token = token; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/resources/development/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 15 | 16 | 17 | 25 | 31 | 37 | -------------------------------------------------------------------------------- /src/main/resources/development/system.properties: -------------------------------------------------------------------------------- 1 | # activeMQ url 2 | broker_url=tcp\://127.0.0.1:61616 3 | # okex ws v3 url 4 | ok_websocket_url=wss\://okexcomreal.bafang.com\:10442/ws/v3 5 | # okex rest v3 url 6 | ok_rest_url=https\://www.okex.me 7 | 8 | ok_api_key=your api key 9 | ok_secret_key=your secret key 10 | ok_passphrase=your passphrase 11 | ok_coins=btc,ltc,eth,etc,bch,xrp,eos 12 | #ok_coins=btc 13 | 14 | #jwt SECRET 15 | jwt_secret=MQLMNQNQJQKwwftsdfXXkjsdrow38854545fdf -------------------------------------------------------------------------------- /src/main/resources/development/user.properties: -------------------------------------------------------------------------------- 1 | admin=123456 2 | test=123456 -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /srv/depthlog 5 | depth 6 | 7 | 8 | 9 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/resources/production/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 14 | 15 | 16 | 17 | 25 | 31 | 37 | -------------------------------------------------------------------------------- /src/main/resources/production/system.properties: -------------------------------------------------------------------------------- 1 | broker_url=tcp\://127.0.0.1\:61616 2 | ok_websocket_url=wss\://real.okex.com\:10442/ws/v3 3 | ok_rest_url=https\://www.okex.com 4 | ok_api_key=your api key 5 | ok_secret_key=your secret key 6 | ok_passphrase=your passphrase 7 | ok_coins=btc,ltc,eth,etc,bch,xrp,eos 8 | 9 | #jwt SECRET 10 | jwt_secret=MQLMNQNQJQKwwftsdfXXkjsdrow38854545fdf -------------------------------------------------------------------------------- /src/main/resources/production/user.properties: -------------------------------------------------------------------------------- 1 | admin=123456 2 | test=123456 -------------------------------------------------------------------------------- /src/main/resources/spring/spring-context-cache.xml: -------------------------------------------------------------------------------- 1 | 2 | 25 | 27 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | index.html 9 | index.htm 10 | index.jsp 11 | 12 | 13 | contextConfigLocation 14 | classpath*:spring/spring-context-*.xml 15 | 16 | 17 | spring.profiles.default 18 | development 19 | 20 | 21 | corsFilter 22 | com.xiang.spring.CorsFilter 23 | 24 | 25 | corsFilter 26 | /* 27 | 28 | 29 | encodingFilter 30 | org.springframework.web.filter.CharacterEncodingFilter 31 | 32 | encoding 33 | utf-8 34 | 35 | 36 | 37 | encodingFilter 38 | /* 39 | 40 | 41 | shiroFilter 42 | org.springframework.web.filter.DelegatingFilterProxy 43 | 44 | 45 | shiroFilter 46 | /* 47 | 48 | 49 | net.sf.ehcache.constructs.web.ShutdownListener 50 | 51 | 52 | org.springframework.web.context.ContextLoaderListener 53 | 54 | 55 | appServlet 56 | org.springframework.web.servlet.DispatcherServlet 57 | 58 | contextConfigLocation 59 | classpath:spring/springmvc.xml 60 | 61 | 1 62 | 63 | 64 | appServlet 65 | / 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 |

api it's running

4 | 5 | 6 | --------------------------------------------------------------------------------