├── .gitignore ├── README.md ├── pom.xml ├── qt-admin ├── pom.xml └── src │ ├── main │ ├── docker │ │ └── DockerFile │ ├── java │ │ └── com │ │ │ └── quant │ │ │ └── admin │ │ │ ├── AppAdmin.java │ │ │ ├── component │ │ │ ├── IMailServiceImpl.java │ │ │ ├── OrderIdReceiver.java │ │ │ ├── ProfitReceiver.java │ │ │ └── RobotMsgReceiver.java │ │ │ ├── config │ │ │ ├── AsyncConfig.java │ │ │ ├── GlobalCorsConfig.java │ │ │ ├── MybatisPlusConfig.java │ │ │ ├── SubscriberConfig.java │ │ │ └── WebSocketConfig.java │ │ │ ├── controller │ │ │ ├── AccountController.java │ │ │ ├── BalanceController.java │ │ │ ├── BaseController.java │ │ │ ├── IndicatorController.java │ │ │ ├── NodeController.java │ │ │ ├── OrderController.java │ │ │ ├── OrderProfitController.java │ │ │ ├── RobotController.java │ │ │ ├── StrategyController.java │ │ │ ├── SymbolController.java │ │ │ └── UserController.java │ │ │ ├── dao │ │ │ ├── AccountMapper.java │ │ │ ├── BalanceMapper.java │ │ │ ├── OrderProfitMapper.java │ │ │ ├── OrdersMapper.java │ │ │ ├── RobotMapper.java │ │ │ ├── StrategyMapper.java │ │ │ ├── SymbolMapper.java │ │ │ └── UserMapper.java │ │ │ ├── rest │ │ │ ├── RobotClientService.java │ │ │ └── impl │ │ │ │ └── RobotClientServiceImpl.java │ │ │ ├── service │ │ │ ├── AccountService.java │ │ │ ├── BalanceService.java │ │ │ ├── IMailService.java │ │ │ ├── OrderProfitService.java │ │ │ ├── OrdersService.java │ │ │ ├── RobotService.java │ │ │ ├── StrategyService.java │ │ │ ├── SymbolService.java │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ ├── AccountServiceImpl.java │ │ │ │ ├── BalanceServiceImpl.java │ │ │ │ ├── OrderProfitServiceImpl.java │ │ │ │ ├── OrdersServiceImpl.java │ │ │ │ ├── RobotServiceImpl.java │ │ │ │ ├── StrategyServiceImpl.java │ │ │ │ ├── SymbolServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ ├── task │ │ │ ├── RobotStatusTask.java │ │ │ └── SymbolTask.java │ │ │ └── utils │ │ │ └── MysqlGenerator.java │ └── resources │ │ ├── application-dev.yml │ │ ├── application-prod.yml │ │ ├── application.yml │ │ ├── banner.txt │ │ ├── logback-spring.xml │ │ └── mapper │ │ ├── AccountMapper.xml │ │ ├── BalanceMapper.xml │ │ ├── OrderProfitMapper.xml │ │ ├── OrdersMapper.xml │ │ ├── RobotMapper.xml │ │ ├── StrategyMapper.xml │ │ ├── SymbolMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── quant │ └── admin │ └── QtParentApplicationTests.java ├── qt-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── quant │ │ │ └── client │ │ │ ├── AppClient.java │ │ │ ├── config │ │ │ └── ThreadPool.java │ │ │ ├── controller │ │ │ └── BotController.java │ │ │ ├── service │ │ │ ├── RobotService.java │ │ │ └── impl │ │ │ │ └── RobotServiceImpl.java │ │ │ └── task │ │ │ ├── IndicatorRobotOperate.java │ │ │ └── SimpleNumRobotOperate.java │ └── resources │ │ ├── application-dev.yml │ │ ├── application-prod.yml │ │ ├── application.yml │ │ ├── banner.txt │ │ └── logback-spring.xml │ └── test │ └── java │ └── Test.java ├── qt-common ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── quant │ │ └── common │ │ ├── config │ │ ├── JsonConfig.java │ │ ├── RedisConfig.java │ │ ├── RedisUtil.java │ │ ├── RestTemplateConfig.java │ │ └── VpnProxyConfig.java │ │ ├── constans │ │ ├── IndicatorCons.java │ │ └── RobotRedisKeyConfig.java │ │ ├── domain │ │ ├── bo │ │ │ └── RobotBo.java │ │ ├── entity │ │ │ ├── Account.java │ │ │ ├── Balance.java │ │ │ ├── MarketOrder.java │ │ │ ├── OrderProfit.java │ │ │ ├── Orders.java │ │ │ ├── Robot.java │ │ │ ├── Strategy.java │ │ │ ├── Symbol.java │ │ │ └── User.java │ │ ├── request │ │ │ ├── CreateOrderRequest.java │ │ │ ├── DepthRequest.java │ │ │ └── IntrustOrdersDetailRequest.java │ │ ├── response │ │ │ ├── Account.java │ │ │ ├── Accounts.java │ │ │ ├── AccountsResponse.java │ │ │ ├── ApiResponse.java │ │ │ ├── Balance.java │ │ │ ├── BalanceBean.java │ │ │ ├── BalanceResponse.java │ │ │ ├── Batchcancel.java │ │ │ ├── BatchcancelBean.java │ │ │ ├── BatchcancelResponse.java │ │ │ ├── Currencys.java │ │ │ ├── CurrencysResponse.java │ │ │ ├── Depth.java │ │ │ ├── DepthResponse.java │ │ │ ├── DetailResponse.java │ │ │ ├── Details.java │ │ │ ├── HistoryTrade.java │ │ │ ├── HistoryTradeResponse.java │ │ │ ├── HistoryTradess.java │ │ │ ├── IntrustDetail.java │ │ │ ├── IntrustDetailResponse.java │ │ │ ├── Kline.java │ │ │ ├── KlineResponse.java │ │ │ ├── MatchresultsOrdersDetail.java │ │ │ ├── MatchresultsOrdersDetailResponse.java │ │ │ ├── Merged.java │ │ │ ├── MergedResponse.java │ │ │ ├── OrdersDetail.java │ │ │ ├── OrdersDetailResponse.java │ │ │ ├── Place.java │ │ │ ├── SubmitcancelResponse.java │ │ │ ├── Symbol.java │ │ │ ├── Symbols.java │ │ │ ├── SymbolsResponse.java │ │ │ ├── TimestampResponse.java │ │ │ ├── Trade.java │ │ │ ├── TradeBean.java │ │ │ └── TradeResponse.java │ │ ├── to │ │ │ ├── BuyAndSellIndicatorTo.java │ │ │ ├── IndicatorBean.java │ │ │ ├── RobotRunMessage.java │ │ │ ├── RuleBean.java │ │ │ └── llIndicatorTo.java │ │ └── vo │ │ │ ├── Account.java │ │ │ ├── AccountVo.java │ │ │ ├── BaseInfoEntity.java │ │ │ ├── IndicatorCalParam.java │ │ │ ├── IndicatorStrategyVo.java │ │ │ ├── Market.java │ │ │ ├── OrderTaskMessage.java │ │ │ ├── ProfitMessage.java │ │ │ ├── RobotStrategyVo.java │ │ │ ├── RobotVo.java │ │ │ └── StrategyVo.java │ │ ├── enums │ │ ├── AType.java │ │ ├── HBOrderType.java │ │ ├── OrderType.java │ │ ├── PirceType.java │ │ ├── RobotState.java │ │ ├── SellType.java │ │ ├── Status.java │ │ ├── StrategyType.java │ │ └── TraceType.java │ │ ├── exception │ │ ├── ApiException.java │ │ ├── ExchangeNetworkException.java │ │ ├── IndicatorException.java │ │ └── TradingApiException.java │ │ └── utils │ │ ├── ComputeUtil.java │ │ ├── DateUtils.java │ │ ├── JsonFormate.java │ │ └── SpringUtils.java │ └── resources │ └── libs │ └── opslabJutil-2.0.3.jar ├── qt-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── quant │ │ └── core │ │ ├── Main.java │ │ ├── api │ │ ├── ApiClient.java │ │ └── ApiResult.java │ │ ├── builder │ │ └── StrategyBuilder.java │ │ ├── config │ │ ├── AccountConfig.java │ │ ├── KlineConfig.java │ │ ├── MarketConfig.java │ │ ├── StrategyConfig.java │ │ └── imp │ │ │ ├── HuoBiAccountConfigImpl.java │ │ │ ├── HuoBiKlineConfigImpl.java │ │ │ ├── HuoBiMarketConfigImpl.java │ │ │ ├── HuoboIndicatorStragegyConfig.java │ │ │ └── HuoboSimpleStragegyConfig.java │ │ ├── exchangeAdapter │ │ ├── BaseExchangeAdapter.java │ │ └── HuobiExchangeAdapter.java │ │ ├── factory │ │ ├── AbsIndicatorFactory.java │ │ └── IndicatorFactory.java │ │ ├── helpers │ │ └── IndicatorHelper.java │ │ ├── indicatorAdapter │ │ ├── ADXIndicatorAdapter.java │ │ ├── AoIndicatorAdapter.java │ │ ├── CciIndicatorAdapter.java │ │ ├── EmaIndicatorAdapter.java │ │ ├── IndicatorAdapter.java │ │ ├── MacdIndicatorAdapter.java │ │ ├── RsiIndicatorAdapter.java │ │ ├── SmaIndicatorAdapter.java │ │ ├── StochasticDIndicatorAdapter.java │ │ ├── StochasticKiIndicatorAdapter.java │ │ └── StochasticRsiiIndicatorAdapter.java │ │ ├── redisMq │ │ ├── OrderIdRedisMqServiceImpl.java │ │ ├── OrderProfitRedisMqServiceImpl.java │ │ ├── RedisMqService.java │ │ └── RobotLogsRedisMqServiceImpl.java │ │ ├── strategy │ │ ├── AbstractStrategy.java │ │ ├── StrategyException.java │ │ ├── TradingStrategy.java │ │ ├── handle │ │ │ ├── HuobiLimitBuyPriceHandle.java │ │ │ ├── HuobiLimitSellPriceHandle.java │ │ │ ├── HuobiNotLimitBuyPriceHandle.java │ │ │ ├── HuobiNotLimitSellPriceHandle.java │ │ │ └── StrategyHandle.java │ │ └── impl │ │ │ ├── HuoBIndicatoryStrategyImpl.java │ │ │ ├── HuoBiSimpleStrategyImpl.java │ │ │ └── StrategyDelegate.java │ │ └── trading │ │ ├── BalanceInfo.java │ │ ├── OpenOrder.java │ │ ├── TradingApi.java │ │ └── impl │ │ └── HuoBiOpenOrderImpl.java │ └── test │ └── java │ ├── StrategyTest.java │ └── TradingBotOnMovingTimeSeries.java └── qt-register ├── pom.xml └── src └── main ├── java └── com │ └── quant │ └── center │ ├── AppRegister.java │ └── te.java └── resources ├── application-dev.yml ├── application-prod.yml ├── application.yml ├── banner.txt └── logback-spring.xml /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |

quant4j

3 |

诚接区块链应用开发,有团队,联系:13693094831

4 |

Quantitative trading platform.

5 |
6 | ta4j包的目录 [0.13-SNAPSHOT.zip](https://github.com/yangyangchu1992/quant4j/files/5718998/0.13-SNAPSHOT.zip) 7 | 查看附件 8 | 9 | 10 | ## 功能 11 | 主要用于创建和管理自己的机器人,后台动态查看运行状态和收益信息。 12 | # 一: 简单策略 基于配置条件达到自己的条件计算总体权重触发买入卖出 13 | # 二: 指标策略 组装指标(RSI MACD ......等等 可以自由组合) 基于指标的值 触发买入卖出 14 | ``` 15 | - 买入 / 卖出 16 | 17 | - 策略中心 18 | - 简单策略 19 | - 指标策略 20 | - 策略列表 21 | 22 | - 指标策略 23 | - 策略自定义添加 24 | - 策略回测(不完善) 25 | - 新增策略组 26 | - 修改策略组 27 | 28 | - 简单策略 29 | - 各因子组合 30 | - 修改组合 31 | 32 | - 托管中心 33 | - 添加机器人 34 | - 修改机器人 35 | - 查看机器人信息 36 | - 查看机器人下的订单信息 37 | - 查看机器人的盈利信息 38 | 39 | - 配置中心 40 | - 火币api设置 41 | - 邮件提醒设置 下单后将推送邮件 42 | 43 | 44 | ``` 45 | 46 | ## 开发 47 | 48 | ```bash 49 | #后端 50 | springboot 51 | 52 | - [sql脚本](https://github.com/tokenIsme/images/blob/master/quant.sql) 53 | - [前端ui](https://github.com/tokenIsme/quant-admin) 54 | 55 | # 进入前端项目目录 56 | cd quant-admin 57 | 58 | # 安装依赖 59 | npm install 60 | 61 | # 建议不要直接使用 cnpm 安装依赖,会有各种诡异的 bug。可以通过如下操作解决 npm 下载速度慢的问题 62 | npm install --registry=https://registry.npm.taobao.org 63 | 64 | # 启动服务 65 | npm run dev 66 | 浏览器访问 http://localhost:9527 67 | 68 | 69 | #后端 70 | - 后台由一个admin 控制中心 client 机器人运行节点 和一个注册中心管理 节点信息组成 71 | - 启动机器人由admin分发信息给相应的机器人节点,redis作为消息中间件,在client和admin之间传递信息。 72 | - 项目由springboot构建 运行admin,client,register三个项目 动态扩展的是client节点。 73 | - 进入admin模块配置好配置文件,run AdminApplication 74 | - 进入client模块配置好配置文件,这里主要配置的是redis和节点的外网ip和端口,以便让admin获取到节点的信息。 执行run ClientApplication 75 | - 进入register模块配置好配置文件,run RegisterApplication 76 | ``` 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /qt-admin/src/main/docker/DockerFile: -------------------------------------------------------------------------------- 1 | FROM -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/AppAdmin.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.context.annotation.ComponentScan; 7 | import org.springframework.scheduling.annotation.EnableScheduling; 8 | 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | @EnableScheduling 13 | @ComponentScan({"com.quant.common", "com.quant.admin"}) 14 | public class AppAdmin { 15 | public static void main(String[] args) { 16 | SpringApplication.run(AppAdmin.class, args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/component/ProfitReceiver.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.component; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 5 | import com.baomidou.mybatisplus.mapper.Wrapper; 6 | import com.quant.common.domain.entity.OrderProfit; 7 | import com.quant.common.domain.vo.ProfitMessage; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import static com.quant.common.utils.JsonFormate.parseJsonToString; 11 | 12 | /*** 13 | * 消息接收者(订阅者) 需要注入到springboot中 @Value(value = "${landen.ip}") 14 | * private String ip; 15 | * @Value(value = "${landen.port}") 16 | * private int port; 17 | */ 18 | @Slf4j 19 | public class ProfitReceiver { 20 | /** 21 | * 收到通道的消息之后执行的方法 22 | * 23 | * @param message 24 | */ 25 | public void receiveMessage(String message) { 26 | ProfitMessage msg = JSON.parseObject(parseJsonToString(message), ProfitMessage.class); 27 | OrderProfit isExist = new OrderProfit(); 28 | Wrapper wrapper = new EntityWrapper<>(); 29 | wrapper.eq("sell_order_id", msg.getSellOrderId()); 30 | wrapper.eq("buy_order_id", msg.getBuyOrderId()); 31 | OrderProfit one = isExist.selectOne(wrapper); 32 | log.info("sell_order_id》{},buy_order_id {}, one{}", msg.getSellOrderId(), msg.getBuyOrderId(), one); 33 | if (one == null) { 34 | log.info("插入盈利信息,购买订单id{},卖出订单id{}", msg.getBuyOrderId(), msg.getSellOrderId()); 35 | OrderProfit orderProfit = new OrderProfit(); 36 | orderProfit.setSellOrderId(msg.getSellOrderId()); 37 | orderProfit.setBuyOrderId(msg.getBuyOrderId()); 38 | orderProfit.setRobotId(msg.getRobot_id()); 39 | orderProfit.setBuyAmount(msg.getBuyAmount()); 40 | orderProfit.setBuyPrice(msg.getBuyPrice()); 41 | orderProfit.setSellAmount(msg.getSellAmount()); 42 | orderProfit.setSellPrice(msg.getSellPrice()); 43 | orderProfit.setBuyCashAmount(msg.getBuyCashAmount()); 44 | orderProfit.setSellCashAmount(msg.getSellCashAmount()); 45 | orderProfit.setDiff(msg.getDiff()); 46 | orderProfit.setDivide(msg.getDivide()); 47 | if (orderProfit.insert()) { 48 | log.info("插入盈利数据成功!!!"); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/component/RobotMsgReceiver.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.component; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.quant.common.domain.to.RobotRunMessage; 5 | import com.quant.common.utils.JsonFormate; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.messaging.simp.SimpMessagingTemplate; 8 | 9 | /*** 10 | * 消息接收者(订阅者) 需要注入到springboot中 11 | */ 12 | @Slf4j 13 | public class RobotMsgReceiver { 14 | 15 | private SimpMessagingTemplate simpMessageSendingOperations;//消息发送模板 16 | 17 | public RobotMsgReceiver(SimpMessagingTemplate simpMessageSendingOperations) { 18 | this.simpMessageSendingOperations = simpMessageSendingOperations; 19 | } 20 | 21 | /** 22 | * 收到通道的消息之后执行的方法 23 | * 24 | * @param message 25 | */ 26 | public void receiveMessage(String message) { 27 | try { 28 | //这里是收到通道的消息之后执行的方法?? 29 | RobotRunMessage msg = JSON.parseObject(JsonFormate.parseJsonToString(message), RobotRunMessage.class); 30 | simpMessageSendingOperations.convertAndSend("/topic/" + msg.getRobotId(), JsonFormate.parseJsonToString(message)); 31 | } catch (NumberFormatException e) { 32 | e.printStackTrace(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/config/AsyncConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 7 | 8 | import java.util.concurrent.Executor; 9 | 10 | @Configuration 11 | @EnableAsync 12 | public class AsyncConfig { 13 | 14 | private final static int corePoolSize = 2; 15 | private final static int maxPoolSize = 4; 16 | private final static int queueCapacity = 6; 17 | 18 | @Bean 19 | public Executor taskExecutor() { 20 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 21 | executor.setCorePoolSize(corePoolSize); 22 | executor.setMaxPoolSize(maxPoolSize); 23 | executor.setQueueCapacity(queueCapacity); 24 | executor.initialize(); 25 | return executor; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/config/GlobalCorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 7 | 8 | @Configuration 9 | public class GlobalCorsConfig { 10 | 11 | 12 | @Bean 13 | public WebMvcConfigurer addCorsMappings() { 14 | 15 | return new WebMvcConfigurer() { 16 | @Override 17 | public void addCorsMappings(CorsRegistry registry) { 18 | 19 | registry.addMapping("/**") 20 | .allowCredentials(true) 21 | .allowedHeaders("*") 22 | .allowedOrigins("*") 23 | .allowedMethods("*"); 24 | } 25 | }; 26 | 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.config; 2 | 3 | import com.baomidou.mybatisplus.plugins.PaginationInterceptor; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | //Spring boot方式 10 | @EnableTransactionManagement 11 | @Configuration 12 | @MapperScan("com.quant.admin.dao") 13 | public class MybatisPlusConfig { 14 | 15 | /** 16 | * 分页插件 17 | */ 18 | @Bean 19 | public PaginationInterceptor paginationInterceptor() { 20 | return new PaginationInterceptor(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 6 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 7 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 8 | 9 | 10 | @Configuration 11 | @EnableWebSocketMessageBroker 12 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 13 | @Override 14 | public void registerStompEndpoints(StompEndpointRegistry registry) { 15 | //注册一个Stomp 协议的endpoint指定URL为myWebSocket,并用.withSockJS()指定 SockJS协议。.setAllowedOrigins("*")设置跨域 16 | registry.addEndpoint("/robotLog").setAllowedOrigins("*").withSockJS(); 17 | } 18 | 19 | @Override 20 | public void configureMessageBroker(MessageBrokerRegistry config) { 21 | //配置消息代理(message broker) 22 | //将消息传回给以‘/topic’开头的客户端 23 | config.enableSimpleBroker("/topic"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | 4 | import com.quant.admin.service.AccountService; 5 | import com.quant.common.domain.vo.AccountVo; 6 | import com.quant.core.api.ApiResult; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | 15 | /** 16 | *

17 | * 前端控制器 18 | *

19 | * 20 | * @author yang 21 | * @since 2019-04-08 22 | */ 23 | @RestController 24 | @RequestMapping("/account") 25 | public class AccountController extends BaseController { 26 | 27 | @Autowired 28 | AccountService accountService; 29 | 30 | @GetMapping("/accountsByUid") 31 | public ApiResult getAccountsByUid(int uid, int page, int limit) { 32 | return accountService.selectListByUid(uid, page, limit); 33 | } 34 | 35 | @GetMapping("/accounts") 36 | public ApiResult getAccountsByUid(int uid) { 37 | return accountService.accounts(uid); 38 | } 39 | 40 | /** 41 | * 添加或者更新一个账户 42 | * 43 | * @return 44 | */ 45 | @PostMapping("/addOrUpdate") 46 | public ApiResult addAccount(@RequestBody AccountVo account) { 47 | return accountService.addOrUpdate(account); 48 | } 49 | 50 | 51 | @Override 52 | protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { 53 | return null; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/BalanceController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | import com.quant.admin.service.BalanceService; 4 | import com.quant.core.api.ApiResult; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | /** 15 | *

16 | * 前端控制器 17 | *

18 | * 19 | * @author yang 20 | * @since 2019-04-15 21 | */ 22 | @RestController 23 | @RequestMapping("/balance") 24 | public class BalanceController extends BaseController { 25 | 26 | @Autowired 27 | BalanceService balanceService; 28 | 29 | 30 | @GetMapping("/getBalanceList") 31 | public ApiResult getBalanceList(String accountId) { 32 | return balanceService.getBalanceListByAccountId(accountId); 33 | } 34 | 35 | 36 | @Override 37 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 38 | return null; 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | import org.springframework.web.servlet.ModelAndView; 4 | import org.springframework.web.servlet.mvc.AbstractController; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | public class BaseController extends AbstractController { 10 | 11 | 12 | public String getUid(HttpServletRequest httpRequest) { 13 | return httpRequest.getHeader("X-Token"); 14 | } 15 | 16 | @Override 17 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 18 | return null; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/NodeController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.netflix.appinfo.InstanceInfo; 5 | import com.netflix.discovery.EurekaClient; 6 | import com.netflix.discovery.shared.Application; 7 | import com.netflix.discovery.shared.Applications; 8 | import com.quant.common.enums.Status; 9 | import com.quant.core.api.ApiResult; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Qualifier; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.RequestMapping; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.concurrent.CopyOnWriteArrayList; 19 | 20 | @RestController 21 | @RequestMapping("/node") 22 | public class NodeController extends BaseController { 23 | private static final String clientStr = "qt-client"; 24 | @Qualifier("eurekaClient") 25 | @Autowired 26 | EurekaClient eurekaClient; 27 | 28 | @GetMapping("/nodes") 29 | public ApiResult nodes() { 30 | 31 | Applications applications = eurekaClient.getApplications(); 32 | List apps = applications.getRegisteredApplications(); 33 | List list = new ArrayList<>(); 34 | int i = 0; 35 | for (Application application : apps) { 36 | if (application.getName().toLowerCase().equals(clientStr)) { 37 | try { 38 | List instanceInfos = new CopyOnWriteArrayList<>(application.getInstances()); 39 | for (InstanceInfo instanceInfo : instanceInfos) { 40 | JSONObject obj = new JSONObject(); 41 | obj.put("ipo", instanceInfo.getIPAddr() + ":" + instanceInfo.getPort()); 42 | obj.put("id", i); 43 | list.add(obj); 44 | i++; 45 | } 46 | } catch (Exception ex) { 47 | ex.printStackTrace(); 48 | return new ApiResult(Status.ERROR); 49 | } 50 | } 51 | 52 | } 53 | return new ApiResult(Status.SUCCESS, list); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | 4 | import com.quant.admin.service.OrdersService; 5 | import com.quant.core.api.ApiResult; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.servlet.ModelAndView; 11 | import org.springframework.web.servlet.mvc.AbstractController; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | *

18 | * 前端控制器 19 | *

20 | * 21 | * @author yang 22 | * @since 2019-04-22 23 | */ 24 | @RestController 25 | @RequestMapping("/order") 26 | public class OrderController extends AbstractController { 27 | 28 | @Autowired 29 | private OrdersService ordersService; 30 | 31 | /** 32 | * 订单列表 33 | * 34 | * @return 35 | */ 36 | @GetMapping("/list") 37 | public ApiResult list(int rid, int page, int limit) { 38 | return ordersService.getOrderByRobotId(rid,page,limit); 39 | } 40 | 41 | @Override 42 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 43 | return null; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/OrderProfitController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | 4 | import com.quant.admin.service.OrderProfitService; 5 | import com.quant.core.api.ApiResult; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | import org.springframework.web.servlet.ModelAndView; 11 | import org.springframework.web.servlet.mvc.AbstractController; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | *

18 | * 前端控制器 19 | *

20 | * 21 | * @author yang 22 | * @since 2019-04-26 23 | */ 24 | @RestController 25 | @RequestMapping("/orderProfit") 26 | public class OrderProfitController extends AbstractController { 27 | 28 | @Autowired 29 | OrderProfitService orderProfitService; 30 | /** 31 | * 订单列表 32 | * 33 | * @return 34 | */ 35 | @GetMapping("/list") 36 | public ApiResult list(int rid, int page, int limit) { 37 | return orderProfitService.getProfitList(rid,page,limit); 38 | } 39 | 40 | 41 | @Override 42 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 43 | return null; 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/RobotController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | 4 | import com.quant.admin.service.RobotService; 5 | import com.quant.core.api.ApiResult; 6 | import com.quant.common.domain.vo.RobotVo; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | import org.springframework.web.servlet.ModelAndView; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | import javax.validation.constraints.NotBlank; 14 | import javax.validation.constraints.NotNull; 15 | 16 | /** 17 | *

18 | * 前端控制器 19 | *

20 | * 21 | * @author yang 22 | * @since 2019-04-17 23 | */ 24 | @RestController 25 | @RequestMapping("/robot") 26 | public class RobotController extends BaseController { 27 | @Autowired 28 | RobotService robotService; 29 | 30 | @PostMapping("/addOrUpdateRobot") 31 | public ApiResult addOrUpdateRobot(@RequestBody RobotVo vo, HttpServletRequest request) { 32 | @NotBlank 33 | String uid = getUid(request); 34 | vo.setUserId(uid); 35 | return robotService.addOrUpdateRobot(vo); 36 | } 37 | 38 | 39 | @GetMapping("/getRobotById") 40 | public ApiResult getRobotById(int id) { 41 | return robotService.getRobotById(id); 42 | } 43 | 44 | /** 45 | * 获取我的机器人 46 | * 47 | * @return 48 | */ 49 | @GetMapping("/list") 50 | public ApiResult list(HttpServletRequest request) { 51 | @NotBlank 52 | String uid = getUid(request); 53 | return robotService.list(uid); 54 | } 55 | 56 | /** 57 | * 删除我的机器人 58 | * 59 | * @return 60 | */ 61 | @GetMapping("/deleteRobot") 62 | public ApiResult deleteRobot(HttpServletRequest request, int id) { 63 | @NotBlank 64 | String uid = getUid(request); 65 | return robotService.deleteRobot(uid, id); 66 | } 67 | 68 | 69 | /** 70 | * 启动或者关闭机器人 71 | * 72 | * @param id 机器人编号 73 | * @return 74 | */ 75 | @GetMapping("/operatingRobot") 76 | public ApiResult operatingRobot(@NotNull Integer id, @NotBlank Integer state, HttpServletRequest request) { 77 | @NotBlank 78 | String uid = getUid(request); 79 | return robotService.operatingRobot(id, state, uid); 80 | } 81 | 82 | @Override 83 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 84 | return null; 85 | } 86 | } 87 | 88 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/SymbolController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | import com.quant.admin.service.SymbolService; 4 | import com.quant.core.api.ApiResult; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RequestMapping("symbol") 11 | @RestController 12 | public class SymbolController extends BaseController { 13 | 14 | @Autowired 15 | SymbolService symbolService; 16 | 17 | 18 | @GetMapping("/symbols") 19 | public ApiResult getSymbols() { 20 | return symbolService.getSymbols(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.controller; 2 | 3 | 4 | import com.quant.common.domain.entity.User; 5 | import com.quant.admin.service.UserService; 6 | import com.quant.core.api.ApiResult; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.*; 11 | import org.springframework.web.servlet.ModelAndView; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | import javax.validation.constraints.NotNull; 16 | 17 | /** 18 | *

19 | * 前端控制器 20 | *

21 | * 22 | * @author yang 23 | * @since 2019-04-08 24 | */ 25 | @RestController 26 | @RequestMapping("/user") 27 | public class UserController extends BaseController { 28 | 29 | private static Logger logger = LoggerFactory.getLogger(UserController.class); 30 | 31 | 32 | @Autowired 33 | UserService userService; 34 | 35 | /** 36 | * 登录 37 | * 38 | * @param user 39 | * @return 40 | */ 41 | @PostMapping(value = "/login") 42 | public ApiResult login(@RequestBody User user) { 43 | return userService.login(user); 44 | } 45 | 46 | /** 47 | * 退出登录 48 | * 49 | * @return 50 | */ 51 | @PostMapping(value = "/logout") 52 | public ApiResult logout() { 53 | return userService.logout(); 54 | } 55 | 56 | 57 | 58 | 59 | @GetMapping(value = "/info") 60 | public ApiResult info(@NotNull String token) { 61 | return userService.info(token); 62 | } 63 | 64 | @GetMapping(value = "/getUserEmail") 65 | public ApiResult getUserEmail(@NotNull Integer id) { 66 | return userService.getUserEmail(id); 67 | } 68 | 69 | 70 | @PostMapping(value = "/emailEditer") 71 | public ApiResult emailEditer(@NotNull @RequestBody User user) { 72 | return userService.emailEditer(user); 73 | } 74 | 75 | 76 | 77 | @Override 78 | protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { 79 | logger.info("method====" + httpServletRequest.getMethod()); 80 | return null; 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/AccountMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.quant.common.domain.entity.Account; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-08 13 | */ 14 | public interface AccountMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/BalanceMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.entity.Balance; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-15 13 | */ 14 | public interface BalanceMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/OrderProfitMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.entity.OrderProfit; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-26 13 | */ 14 | public interface OrderProfitMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/OrdersMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.entity.Orders; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-22 13 | */ 14 | public interface OrdersMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/RobotMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.bo.RobotBo; 5 | import com.quant.common.domain.entity.Robot; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * Mapper 接口 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-17 16 | */ 17 | public interface RobotMapper extends BaseMapper { 18 | List getRobotList(String uid); 19 | } 20 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/StrategyMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.entity.Strategy; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-15 13 | */ 14 | public interface StrategyMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/SymbolMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.quant.common.domain.entity.Symbol; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-17 13 | */ 14 | public interface SymbolMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.dao; 2 | 3 | import com.quant.common.domain.entity.User; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-08 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/rest/RobotClientService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.rest; 2 | 3 | import com.quant.common.domain.vo.IndicatorStrategyVo; 4 | import com.quant.core.api.ApiResult; 5 | import com.quant.common.domain.vo.RobotStrategyVo; 6 | 7 | public interface RobotClientService { 8 | 9 | ApiResult operatingRobot(String url, RobotStrategyVo vo); 10 | 11 | ApiResult operatingIndicatorRobot(String url, IndicatorStrategyVo strategyVo); 12 | } 13 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/rest/impl/RobotClientServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.rest.impl; 2 | 3 | import com.quant.admin.rest.RobotClientService; 4 | import com.quant.common.domain.vo.IndicatorStrategyVo; 5 | import com.quant.core.api.ApiResult; 6 | import com.quant.common.domain.vo.RobotStrategyVo; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | /** 12 | * 调用机器人节点服务器 传递数据给机器人 13 | */ 14 | @Service 15 | public class RobotClientServiceImpl implements RobotClientService { 16 | 17 | @Autowired 18 | RestTemplate restTemplate; 19 | 20 | /** 21 | * 发送信息到client端 22 | * 23 | * @param url 24 | * @param vo 25 | * @return 26 | */ 27 | @Override 28 | public ApiResult operatingRobot(String url, RobotStrategyVo vo) { 29 | return restTemplate.postForEntity(url, vo, ApiResult.class).getBody(); 30 | } 31 | 32 | @Override 33 | public ApiResult operatingIndicatorRobot(String url, IndicatorStrategyVo strategyVo) { 34 | return restTemplate.postForEntity(url, strategyVo, ApiResult.class).getBody(); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.quant.common.domain.entity.Account; 4 | import com.baomidou.mybatisplus.service.IService; 5 | import com.quant.common.domain.vo.AccountVo; 6 | import com.quant.core.api.ApiResult; 7 | 8 | /** 9 | *

10 | * 服务类 11 | *

12 | * 13 | * @author yang 14 | * @since 2019-04-08 15 | */ 16 | public interface AccountService extends IService { 17 | 18 | /** 19 | * 添加一个账户 20 | * 21 | * @param account 22 | */ 23 | ApiResult addOrUpdate(AccountVo account); 24 | 25 | ApiResult selectListByUid(int uid, int page, int limit); 26 | 27 | ApiResult accounts(int uid); 28 | } 29 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/BalanceService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.Balance; 5 | import com.quant.core.api.ApiResult; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author yang 13 | * @since 2019-04-15 14 | */ 15 | public interface BalanceService extends IService { 16 | 17 | ApiResult getBalanceListByAccountId(String accountId); 18 | } 19 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/IMailService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import javax.mail.MessagingException; 4 | 5 | public interface IMailService { 6 | /** 7 | * 发送文本邮件 8 | * 9 | * @param to 10 | * @param subject 11 | * @param content 12 | */ 13 | void sendSimpleMail(String to, String subject, String content); 14 | 15 | 16 | /** 17 | * 发送HTML邮件 18 | * 19 | * @param to 20 | * @param subject 21 | * @param content 22 | * @throws MessagingException 23 | */ 24 | void sendHtmlMail(String to, String subject, String content) throws MessagingException; 25 | 26 | /** 27 | * 发送带附件的邮件 28 | * 29 | * @param to 30 | * @param subject 31 | * @param content 32 | * @param filePath 33 | * @throws MessagingException 34 | */ 35 | void sendAttachmentsMail(String to, String subject, String content, String filePath) throws MessagingException; 36 | 37 | /** 38 | * 发送正文中有静态资源的邮件 39 | * 40 | * @param to 41 | * @param subject 42 | * @param content 43 | * @param rscPath 44 | * @param rscId 45 | * @throws MessagingException 46 | */ 47 | void sendResourceMail(String to, String subject, String content, String rscPath, String rscId) throws MessagingException; 48 | 49 | 50 | } -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/OrderProfitService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.OrderProfit; 5 | import com.quant.core.api.ApiResult; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author yang 13 | * @since 2019-04-26 14 | */ 15 | public interface OrderProfitService extends IService { 16 | 17 | ApiResult getProfitList(int rid, int page, int limit); 18 | } 19 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/OrdersService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.Orders; 5 | import com.quant.core.api.ApiResult; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author yang 13 | * @since 2019-04-22 14 | */ 15 | public interface OrdersService extends IService { 16 | 17 | ApiResult getOrderByRobotId(int robotId, int page, int limit); 18 | } 19 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/RobotService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.Robot; 5 | import com.quant.core.api.ApiResult; 6 | import com.quant.common.domain.vo.RobotVo; 7 | 8 | import javax.validation.constraints.NotBlank; 9 | 10 | /** 11 | *

12 | * 服务类 13 | *

14 | * 15 | * @author yang 16 | * @since 2019-04-17 17 | */ 18 | public interface RobotService extends IService { 19 | 20 | ApiResult addOrUpdateRobot(RobotVo vo); 21 | 22 | ApiResult list(String uid); 23 | 24 | ApiResult operatingRobot(Integer id,Integer state, String uid); 25 | 26 | ApiResult deleteRobot(String uid,int id); 27 | 28 | boolean editRobotRunState(int runState); 29 | 30 | ApiResult getRobotById(@NotBlank int uid); 31 | } 32 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/StrategyService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.baomidou.mybatisplus.service.IService; 5 | import com.quant.common.domain.entity.Strategy; 6 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 7 | import com.quant.common.domain.to.llIndicatorTo; 8 | import com.quant.core.api.ApiResult; 9 | import com.quant.common.domain.vo.StrategyVo; 10 | 11 | /** 12 | *

13 | * 服务类 14 | *

15 | * 16 | * @author yang 17 | * @since 2019-04-15 18 | */ 19 | public interface StrategyService extends IService { 20 | 21 | ApiResult addOrUpdateStrategy(StrategyVo strategyVo, String uid); 22 | 23 | ApiResult strategyList(String uid); 24 | 25 | ApiResult simpleStrategyList(String uid); 26 | 27 | ApiResult getStrategyById(int id, String uid); 28 | 29 | ApiResult deleteStrategy(int id, String uid); 30 | 31 | ApiResult addOrUpdateIndicatorStrategy(llIndicatorTo strategyVo, String uid); 32 | } 33 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/SymbolService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.Symbol; 5 | import com.quant.core.api.ApiResult; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author yang 13 | * @since 2019-04-17 14 | */ 15 | public interface SymbolService extends IService { 16 | 17 | ApiResult getSymbols(); 18 | } 19 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.quant.common.domain.entity.User; 5 | import com.quant.core.api.ApiResult; 6 | 7 | import javax.validation.constraints.NotNull; 8 | 9 | /** 10 | *

11 | * 服务类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-08 16 | */ 17 | public interface UserService extends IService { 18 | 19 | /** 20 | * simple登录 21 | * @param params 22 | * @return 23 | */ 24 | ApiResult login(User params); 25 | 26 | 27 | ApiResult info(String token); 28 | 29 | ApiResult logout(); 30 | 31 | ApiResult getUserEmail(@NotNull Integer id); 32 | 33 | ApiResult emailEditer(@NotNull User user); 34 | } 35 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/impl/BalanceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 4 | import com.baomidou.mybatisplus.mapper.Wrapper; 5 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 6 | import com.quant.admin.dao.BalanceMapper; 7 | import com.quant.common.domain.entity.Balance; 8 | import com.quant.admin.service.BalanceService; 9 | import com.quant.common.enums.Status; 10 | import com.quant.core.api.ApiResult; 11 | import org.springframework.stereotype.Service; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | /** 17 | *

18 | * 服务实现类 19 | *

20 | * 21 | * @author yang 22 | * @since 2019-04-15 23 | */ 24 | @Service 25 | public class BalanceServiceImpl extends ServiceImpl implements BalanceService { 26 | 27 | @Override 28 | public ApiResult getBalanceListByAccountId(String accountId) { 29 | try { 30 | Wrapper balanceWrapper = new EntityWrapper<>(); 31 | balanceWrapper.eq("account_id", accountId); 32 | balanceWrapper.orderDesc(Collections.singleton("trade_balance")); 33 | Balance balance = new Balance(); 34 | List balances = balance.selectList(balanceWrapper); 35 | return new ApiResult(Status.SUCCESS, balances); 36 | } catch (Exception e) { 37 | return new ApiResult(Status.ERROR); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/impl/OrderProfitServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 4 | import com.baomidou.mybatisplus.mapper.Wrapper; 5 | import com.baomidou.mybatisplus.plugins.Page; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import com.quant.admin.dao.OrderProfitMapper; 8 | import com.quant.common.domain.entity.OrderProfit; 9 | import com.quant.admin.service.OrderProfitService; 10 | import com.quant.core.api.ApiResult; 11 | import com.quant.common.enums.Status; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.Collections; 16 | 17 | /** 18 | *

19 | * 服务实现类 20 | *

21 | * 22 | * @author yang 23 | * @since 2019-04-26 24 | */ 25 | @Slf4j 26 | @Service 27 | public class OrderProfitServiceImpl extends ServiceImpl implements OrderProfitService { 28 | 29 | @Override 30 | public ApiResult getProfitList(int rid, int page, int limit) { 31 | try { 32 | Wrapper orderProfitEntityWrapper = new EntityWrapper<>(); 33 | orderProfitEntityWrapper.eq("robot_id", rid); 34 | orderProfitEntityWrapper.orderDesc(Collections.singleton("create_time")); 35 | OrderProfit orders = new OrderProfit(); 36 | Page ordersPage = orders.selectPage(new Page<>(page, limit), orderProfitEntityWrapper); 37 | return new ApiResult(Status.SUCCESS, ordersPage); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | log.error("查询盈亏订单列表失败 {}", e.getMessage()); 41 | } 42 | return new ApiResult(Status.ERROR); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/impl/OrdersServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 4 | import com.baomidou.mybatisplus.mapper.Wrapper; 5 | import com.baomidou.mybatisplus.plugins.Page; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import com.quant.admin.dao.OrdersMapper; 8 | import com.quant.common.domain.entity.Orders; 9 | import com.quant.admin.service.OrdersService; 10 | import com.quant.core.api.ApiResult; 11 | import com.quant.common.enums.Status; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.Collections; 16 | 17 | /** 18 | *

19 | * 服务实现类 20 | *

21 | * 22 | * @author yang 23 | * @since 2019-04-22 24 | */ 25 | @Slf4j 26 | @Service 27 | public class OrdersServiceImpl extends ServiceImpl implements OrdersService { 28 | 29 | @Override 30 | public ApiResult getOrderByRobotId(int rid, int page, int limit) { 31 | try { 32 | Wrapper ordersWrapper = new EntityWrapper<>(); 33 | ordersWrapper.eq("robot_id", rid); 34 | ordersWrapper.orderDesc(Collections.singleton("order_id")); 35 | Orders orders = new Orders(); 36 | Page ordersPage = orders.selectPage(new Page<>(page, limit), ordersWrapper); 37 | return new ApiResult(Status.SUCCESS, ordersPage); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | log.error("查询机器人订单列表失败 {}", e.getMessage()); 41 | } 42 | return new ApiResult(Status.ERROR); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/impl/SymbolServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 4 | import com.quant.admin.dao.SymbolMapper; 5 | import com.quant.common.domain.entity.Symbol; 6 | import com.quant.admin.service.SymbolService; 7 | import com.quant.common.enums.Status; 8 | import com.quant.core.api.ApiResult; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * 服务实现类 16 | *

17 | * 18 | * @author yang 19 | * @since 2019-04-17 20 | */ 21 | @Service 22 | public class SymbolServiceImpl extends ServiceImpl implements SymbolService { 23 | 24 | @Override 25 | public ApiResult getSymbols() { 26 | Symbol symbol = new Symbol(); 27 | List symbols = symbol.selectAll(); 28 | return new ApiResult(Status.SUCCESS, symbols); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 4 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 5 | import com.quant.admin.dao.UserMapper; 6 | import com.quant.common.domain.entity.User; 7 | import com.quant.admin.service.UserService; 8 | import com.quant.common.enums.Status; 9 | import com.quant.core.api.ApiResult; 10 | import org.springframework.stereotype.Service; 11 | 12 | import javax.validation.constraints.NotNull; 13 | 14 | /** 15 | *

16 | * 服务实现类 17 | *

18 | * 19 | * @author yang 20 | * @since 2019-04-08 21 | */ 22 | @Service 23 | public class UserServiceImpl extends ServiceImpl implements UserService { 24 | 25 | @Override 26 | public ApiResult login(User params) { 27 | EntityWrapper wrapper = new EntityWrapper<>(); 28 | User user = new User(); 29 | wrapper.eq("username", params.getUsername()); 30 | wrapper.eq("password", params.getPassword()); 31 | wrapper.eq("is_delete", 0); 32 | User u = user.selectOne(wrapper); 33 | if (u != null) { 34 | return new ApiResult(Status.SUCCESS, u.getId()); 35 | } else { 36 | return new ApiResult(Status.USER_NOT_EXIST); 37 | } 38 | 39 | } 40 | 41 | @Override 42 | public ApiResult info(String token) { 43 | EntityWrapper wrapper = new EntityWrapper<>(); 44 | User user = new User(); 45 | wrapper.eq("id", token); 46 | wrapper.eq("is_delete", 0); 47 | User u = user.selectOne(wrapper); 48 | if (u != null) { 49 | u.setPassword(null); 50 | return new ApiResult(Status.SUCCESS, u); 51 | } else { 52 | return new ApiResult(Status.USER_NOT_EXIST); 53 | } 54 | 55 | } 56 | 57 | @Override 58 | public ApiResult logout() { 59 | return new ApiResult(Status.SUCCESS); 60 | } 61 | 62 | @Override 63 | public ApiResult getUserEmail(@NotNull Integer id) { 64 | User user = new User(); 65 | User selectById = user.selectById(id); 66 | return new ApiResult(Status.SUCCESS, selectById); 67 | } 68 | 69 | @Override 70 | public ApiResult emailEditer(@NotNull User user) { 71 | 72 | boolean byId = user.updateById(); 73 | if (byId) { 74 | return new ApiResult(Status.SUCCESS); 75 | } 76 | return new ApiResult(Status.ERROR); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/task/RobotStatusTask.java: -------------------------------------------------------------------------------- 1 | //package com.quant.admin.task; 2 | // 3 | //import com.quant.common.domain.entity.Robot; 4 | //import com.quant.common.config.RedisUtil; 5 | //import com.quant.common.constans.RobotRedisKeyConfig; 6 | //import lombok.extern.slf4j.Slf4j; 7 | //import org.springframework.beans.factory.annotation.Autowired; 8 | //import org.springframework.scheduling.annotation.Async; 9 | //import org.springframework.scheduling.annotation.Scheduled; 10 | //import org.springframework.stereotype.Component; 11 | // 12 | //import java.util.List; 13 | // 14 | //@Slf4j 15 | //@Component 16 | //public class RobotStatusTask { 17 | // 18 | // @Autowired 19 | // RedisUtil redisUtil; 20 | // 21 | // /** 22 | // * 更新机器人的运行状态 23 | // */ 24 | // @Async 25 | // @Scheduled(fixedDelay = 5000, initialDelay = 1000) 26 | // public void updateRobotRunState() { 27 | // Robot robot = new Robot(); 28 | // List robots = robot.selectAll(); 29 | // for (Robot r : robots) { 30 | // String key = RobotRedisKeyConfig.getRobotIsRunStateKey() + r.getId(); 31 | // Object o = redisUtil.get(key); 32 | // if (o == null) { 33 | // //已经取消了机器人的运行 34 | // r.setIsRun(0); 35 | // } else { 36 | // r.setIsRun(1); 37 | // } 38 | // try { 39 | // r.updateById(); 40 | // } catch (Exception e) { 41 | // e.printStackTrace(); 42 | // log.error("更新机器人状态失败"); 43 | // } 44 | // } 45 | // 46 | // 47 | // } 48 | //} 49 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/quant/admin/task/SymbolTask.java: -------------------------------------------------------------------------------- 1 | package com.quant.admin.task; 2 | 3 | import com.quant.common.config.RedisUtil; 4 | import com.quant.common.config.VpnProxyConfig; 5 | import com.quant.common.constans.RobotRedisKeyConfig; 6 | import com.quant.core.api.ApiClient; 7 | import com.quant.common.domain.response.Symbol; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.scheduling.annotation.Async; 12 | import org.springframework.scheduling.annotation.Scheduled; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.Comparator; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | 19 | @Component 20 | public class SymbolTask { 21 | 22 | private static Logger logger = LoggerFactory.getLogger(SymbolTask.class); 23 | @Autowired 24 | VpnProxyConfig vpnProxyConfig; 25 | @Autowired 26 | RedisUtil redisUtil; 27 | 28 | /** 29 | * 收集交易对信息存到数据库 /v1/common/symbols 30 | */ 31 | @Async 32 | @Scheduled(fixedDelay = 1000 * 60 * 60 * 24, initialDelay = 5000) 33 | public void symbolCollects() { 34 | logger.info("=========数据 redis 同步交易对信息开始========="); 35 | ApiClient apiClient = new ApiClient(vpnProxyConfig); 36 | List symbols = apiClient.getSymbols(); 37 | //获取到交易对 进行排序操作 防止每次都插入不一致 38 | symbols = symbols.stream().sorted(Comparator.comparing(Symbol::getSymbol)).collect(Collectors.toList()); 39 | int i = 0; 40 | for (Symbol s : symbols) { 41 | ++i; 42 | com.quant.common.domain.entity.Symbol symbol = new com.quant.common.domain.entity.Symbol(); 43 | symbol.setId(i); 44 | symbol.setAmountPrecision(s.getAmountPrecision()); 45 | symbol.setBaseCurrency(s.getBaseCurrency()); 46 | symbol.setPricePrecision(s.getPricePrecision()); 47 | symbol.setQuoteCurrency(s.getQuoteCurrency()); 48 | symbol.setSymbol(s.getSymbol()); 49 | if (symbol.insertOrUpdate()) { 50 | //将交易对的quote保存redis 51 | redisUtil.set(RobotRedisKeyConfig.getSymbol() + symbol.getSymbol(), symbol.getBaseCurrency() + "_" + symbol.getQuoteCurrency() + "_" + symbol.getPricePrecision() + "_" + symbol.getAmountPrecision()); 52 | } 53 | } 54 | 55 | logger.info("=========同步交易对信息完毕========="); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | connection-timeout: 10000 4 | #添加数据源 5 | spring: 6 | datasource: 7 | type: com.alibaba.druid.pool.DruidDataSource 8 | driver-class-name: com.mysql.jdbc.Driver 9 | url: jdbc:mysql://localhost:3306/quant?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 10 | username: root 11 | password: root 12 | druid: 13 | initial-size: 5 14 | min-idle: 10 15 | max-active: 20 16 | max-wait: 60000 17 | min-evictable-idle-time-millis: 6000 18 | time-between-eviction-runs-millis: 3000 19 | validation-query: SELECT 1 FROM DUAL 20 | test-while-idle: true 21 | test-on-borrow: false 22 | test-on-return: false 23 | filters: stat,wall 24 | use-global-data-source-stat: true 25 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 26 | jackson: 27 | date-format: yyyy-MM-dd HH:mm:ss 28 | time-zone: GMT+8 29 | application: 30 | name: qt-admin 31 | redis: 32 | database: 0 33 | host: 127.0.0.1 34 | port: 6379 35 | password: 36 | jedis: 37 | pool: 38 | max-active: 8 39 | max-wait: -1 40 | max-idle: 8 41 | min-idle: 0 42 | timeout: 15000 43 | mail: 44 | host: smtp.qq.com #发送邮件服务器 45 | username: yangge975965279@vip.qq.com #QQ邮箱 请换自己的邮箱谢谢 46 | password: sdncjthvgtwrbfgg #客户端授权码 47 | protocol: smtp #发送邮件协议 48 | properties.mail.smtp.auth: true 49 | properties.mail.smtp.port: 465 #端口号465或587 50 | properties.mail.display.sendmail: quant #可以任意 51 | properties.mail.display.sendname: quant Email #可以任意 52 | properties.mail.smtp.starttls.enable: true 53 | properties.mail.smtp.starttls.required: true 54 | properties.mail.smtp.ssl.enable: true 55 | default-encoding: utf-8 56 | from: yangge975965279@vip.qq.com #与上面的username保持一致 57 | # mapper-locations: classpath:/mapper/* 58 | eureka: 59 | client: 60 | serviceUrl: 61 | defaultZone: http://${EUREKA_ZONE_HOST:localhost}:${EUREKA_ZONE_PORT:8761}/eureka/ 62 | mybatis-plus: 63 | mapper-locations: classpath*:mapper/*Mapper.xml 64 | 65 | vpnproxy: 66 | enable: false 67 | ip: 127.0.0.1 68 | port: 1088 69 | 70 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8180 3 | address: 0.0.0.0 4 | #添加数据源 5 | spring: 6 | datasource: 7 | type: com.alibaba.druid.pool.DruidDataSource 8 | driver-class-name: com.mysql.jdbc.Driver 9 | url: jdbc:mysql://localhost:3306/quant?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 10 | username: root 11 | password: xxxx 12 | druid: 13 | initial-size: 5 14 | min-idle: 10 15 | max-active: 20 16 | max-wait: 60000 17 | min-evictable-idle-time-millis: 6000 18 | time-between-eviction-runs-millis: 3000 19 | validation-query: SELECT 1 FROM DUAL 20 | test-while-idle: true 21 | test-on-borrow: false 22 | test-on-return: false 23 | filters: stat,wall 24 | use-global-data-source-stat: true 25 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 26 | jackson: 27 | date-format: yyyy-MM-dd HH:mm:ss 28 | time-zone: GMT+8 29 | application: 30 | name: qt-admin 31 | redis: 32 | database: 0 33 | host: 127.0.0.1 34 | port: 6379 35 | password: 36 | jedis: 37 | pool: 38 | max-active: 8 39 | max-wait: -1 40 | max-idle: 8 41 | min-idle: 0 42 | timeout: 15000 43 | mail: 44 | host: smtp.qq.com #发送邮件服务器 45 | username: yangge975965279@vip.qq.com #QQ邮箱 请换自己的邮箱谢谢 46 | password: sdncjthvgtwrbfgg #客户端授权码 47 | protocol: smtp #发送邮件协议 48 | properties.mail.smtp.auth: true 49 | properties.mail.smtp.port: 465 #端口号465或587 50 | properties.mail.display.sendmail: quant #可以任意 51 | properties.mail.display.sendname: quant Email #可以任意 52 | properties.mail.smtp.starttls.enable: true 53 | properties.mail.smtp.starttls.required: true 54 | properties.mail.smtp.ssl.enable: true 55 | default-encoding: utf-8 56 | from: yangge975965279@vip.qq.com #与上面的username保持一致 57 | eureka: 58 | client: 59 | serviceUrl: 60 | defaultZone: http://${EUREKA_ZONE_HOST:0.0.0.0}:${EUREKA_ZONE_PORT:8762}/eureka/ 61 | mybatis-plus: 62 | mapper-locations: classpath*:mapper/*Mapper.xml 63 | 64 | vpnproxy: 65 | enable: false 66 | ip: 127.0.0.1 67 | port: 1088 -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ _ _ _ __ 2 | / / | | | | (_) \ \ 3 | / / __ _ _ _ __ _ _ __ | |_ ______ __ _ __| |_ __ ___ _ _ __ \ \ 4 | < < / _` | | | |/ _` | '_ \| __|______/ _` |/ _` | '_ ` _ \| | '_ \ > > 5 | \ | (_| | |_| | (_| | | | | |_ | (_| | (_| | | | | | | | | | |/ / 6 | \_\__, |\__,_|\__,_|_| |_|\__| \__,_|\__,_|_| |_| |_|_|_| |_/_/ 7 | | | 8 | |_| -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/AccountMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | id, user_id AS userId,name as name , access_key AS accessKey, secret_key AS secretKey, type, state, info, create_time AS createTime, is_delete AS isDelete 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/BalanceMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, account_id AS accountId, type, currency, trade_balance AS tradeBalance, frozen_balance AS frozenBalance 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/OrderProfitMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | id, robot_id AS robotId, sell_order_id AS sellOrderId, buy_order_id AS buyOrderId, buy_price AS buyPrice, sell_price AS sellPrice, buy_cash_amount AS buyCashAmount, sell_cash_amount AS sellCashAmount, buy_amount AS buyAmount, sell_amount AS sellAmount, is_profit AS isProfit, diff, divide, create_time AS createTime 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/OrdersMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | id, order_id AS orderId, symbol, robot_id AS robotId, account_id AS accountId, amount, price, order_state AS orderState, order_type AS orderType, create_time AS createTime, finished_time AS finishedTime, field_fees AS fieldFees, field_amount AS fieldAmount, field_cash_amount AS fieldCashAmount 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/RobotMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | id, user_id AS userId, robot_name AS robotName, symbol, strategy_id AS strategyId, client_address AS clientAddress, create_time AS createTime, is_delete AS isDelete,is_run as isRun 22 | 23 | 24 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/StrategyMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | id, user_id AS userId, strategy_name AS strategyName, buy_amount AS buyAmount, buy_quota_price AS buyQuotaPrice, sell_amount AS sellAmount, buy_price AS buyPrice, sell_price AS sellPrice, is_all_buy AS isAllBuy, is_all_sell AS isAllSell, is_limit_price AS isLimitPrice, sell_all_weights AS sellAllWeights, buy_all_weights AS buyAllWeights, profit, sleep, setting1, setting2, setting3, setting4, setting5, setting6 33 | 34 | 35 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/SymbolMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | id, base_currency AS baseCurrency, quote_currency AS quoteCurrency, price_precision AS pricePrecision, amount_precision AS amountPrecision, symbol 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | id, username, password, create_time AS createTime, is_delete AS isDelete, avatar, introduction, roles 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /qt-admin/src/test/java/com/quant/admin/QtParentApplicationTests.java: -------------------------------------------------------------------------------- 1 | //package com.qklx.qt.admin; 2 | // 3 | //import User; 4 | //import RedisUtil; 5 | //import org.junit.Test; 6 | //import org.junit.runner.RunWith; 7 | //import org.springframework.beans.factory.annotation.Autowired; 8 | //import org.springframework.boot.test.context.SpringBootTest; 9 | //import org.springframework.test.context.junit4.SpringRunner; 10 | // 11 | //@RunWith(SpringRunner.class) 12 | //@SpringBootTest 13 | //public class QtParentApplicationTests { 14 | // 15 | // @Autowired 16 | // RedisUtil redisUtil; 17 | // 18 | // 19 | // @Test 20 | // public void test() throws Exception { 21 | // 22 | // redisUtil.sSet("testSet", 1, 2, 3); 23 | // 24 | // boolean testSet1 = redisUtil.sHasKey("testSet", 1); 25 | // boolean testSet2 = redisUtil.sHasKey("testSet", 4); 26 | // System.out.println("testSet1" + testSet1); 27 | // System.out.println("testSet2" + testSet2); 28 | // } 29 | // 30 | // 31 | //} 32 | -------------------------------------------------------------------------------- /qt-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qt-parent 7 | com.quant 8 | 0.0.1-SNAPSHOT 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | qt-client 14 | 15 | 16 | com.quant 17 | qt-core 18 | 0.0.1-SNAPSHOT 19 | compile 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.yaml 28 | snakeyaml 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-redis 33 | 34 | 35 | 36 | redis.clients 37 | jedis 38 | 2.7.3 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-maven-plugin 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/AppClient.java: -------------------------------------------------------------------------------- 1 | package com.quant.client; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | import org.springframework.context.annotation.ComponentScan; 10 | import org.springframework.scheduling.annotation.EnableScheduling; 11 | 12 | @EnableEurekaClient 13 | @EnableScheduling 14 | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class}) 15 | @ComponentScan({"com.quant.common","com.quant.client"}) 16 | public class AppClient { 17 | public static void main(String[] args) { 18 | 19 | SpringApplication.run(AppClient.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/config/ThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.config; 2 | 3 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import java.util.concurrent.*; 8 | 9 | @Configuration 10 | public class ThreadPool { 11 | 12 | @Bean 13 | public ExecutorService initPool() { 14 | ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() 15 | .setNameFormat("-----机器人后台程序-----pool--%d").build(); 16 | return new ThreadPoolExecutor(10, 17 | 20, 18 | 1000L, 19 | TimeUnit.MILLISECONDS, 20 | new LinkedBlockingQueue<>(1000), 21 | namedThreadFactory, 22 | new ThreadPoolExecutor.AbortPolicy()); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/controller/BotController.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.controller; 2 | 3 | import com.quant.client.service.RobotService; 4 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 5 | import com.quant.common.domain.vo.IndicatorStrategyVo; 6 | import com.quant.core.api.ApiResult; 7 | import com.quant.common.domain.vo.RobotStrategyVo; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.PostMapping; 11 | import org.springframework.web.bind.annotation.RequestBody; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RestController; 14 | 15 | @Slf4j 16 | @RestController 17 | @RequestMapping("/robot") 18 | public class BotController { 19 | 20 | @Autowired 21 | RobotService robotService; 22 | 23 | @PostMapping("/operatingRobot") 24 | public ApiResult operatingRobot(@RequestBody RobotStrategyVo vo) { 25 | log.info("获取到机器人的配置信息:{}", vo.toString()); 26 | return robotService.operatingRobot(vo); 27 | } 28 | 29 | @PostMapping("/operatingIndicatorRobot") 30 | public ApiResult operatingIndicatorRobot(@RequestBody IndicatorStrategyVo vo) { 31 | log.info("获取到机器人的配置信息:{}", vo.toString()); 32 | return robotService.operatingIndicatorRobot(vo); 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/service/RobotService.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.service; 2 | 3 | import com.quant.common.domain.vo.IndicatorStrategyVo; 4 | import com.quant.common.domain.vo.RobotStrategyVo; 5 | import com.quant.core.api.ApiResult; 6 | 7 | public interface RobotService { 8 | 9 | 10 | ApiResult operatingRobot(RobotStrategyVo vo); 11 | 12 | ApiResult operatingIndicatorRobot(IndicatorStrategyVo vo); 13 | } 14 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/service/impl/RobotServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.service.impl; 2 | 3 | import com.quant.client.task.IndicatorRobotOperate; 4 | import com.quant.client.task.SimpleNumRobotOperate; 5 | import com.quant.client.service.RobotService; 6 | import com.quant.common.config.RedisUtil; 7 | import com.quant.common.config.VpnProxyConfig; 8 | import com.quant.common.domain.vo.IndicatorStrategyVo; 9 | import com.quant.core.api.ApiResult; 10 | import com.quant.common.enums.Status; 11 | import com.quant.common.domain.vo.RobotStrategyVo; 12 | import lombok.extern.slf4j.Slf4j; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.concurrent.ExecutorService; 17 | 18 | @Slf4j 19 | @Service 20 | public class RobotServiceImpl implements RobotService { 21 | @Autowired 22 | VpnProxyConfig vpnProxyConfig; 23 | @Autowired 24 | RedisUtil redisUtil; 25 | @Autowired 26 | ExecutorService executorService; 27 | 28 | @Override 29 | public ApiResult operatingRobot(RobotStrategyVo vo) { 30 | //启动机器人 31 | try { 32 | executorService.execute(() -> { 33 | SimpleNumRobotOperate robotOperate = new SimpleNumRobotOperate(redisUtil, vpnProxyConfig); 34 | robotOperate.doRobotTask(vo); 35 | }); 36 | return new ApiResult(Status.SUCCESS); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | log.error("client端启动机器人发生错误:机器人编号:{},client端地址:{}", vo.getRobotId(), vo.getAddress()); 40 | log.error("错误信息:" + e.getMessage()); 41 | return new ApiResult(Status.startRobotError); 42 | } 43 | } 44 | 45 | @Override 46 | public ApiResult operatingIndicatorRobot(IndicatorStrategyVo vo) { 47 | //启动机器人 48 | try { 49 | executorService.execute(() -> { 50 | IndicatorRobotOperate robotOperate = new IndicatorRobotOperate(redisUtil, vpnProxyConfig); 51 | robotOperate.doRobotTask(vo); 52 | }); 53 | return new ApiResult(Status.SUCCESS); 54 | } catch (Exception e) { 55 | e.printStackTrace(); 56 | log.error("client端启动机器人发生错误:机器人编号:{},client端地址:{}", vo.getRobotId(), vo.getAddress()); 57 | log.error("错误信息:" + e.getMessage()); 58 | return new ApiResult(Status.startRobotError); 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/task/IndicatorRobotOperate.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.task; 2 | 3 | import com.quant.common.config.RedisUtil; 4 | import com.quant.common.config.VpnProxyConfig; 5 | import com.quant.common.domain.vo.IndicatorStrategyVo; 6 | import com.quant.common.enums.StrategyType; 7 | import com.quant.core.builder.StrategyBuilder; 8 | import com.quant.core.strategy.StrategyException; 9 | import com.quant.core.strategy.TradingStrategy; 10 | import com.quant.core.strategy.impl.HuoBIndicatoryStrategyImpl; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | /** 14 | * IndicatorRobotOperate 指标策略机器人启动 15 | * Created by yang on 2019/5/31. 16 | */ 17 | @Slf4j 18 | public class IndicatorRobotOperate { 19 | private RedisUtil redisUtil; 20 | 21 | 22 | private VpnProxyConfig vpnProxyConfig; 23 | 24 | public IndicatorRobotOperate(RedisUtil redisUtil, VpnProxyConfig vpnProxyConfig) { 25 | this.redisUtil = redisUtil; 26 | this.vpnProxyConfig = vpnProxyConfig; 27 | } 28 | 29 | public void doRobotTask(IndicatorStrategyVo vo) { 30 | log.info("启动机器人{}>>>>>>", vo.getRobotId()); 31 | TradingStrategy strategy = builderStrategy(vo); 32 | try { 33 | strategy.execute(); 34 | } catch (StrategyException e) { 35 | e.printStackTrace(); 36 | } 37 | 38 | } 39 | 40 | private TradingStrategy builderStrategy(IndicatorStrategyVo vo) { 41 | 42 | StrategyType indicator = StrategyType.indicator; 43 | StrategyBuilder builder = new StrategyBuilder().setRedisUtil(redisUtil) 44 | .setStratrgyType(indicator) 45 | .setIndicatorStrategyVo(vo).setVpnProxyConfig(vpnProxyConfig) 46 | .buildApiClient() 47 | .buildTradingApi().buildMarketConfig() 48 | .buildStrategyConfig().buildAccountConfig(); 49 | 50 | TradingStrategy huoBIndicatoryStrategy = new HuoBIndicatoryStrategyImpl(redisUtil, vo.getRobotId()); 51 | 52 | log.info("加载机器人{}>>>>>>", vo.getRobotId()); 53 | huoBIndicatoryStrategy.init(builder); 54 | return huoBIndicatoryStrategy; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/quant/client/task/SimpleNumRobotOperate.java: -------------------------------------------------------------------------------- 1 | package com.quant.client.task; 2 | 3 | import com.quant.common.config.RedisUtil; 4 | import com.quant.common.config.VpnProxyConfig; 5 | import com.quant.common.enums.StrategyType; 6 | import com.quant.core.builder.StrategyBuilder; 7 | import com.quant.core.strategy.StrategyException; 8 | import com.quant.core.strategy.TradingStrategy; 9 | import com.quant.core.strategy.impl.HuoBiSimpleStrategyImpl; 10 | import com.quant.common.domain.vo.RobotStrategyVo; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | @Slf4j 14 | public class SimpleNumRobotOperate { 15 | 16 | private RedisUtil redisUtil; 17 | 18 | 19 | private VpnProxyConfig vpnProxyConfig; 20 | 21 | public SimpleNumRobotOperate(RedisUtil redisUtil, VpnProxyConfig vpnProxyConfig) { 22 | this.redisUtil = redisUtil; 23 | this.vpnProxyConfig = vpnProxyConfig; 24 | } 25 | 26 | public void doRobotTask(RobotStrategyVo vo) { 27 | log.info("启动机器人{}>>>>>>", vo.getRobotId()); 28 | TradingStrategy strategy = builderStrategy(vo); 29 | try { 30 | strategy.execute(); 31 | } catch (StrategyException e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | } 36 | 37 | private TradingStrategy builderStrategy(RobotStrategyVo vo) { 38 | 39 | StrategyType simple = StrategyType.simple; 40 | StrategyBuilder builder = new StrategyBuilder().setRedisUtil(redisUtil) 41 | .setStratrgyType(simple) 42 | .setRobotStrategyVo(vo) 43 | .setVpnProxyConfig(vpnProxyConfig) 44 | .buildApiClient() 45 | .buildTradingApi().buildMarketConfig() 46 | .buildStrategyConfig().buildAccountConfig(); 47 | 48 | TradingStrategy huoBIndicatoryStrategy = new HuoBiSimpleStrategyImpl(redisUtil, vo.getRobotId()); 49 | 50 | log.info("加载机器人{}>>>>>>", vo.getRobotId()); 51 | huoBIndicatoryStrategy.init(builder); 52 | return huoBIndicatoryStrategy; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8024 3 | address: 0.0.0.0 4 | eureka: 5 | client: 6 | serviceUrl: 7 | defaultZone: http://${EUREKA_ZONE_HOST:127.0.0.1}:${EUREKA_ZONE_PORT:8761}/eureka/ 8 | instance: 9 | prefer-ip-address: true 10 | ip-address: ${server.address} 11 | spring: 12 | application: 13 | name: qt-client 14 | # rabbitmq: 15 | # host: ${RABBIT_MQ_HOST:localhost} 16 | # port: ${RABBIT_MQ_PORT:5672} 17 | # username: ${RABBIT_MQ_USERNAME:yang} 18 | # password: ${RABBIT_MQ_PASSWORD:yang} 19 | redis: 20 | database: 0 21 | host: 127.0.0.1 22 | port: 6379 23 | password: 24 | jedis: 25 | pool: 26 | max-active: 8 27 | max-wait: -1 28 | max-idle: 8 29 | min-idle: 0 30 | timeout: 15000 31 | feign: 32 | hystrix: 33 | enabled: true 34 | 35 | management: 36 | endpoints: 37 | web: 38 | exposure: 39 | include: '*' 40 | base-path: / 41 | vpnproxy: 42 | enable: true 43 | ip: 127.0.0.1 44 | port: 1088 45 | 46 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8024 3 | address: 0.0.0.0 4 | eureka: 5 | client: 6 | serviceUrl: 7 | defaultZone: http://${EUREKA_ZONE_HOST:124.156.196.215}:${EUREKA_ZONE_PORT:8762}/eureka/ 8 | instance: 9 | prefer-ip-address: true 10 | ip-address: 124.156.196.215 11 | 12 | spring: 13 | application: 14 | name: qt-client 15 | redis: 16 | database: 0 17 | host: 127.0.0.1 18 | port: 6379 19 | password: 20 | jedis: 21 | pool: 22 | max-active: 8 23 | max-wait: -1 24 | max-idle: 8 25 | min-idle: 0 26 | timeout: 15000 27 | feign: 28 | hystrix: 29 | enabled: true 30 | 31 | management: 32 | endpoints: 33 | web: 34 | exposure: 35 | include: '*' 36 | base-path: / 37 | vpnproxy: 38 | enable: false 39 | ip: 127.0.0.1 40 | port: 64035 41 | 42 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ _ _ _ _ __ 2 | / / | | | (_) | | \ \ 3 | / / __ _ _ _ __ _ _ __ | |_ ______ ___| |_ ___ _ __ | |_ \ \ 4 | < < / _` | | | |/ _` | '_ \| __|______/ __| | |/ _ | '_ \| __| > > 5 | \ | (_| | |_| | (_| | | | | |_ | (__| | | __| | | | |_ / / 6 | \_\__, |\__,_|\__,_|_| |_|\__| \___|_|_|\___|_| |_|\__/_/ 7 | | | 8 | |_| -------------------------------------------------------------------------------- /qt-client/src/test/java/Test.java: -------------------------------------------------------------------------------- 1 | public class Test { 2 | 3 | public static void main(String[] args) { 4 | 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/config/JsonConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.config; 2 | 3 | import com.alibaba.fastjson.serializer.SerializerFeature; 4 | import com.alibaba.fastjson.support.config.FastJsonConfig; 5 | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; 6 | import org.springframework.boot.autoconfigure.http.HttpMessageConverters; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.http.converter.HttpMessageConverter; 10 | 11 | @Configuration 12 | public class JsonConfig { 13 | 14 | /** 15 | * 覆盖方法configureMessageConverters,使用fastJson 16 | * 17 | * @return 18 | */ 19 | @Bean 20 | public HttpMessageConverters fastJsonHttpMessageConverters() { 21 | //1、定义一个convert转换消息的对象 22 | FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); 23 | //2、添加fastjson的配置信息 24 | FastJsonConfig fastJsonConfig = new FastJsonConfig(); 25 | fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); 26 | //3、在convert中添加配置信息 27 | fastConverter.setFastJsonConfig(fastJsonConfig); 28 | //4、将convert添加到converters中 29 | HttpMessageConverter converter = fastConverter; 30 | return new HttpMessageConverters(converter); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.config; 2 | 3 | import com.fasterxml.jackson.annotation.JsonAutoDetect; 4 | import com.fasterxml.jackson.annotation.PropertyAccessor; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.data.redis.connection.RedisConnectionFactory; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.data.redis.core.StringRedisTemplate; 11 | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; 12 | 13 | /** 14 | * RedisConfig 重新 redis存储对象的键值对 15 | */ 16 | @Configuration 17 | public class RedisConfig { 18 | 19 | /** 20 | * 定义 StringRedisTemplate ,指定序列化和反序列化的处理类 21 | * 22 | * @param factory 23 | * @return 24 | */ 25 | @Bean 26 | public RedisTemplate redisTemplate(RedisConnectionFactory factory) { 27 | StringRedisTemplate template = new StringRedisTemplate(factory); 28 | Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>( 29 | Object.class); 30 | ObjectMapper om = new ObjectMapper(); 31 | om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); 32 | om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); 33 | jackson2JsonRedisSerializer.setObjectMapper(om); 34 | //序列化 值时使用此序列化方法 35 | template.setValueSerializer(jackson2JsonRedisSerializer); 36 | template.afterPropertiesSet(); 37 | return template; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/config/VpnProxyConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * Created by yang on 2019/5/16. 9 | */ 10 | @Data 11 | @Component 12 | @ConfigurationProperties(prefix = "vpnproxy") 13 | public class VpnProxyConfig { 14 | 15 | private Boolean enable; 16 | 17 | private String ip; 18 | 19 | private int port; 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/constans/IndicatorCons.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.constans; 2 | 3 | /** 4 | * Created by yang on 2019/5/30. 5 | */ 6 | public class IndicatorCons { 7 | public static final String and = "and"; //and 8 | public static final String or = "or"; //or 9 | 10 | public static final String num_under = "num_under"; //小于 11 | public static final String num_over = "num_over"; //大于 12 | public static final String num_cross_up = "num_cross_up"; //大于等于 13 | public static final String num_cross_down = "num_cross_down"; //小于等于 14 | public static final String num_equal = "num_equal"; //小于等于 15 | 16 | 17 | public static final String indicator_cross_up = "indicator_cross_up"; //交叉向上 18 | public static final String indicator_cross_down = "indicator_cross_down"; //交叉乡下 19 | public static final String indicator_up = "indicator_up"; //大于 20 | public static final String indicator_under = "indicator_under"; //小于 21 | public static final String indicator_equal = "indicator_equal"; //等于 22 | 23 | 24 | public static final String CLOSE = "CLOSE"; 25 | public static final String OPEN = "OPEN"; 26 | public static final String HIGHT = "HIGHT"; 27 | public static final String LOW = "LOW"; 28 | 29 | public static final String PRICE = "PRICE"; 30 | 31 | public static final String VOLUME = "VOLUME"; 32 | 33 | 34 | //指标名称 35 | public static final String RSI = "RSI"; 36 | public static final String ADX = "ADX"; 37 | public static final String SMA = "SMA"; 38 | 39 | public static final String EMA = "EMA"; 40 | 41 | public static final String CCI = "CCI"; 42 | 43 | public static final String AO = "AO"; 44 | public static final String MACD = "MACD"; 45 | public static final String STOCHK = "STOCH-K"; 46 | public static final String STOCHD = "STOCH-D"; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/constans/RobotRedisKeyConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.constans; 2 | 3 | 4 | public class RobotRedisKeyConfig { 5 | 6 | /** 7 | * 机器人是否启动的标志 8 | */ 9 | private final static String robotIsStartStateKey = "robot_start_id_"; 10 | 11 | /** 12 | * 机器人是否还在运行的标志 13 | * 14 | * @return 15 | */ 16 | private final static String robotIsRunStateKey = "robot_run_id_"; 17 | 18 | /** 19 | * 订单成功后的id存储在queue这个队列中 20 | */ 21 | private final static String queue = "order_id"; 22 | 23 | /** 24 | * 订单成功后的id存储在queue这个队列中 25 | */ 26 | private final static String robot_msg_queue = "robot_msg"; 27 | 28 | /** 29 | * 30 | */ 31 | private final static String order_profit = "order_profit"; 32 | 33 | /** 34 | * 每个交易对对应的 和 quote 标志 35 | */ 36 | private final static String symbol = "symbol_base_quote_price_amount_"; 37 | 38 | public final static String ok = "ok"; 39 | 40 | 41 | public static String getOrder_profit() { 42 | return order_profit; 43 | } 44 | 45 | public static String getRobot_msg_queue() { 46 | return robot_msg_queue; 47 | } 48 | 49 | public static String getQueue() { 50 | return queue; 51 | } 52 | 53 | public static String getSymbol() { 54 | return symbol; 55 | } 56 | 57 | public static String getRobotIsStartStateKey() { 58 | return robotIsStartStateKey; 59 | } 60 | 61 | public static String getRobotIsRunStateKey() { 62 | return robotIsRunStateKey; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/bo/RobotBo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.bo; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | @Data 8 | public class RobotBo { 9 | private static final long serialVersionUID = 1L; 10 | 11 | 12 | private Integer id; 13 | 14 | private String robotName; 15 | 16 | private String symbol; 17 | 18 | private String userId; 19 | 20 | private Integer strategyId; 21 | 22 | private String clientAddress; 23 | 24 | private Date createTime; 25 | 26 | private Integer isDelete; 27 | 28 | private Integer isRun; 29 | 30 | private String strategyName; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/entity/MarketOrder.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.entity; 2 | 3 | import com.quant.common.domain.response.TradeBean; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author yang 10 | 11 | * @desc MarketOrder 12 | * @date 2019/7/9 13 | */ 14 | @Data 15 | public class MarketOrder { 16 | 17 | List buy; 18 | List sell; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/entity/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.entity; 2 | 3 | import com.baomidou.mybatisplus.enums.IdType; 4 | import com.baomidou.mybatisplus.annotations.TableId; 5 | import com.baomidou.mybatisplus.annotations.TableField; 6 | import com.baomidou.mybatisplus.activerecord.Model; 7 | import java.io.Serializable; 8 | 9 | /** 10 | *

11 | * 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-17 16 | */ 17 | public class Symbol extends Model { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | @TableId(value = "id", type = IdType.INPUT) 22 | private Integer id; 23 | @TableField("base_currency") 24 | private String baseCurrency; 25 | @TableField("quote_currency") 26 | private String quoteCurrency; 27 | @TableField("price_precision") 28 | private Integer pricePrecision; 29 | @TableField("amount_precision") 30 | private Integer amountPrecision; 31 | private String symbol; 32 | 33 | 34 | public Integer getId() { 35 | return id; 36 | } 37 | 38 | public void setId(Integer id) { 39 | this.id = id; 40 | } 41 | 42 | public String getBaseCurrency() { 43 | return baseCurrency; 44 | } 45 | 46 | public void setBaseCurrency(String baseCurrency) { 47 | this.baseCurrency = baseCurrency; 48 | } 49 | 50 | public String getQuoteCurrency() { 51 | return quoteCurrency; 52 | } 53 | 54 | public void setQuoteCurrency(String quoteCurrency) { 55 | this.quoteCurrency = quoteCurrency; 56 | } 57 | 58 | public Integer getPricePrecision() { 59 | return pricePrecision; 60 | } 61 | 62 | public void setPricePrecision(Integer pricePrecision) { 63 | this.pricePrecision = pricePrecision; 64 | } 65 | 66 | public Integer getAmountPrecision() { 67 | return amountPrecision; 68 | } 69 | 70 | public void setAmountPrecision(Integer amountPrecision) { 71 | this.amountPrecision = amountPrecision; 72 | } 73 | 74 | public String getSymbol() { 75 | return symbol; 76 | } 77 | 78 | public void setSymbol(String symbol) { 79 | this.symbol = symbol; 80 | } 81 | 82 | @Override 83 | protected Serializable pkVal() { 84 | return this.id; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "Symbol{" + 90 | ", id=" + id + 91 | ", baseCurrency=" + baseCurrency + 92 | ", quoteCurrency=" + quoteCurrency + 93 | ", pricePrecision=" + pricePrecision + 94 | ", amountPrecision=" + amountPrecision + 95 | ", symbol=" + symbol + 96 | "}"; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/request/CreateOrderRequest.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.request; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CreateOrderRequest { 7 | 8 | /** 9 | * 交易对,必填,例如:"ethcny", 10 | */ 11 | String symbol; 12 | 13 | /** 14 | * 账户ID,必填,例如:"12345" 15 | */ 16 | String accountId; 17 | 18 | /** 19 | * 当订单类型为buy-limit,sell-limit时,表示订单数量, 当订单类型为buy-market时,表示订单总金额, 当订单类型为sell-market时,表示订单总数量 20 | */ 21 | String amount; 22 | 23 | /** 24 | * 订单价格,仅针对限价单有效,例如:"1234.56" 25 | */ 26 | String price = "0.0"; 27 | 28 | /** 29 | * 订单类型,取值范围"buy-market,sell-market,buy-limit,sell-limit" 30 | */ 31 | String type; 32 | 33 | /** 34 | * 订单来源,例如:"api" 35 | */ 36 | String source = "com/qklx/qt/core/api"; 37 | } 38 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/request/DepthRequest.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.request; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 14:39 7 | */ 8 | 9 | public class DepthRequest { 10 | 11 | //交易对 12 | public String symbol; 13 | 14 | //Depth 类型 step0, step1, step2, step3, step4, step5(合并深度0-5);step0时,不合并深度 15 | public String type; 16 | 17 | public String getSymbol() { 18 | return symbol; 19 | } 20 | 21 | public void setSymbol(String symbol) { 22 | this.symbol = symbol; 23 | } 24 | 25 | public String getType() { 26 | return type; 27 | } 28 | 29 | public void setType(String type) { 30 | this.type = type; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/request/IntrustOrdersDetailRequest.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.request; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 19:08 7 | */ 8 | 9 | public class IntrustOrdersDetailRequest { 10 | 11 | public static interface OrderType { 12 | /** 13 | * 限价买入 14 | */ 15 | static final String BUY_LIMIT = "buy-limit"; 16 | /** 17 | * 限价卖出 18 | */ 19 | static final String SELL_LIMIT = "sell-limit"; 20 | /** 21 | * 市价买入 22 | */ 23 | static final String BUY_MARKET = "buy-market"; 24 | /** 25 | * 市价卖出 26 | */ 27 | static final String SELL_MARKET = "sell-market"; 28 | } 29 | 30 | public static interface OrderStates { 31 | /** 32 | * pre-submitted 准备提交 33 | */ 34 | static final String PRE_SUBMITTED = "pre-submitted"; 35 | /** 36 | * submitted 已提交 37 | */ 38 | static final String SUBMITTED = "submitted"; 39 | /** 40 | * partial-filled 部分成交 41 | */ 42 | static final String PARTIAL_FILLED = "partial-filled"; 43 | /** 44 | * partial-canceled 部分成交撤销 45 | */ 46 | static final String PARTIAL_CANCELED = "partial-canceled"; 47 | 48 | /** 49 | * filled 完全成交 50 | */ 51 | static final String FILLED = "filled"; 52 | /** 53 | * canceled 已撤销 54 | */ 55 | static final String CANCELED = "canceled"; 56 | } 57 | 58 | public String symbol; //true string 交易对 btcusdt, bccbtc, rcneth ... 59 | public String types; //false string 查询的订单类型组合,使用','分割 buy-market:市价买, sell-market:市价卖, buy-limit:限价买, sell-limit:限价卖 60 | public String startDate; //false string 查询开始日期, 日期格式yyyy-mm-dd 61 | public String endDate; //false string 查询结束日期, 日期格式yyyy-mm-dd 62 | public String states; //true string 查询的订单状态组合,使用','分割 pre-submitted 准备提交, submitted 已提交, partial-filled 部分成交, 63 | // partial-canceled 部分成交撤销, filled 完全成交, canceled 已撤销 64 | public String from; //false string 查询起始 ID 65 | public String direct; //false string 查询方向 prev 向前,next 向后 66 | public String size; //false string 查询记录大小 67 | } 68 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Account.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 16:02 9 | */ 10 | @Data 11 | public class Account { 12 | public long id; 13 | public String type; 14 | public String state; 15 | } 16 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Accounts.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 16:02 7 | */ 8 | 9 | public class Accounts { 10 | /** 11 | * id : 100009 12 | * type : spot 13 | * state : working 14 | * user-id : 1000 15 | */ 16 | 17 | private int id; 18 | private String type; 19 | private String state; 20 | private int userid; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getType() { 31 | return type; 32 | } 33 | 34 | public void setType(String type) { 35 | this.type = type; 36 | } 37 | 38 | public String getState() { 39 | return state; 40 | } 41 | 42 | public void setState(String state) { 43 | this.state = state; 44 | } 45 | 46 | public int getUserid() { 47 | return userid; 48 | } 49 | 50 | public void setUserid(int userid) { 51 | this.userid = userid; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/AccountsResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | 4 | import com.quant.common.exception.ApiException; 5 | 6 | /** 7 | * @Author ISME 8 | * @Date 2018/1/14 9 | * @Time 16:01 10 | */ 11 | 12 | public class AccountsResponse { 13 | 14 | /** 15 | * status : ok 16 | * data : [{"id":100009,"type":"spot","state":"working","user-id":1000}] 17 | */ 18 | 19 | private String status; 20 | public String errCode; 21 | public String errMsg; 22 | private T data; 23 | 24 | public T checkAndReturn() { 25 | if ("ok".equals(status)) { 26 | return data; 27 | } 28 | throw new ApiException(errCode, errMsg); 29 | } 30 | 31 | public String getStatus() { 32 | return status; 33 | } 34 | 35 | public void setStatus(String status) { 36 | this.status = status; 37 | } 38 | 39 | public T getData() { 40 | return data; 41 | } 42 | 43 | public void setData(T data) { 44 | this.data = data; 45 | } 46 | 47 | public String getErrCode() { 48 | return errCode; 49 | } 50 | 51 | public void setErrCode(String errCode) { 52 | this.errCode = errCode; 53 | } 54 | 55 | public String getErrMsg() { 56 | return errMsg; 57 | } 58 | 59 | public void setErrMsg(String errMsg) { 60 | this.errMsg = errMsg; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/ApiResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import com.quant.common.exception.ApiException; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class ApiResponse { 8 | 9 | public String status; 10 | public String errCode; 11 | public String errMsg; 12 | public T data; 13 | 14 | public T checkAndReturn() { 15 | if ("ok".equals(status)) { 16 | return data; 17 | } 18 | throw new ApiException(errCode, errMsg); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Balance.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 16:15 7 | */ 8 | 9 | public class Balance { 10 | /** 11 | * id : 100009 12 | * type : spot 13 | * state : working 14 | * list : [{"currency":"usdt","type":"trade","balance":"500009195917.4362872650"}] 15 | * user-id : 1000 16 | */ 17 | 18 | private String id; 19 | private String type; 20 | private String state; 21 | private String userid; 22 | private T list; 23 | 24 | public String getId() { 25 | return id; 26 | } 27 | 28 | public void setId(String id) { 29 | this.id = id; 30 | } 31 | 32 | public String getType() { 33 | return type; 34 | } 35 | 36 | public void setType(String type) { 37 | this.type = type; 38 | } 39 | 40 | public String getState() { 41 | return state; 42 | } 43 | 44 | public void setState(String state) { 45 | this.state = state; 46 | } 47 | 48 | public String getUserid() { 49 | return userid; 50 | } 51 | 52 | public void setUserid(String userid) { 53 | this.userid = userid; 54 | } 55 | 56 | public T getList() { 57 | return list; 58 | } 59 | 60 | public void setList(T list) { 61 | this.list = list; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/BalanceBean.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 16:23 7 | */ 8 | 9 | public class BalanceBean { 10 | /** 11 | * currency : usdt 12 | * type : trade 13 | * balance : 500009195917.4362872650 14 | */ 15 | 16 | private String currency; 17 | private String type; 18 | private String balance; 19 | 20 | public String getCurrency() { 21 | return currency; 22 | } 23 | 24 | public void setCurrency(String currency) { 25 | this.currency = currency; 26 | } 27 | 28 | public String getType() { 29 | return type; 30 | } 31 | 32 | public void setType(String type) { 33 | this.type = type; 34 | } 35 | 36 | public String getBalance() { 37 | return balance; 38 | } 39 | 40 | public void setBalance(String balance) { 41 | this.balance = balance; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/BalanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 16:11 7 | */ 8 | 9 | public class BalanceResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * data : {"id":"100009","type":"spot","state":"working","list":[{"currency":"usdt","type":"trade","balance":"500009195917.4362872650"}],"user-id":"1000"} 15 | */ 16 | 17 | private String status; 18 | public String errCode; 19 | public String errMsg; 20 | private T data; 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public T getData() { 31 | return data; 32 | } 33 | 34 | public void setData(T data) { 35 | this.data = data; 36 | } 37 | 38 | public String getErrCode() { 39 | return errCode; 40 | } 41 | 42 | public void setErrCode(String errCode) { 43 | this.errCode = errCode; 44 | } 45 | 46 | public String getErrMsg() { 47 | return errMsg; 48 | } 49 | 50 | public void setErrMsg(String errMsg) { 51 | this.errMsg = errMsg; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Batchcancel.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:52 7 | */ 8 | 9 | public class Batchcancel { 10 | private T1 success; 11 | private T2 failed; 12 | 13 | public T1 getSuccess() { 14 | return success; 15 | } 16 | 17 | public void setSuccess(T1 success) { 18 | this.success = success; 19 | } 20 | 21 | public T2 getFailed() { 22 | return failed; 23 | } 24 | 25 | public void setFailed(T2 failed) { 26 | this.failed = failed; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/BatchcancelBean.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:53 7 | */ 8 | 9 | public class BatchcancelBean { 10 | /** 11 | * err-msg : 记录无效 12 | * order-id : 2 13 | * err-code : base-record-invalid 14 | */ 15 | 16 | private String errmsg; 17 | private String orderid; 18 | private String errcode; 19 | 20 | public String getErrmsg() { 21 | return errmsg; 22 | } 23 | 24 | public void setErrmsg(String errmsg) { 25 | this.errmsg = errmsg; 26 | } 27 | 28 | public String getOrderid() { 29 | return orderid; 30 | } 31 | 32 | public void setOrderid(String orderid) { 33 | this.orderid = orderid; 34 | } 35 | 36 | public String getErrcode() { 37 | return errcode; 38 | } 39 | 40 | public void setErrcode(String errcode) { 41 | this.errcode = errcode; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/BatchcancelResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:51 7 | */ 8 | 9 | public class BatchcancelResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * data : {"success":["1","3"],"failed":[{"err-msg":"记录无效","order-id":"2","err-code":"base-record-invalid"}]} 15 | */ 16 | 17 | private String status; 18 | public String errCode; 19 | public String errMsg; 20 | private T data; 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public String getErrCode() { 31 | return errCode; 32 | } 33 | 34 | public void setErrCode(String errCode) { 35 | this.errCode = errCode; 36 | } 37 | 38 | public String getErrMsg() { 39 | return errMsg; 40 | } 41 | 42 | public void setErrMsg(String errMsg) { 43 | this.errMsg = errMsg; 44 | } 45 | 46 | public T getData() { 47 | return data; 48 | } 49 | 50 | public void setData(T data) { 51 | this.data = data; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Currencys.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:47 7 | */ 8 | 9 | public class Currencys { 10 | } 11 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/CurrencysResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 15:46 9 | */ 10 | 11 | public class CurrencysResponse { 12 | 13 | 14 | /** 15 | * status : ok 16 | * data : ["usdt","eth","etc"] 17 | */ 18 | 19 | private String status; 20 | public String errCode; 21 | public String errMsg; 22 | private List data; 23 | 24 | public String getStatus() { 25 | return status; 26 | } 27 | 28 | public void setStatus(String status) { 29 | this.status = status; 30 | } 31 | 32 | public List getData() { 33 | return data; 34 | } 35 | 36 | public void setData(List data) { 37 | this.data = data; 38 | } 39 | 40 | public String getErrCode() { 41 | return errCode; 42 | } 43 | 44 | public void setErrCode(String errCode) { 45 | this.errCode = errCode; 46 | } 47 | 48 | public String getErrMsg() { 49 | return errMsg; 50 | } 51 | 52 | public void setErrMsg(String errMsg) { 53 | this.errMsg = errMsg; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Depth.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.List; 5 | 6 | /** 7 | * @Author ISME 8 | * @Date 2018/1/14 9 | * @Time 14:39 10 | */ 11 | 12 | public class Depth { 13 | 14 | /** 15 | * id : 1489464585407 16 | * ts : 1489464585407 17 | * bids : [[7964,0.0678],[7963,0.9162]] 18 | * asks : [[7979,0.0736],[8020,13.6584]] 19 | */ 20 | 21 | private String id; 22 | private String ts; 23 | private List> bids; 24 | private List> asks; 25 | 26 | public String getId() { 27 | return id; 28 | } 29 | 30 | public void setId(String id) { 31 | this.id = id; 32 | } 33 | 34 | public String getTs() { 35 | return ts; 36 | } 37 | 38 | public void setTs(String ts) { 39 | this.ts = ts; 40 | } 41 | 42 | public List> getBids() { 43 | return bids; 44 | } 45 | 46 | public void setBids(List> bids) { 47 | this.bids = bids; 48 | } 49 | 50 | public List> getAsks() { 51 | return asks; 52 | } 53 | 54 | public void setAsks(List> asks) { 55 | this.asks = asks; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/DepthResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 14:38 7 | */ 8 | 9 | public class DepthResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * ch : market.btcusdt.depth.step1 15 | * ts : 1489472598812 16 | * tick : {"id":"1489464585407","ts":"1489464585407","bids":[[7964,0.0678],[7963,0.9162]],"asks":[[7979,0.0736],[8020,13.6584]]} 17 | */ 18 | 19 | private String status; 20 | private String ch; 21 | private String ts; 22 | public String errCode; 23 | public String errMsg; 24 | 25 | /** 26 | * tick 说明: 27 | * "tick": { 28 | * "id": 消息id, 29 | * "ts": 消息生成时间,单位:毫秒, 30 | * "bids": 买盘,[price(成交价), amount(成交量)], 按price降序, 31 | * "asks": 卖盘,[price(成交价), amount(成交量)], 按price升序 32 | * } 33 | */ 34 | private Depth tick; 35 | 36 | 37 | public String getStatus() { 38 | return status; 39 | } 40 | 41 | public void setStatus(String status) { 42 | this.status = status; 43 | } 44 | 45 | public String getCh() { 46 | return ch; 47 | } 48 | 49 | public void setCh(String ch) { 50 | this.ch = ch; 51 | } 52 | 53 | public String getTs() { 54 | return ts; 55 | } 56 | 57 | public void setTs(String ts) { 58 | this.ts = ts; 59 | } 60 | 61 | public Depth getTick() { 62 | return tick; 63 | } 64 | 65 | public void setTick(Depth tick) { 66 | this.tick = tick; 67 | } 68 | 69 | public String getErrCode() { 70 | return errCode; 71 | } 72 | 73 | public void setErrCode(String errCode) { 74 | this.errCode = errCode; 75 | } 76 | 77 | public String getErrMsg() { 78 | return errMsg; 79 | } 80 | 81 | public void setErrMsg(String errMsg) { 82 | this.errMsg = errMsg; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:31 7 | */ 8 | 9 | public class DetailResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * ch : market.btcusdt.detail 15 | * ts : 1489473538996 16 | * tick : {"amount":4316.4346,"open":8090.54,"close":7962.62,"high":8119,"ts":1489464451000,"id":1489464451,"count":9595,"low":7875,"vol":3.449727690576E7} 17 | */ 18 | 19 | private String status; 20 | private String ch; 21 | private long ts; 22 | public String errCode; 23 | public String errMsg; 24 | private T tick; 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | 34 | public String getCh() { 35 | return ch; 36 | } 37 | 38 | public void setCh(String ch) { 39 | this.ch = ch; 40 | } 41 | 42 | public long getTs() { 43 | return ts; 44 | } 45 | 46 | public void setTs(long ts) { 47 | this.ts = ts; 48 | } 49 | 50 | public String getErrCode() { 51 | return errCode; 52 | } 53 | 54 | public void setErrCode(String errCode) { 55 | this.errCode = errCode; 56 | } 57 | 58 | public String getErrMsg() { 59 | return errMsg; 60 | } 61 | 62 | public void setErrMsg(String errMsg) { 63 | this.errMsg = errMsg; 64 | } 65 | 66 | public T getTick() { 67 | return tick; 68 | } 69 | 70 | public void setTick(T tick) { 71 | this.tick = tick; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Details.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * @Author ISME 9 | * @Date 2018/1/14 10 | * @Time 15:33 11 | */ 12 | @Data 13 | public class Details { 14 | 15 | /** 16 | * amount : 4316.4346 17 | * open : 8090.54 18 | * close : 7962.62 19 | * high : 8119 20 | * ts : 1489464451000 21 | * id : 1489464451 22 | * count : 9595 23 | * low : 7875 24 | * vol : 3.449727690576E7 25 | */ 26 | 27 | private BigDecimal amount; 28 | private BigDecimal open; 29 | private BigDecimal close; 30 | private BigDecimal high; 31 | private String ts; 32 | private String id; 33 | private String count; 34 | private BigDecimal low; 35 | private BigDecimal vol; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/HistoryTrade.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:24 7 | */ 8 | 9 | public class HistoryTrade { 10 | /** 11 | * id : 17592256642623 12 | * amount : 0.04 13 | * price : 1997 14 | * direction : buy 15 | * ts : 1502448920106 16 | */ 17 | 18 | private long id; 19 | private double amount; 20 | private int price; 21 | private String direction; 22 | private long ts; 23 | 24 | public long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(long id) { 29 | this.id = id; 30 | } 31 | 32 | public double getAmount() { 33 | return amount; 34 | } 35 | 36 | public void setAmount(double amount) { 37 | this.amount = amount; 38 | } 39 | 40 | public int getPrice() { 41 | return price; 42 | } 43 | 44 | public void setPrice(int price) { 45 | this.price = price; 46 | } 47 | 48 | public String getDirection() { 49 | return direction; 50 | } 51 | 52 | public void setDirection(String direction) { 53 | this.direction = direction; 54 | } 55 | 56 | public long getTs() { 57 | return ts; 58 | } 59 | 60 | public void setTs(long ts) { 61 | this.ts = ts; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/HistoryTradeResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:22 7 | */ 8 | 9 | public class HistoryTradeResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * ch : market.ethusdt.trade.detail 15 | * ts : 1502448925216 16 | * data : [{"id":31459998,"ts":1502448920106,"data":[{"id":17592256642623,"amount":0.04,"price":1997,"direction":"buy","ts":1502448920106}]}] 17 | */ 18 | 19 | private String status; 20 | private String ch; 21 | private long ts; 22 | public String errCode; 23 | public String errMsg; 24 | private T data; 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | 34 | public String getCh() { 35 | return ch; 36 | } 37 | 38 | public void setCh(String ch) { 39 | this.ch = ch; 40 | } 41 | 42 | public long getTs() { 43 | return ts; 44 | } 45 | 46 | public void setTs(long ts) { 47 | this.ts = ts; 48 | } 49 | 50 | public T getData() { 51 | return data; 52 | } 53 | 54 | public void setData(T data) { 55 | this.data = data; 56 | } 57 | 58 | public String getErrCode() { 59 | return errCode; 60 | } 61 | 62 | public void setErrCode(String errCode) { 63 | this.errCode = errCode; 64 | } 65 | 66 | public String getErrMsg() { 67 | return errMsg; 68 | } 69 | 70 | public void setErrMsg(String errMsg) { 71 | this.errMsg = errMsg; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/HistoryTradess.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:25 7 | */ 8 | 9 | public class HistoryTradess { 10 | /** 11 | * id : 31459998 12 | * ts : 1502448920106 13 | * data : [{"id":17592256642623,"amount":0.04,"price":1997,"direction":"buy","ts":1502448920106}] 14 | */ 15 | 16 | private int id; 17 | private long ts; 18 | private HistoryTrade data; 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public long getTs() { 29 | return ts; 30 | } 31 | 32 | public void setTs(long ts) { 33 | this.ts = ts; 34 | } 35 | 36 | public HistoryTrade getData() { 37 | return data; 38 | } 39 | 40 | public void setData(HistoryTrade data) { 41 | this.data = data; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/IntrustDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 19:08 7 | */ 8 | 9 | public class IntrustDetailResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * data : [{"id":59378,"symbol":"ethusdt","account-id":100009,"amount":"10.1000000000","price":"100.1000000000","created-at":1494901162595,"type":"buy-limit","field-amount":"10.1000000000","field-cash-amount":"1011.0100000000","field-fees":"0.0202000000","finished-at":1494901400468,"user-id":1000,"source":"api","state":"filled","canceled-at":0,"exchange":"huobi","batch":""}] 15 | */ 16 | 17 | private String status; 18 | public String errCode; 19 | public String errMsg; 20 | private T data; 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public T getData() { 31 | return data; 32 | } 33 | 34 | public void setData(T data) { 35 | this.data = data; 36 | } 37 | 38 | public String getErrCode() { 39 | return errCode; 40 | } 41 | 42 | public void setErrCode(String errCode) { 43 | this.errCode = errCode; 44 | } 45 | 46 | public String getErrMsg() { 47 | return errMsg; 48 | } 49 | 50 | public void setErrMsg(String errMsg) { 51 | this.errMsg = errMsg; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Kline.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author yang 7 | * @Date 2018/1/14 8 | * @Time 11:35 9 | * kline 10 | */ 11 | @Data 12 | public class Kline { 13 | private long id; 14 | private Double amount; 15 | private int count; 16 | private Double open; 17 | private Double close; 18 | private Double low; 19 | private Double high; 20 | private Double vol; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/KlineResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import com.quant.common.exception.ApiException; 4 | import lombok.Data; 5 | 6 | /** 7 | * @Author ISME 8 | * @Date 2018/1/14 9 | * @Time 11:56 10 | */ 11 | @Data 12 | public class KlineResponse { 13 | 14 | private String status; 15 | private String ch; 16 | private String ts; 17 | public String errCode; 18 | public String errMsg; 19 | public T data; 20 | 21 | public T checkAndReturn() { 22 | if ("ok".equals(status)) { 23 | return data; 24 | } 25 | throw new ApiException(errCode, errMsg); 26 | } 27 | 28 | 29 | public String getStatus() { 30 | return status; 31 | } 32 | 33 | public void setStatus(String status) { 34 | this.status = status; 35 | } 36 | 37 | public String getCh() { 38 | return ch; 39 | } 40 | 41 | public void setCh(String ch) { 42 | this.ch = ch; 43 | } 44 | 45 | public String getTs() { 46 | return ts; 47 | } 48 | 49 | public void setTs(String ts) { 50 | this.ts = ts; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/MatchresultsOrdersDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 18:48 7 | */ 8 | 9 | public class MatchresultsOrdersDetailResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * data : [{"id":29553,"order-id":59378,"match-id":59335,"symbol":"ethusdt","type":"buy-limit","source":"api","price":"100.1000000000","filled-amount":"9.1155000000","filled-fees":"0.0182310000","created-at":1494901400435}] 15 | */ 16 | 17 | private String status; 18 | public String errCode; 19 | public String errMsg; 20 | private T data; 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public T getData() { 31 | return data; 32 | } 33 | 34 | public void setData(T data) { 35 | this.data = data; 36 | } 37 | 38 | public String getErrCode() { 39 | return errCode; 40 | } 41 | 42 | public void setErrCode(String errCode) { 43 | this.errCode = errCode; 44 | } 45 | 46 | public String getErrMsg() { 47 | return errMsg; 48 | } 49 | 50 | public void setErrMsg(String errMsg) { 51 | this.errMsg = errMsg; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Merged.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 14:16 9 | */ 10 | 11 | public class Merged { 12 | 13 | /** 14 | * id : 1499225271 15 | * ts : 1499225271000 16 | * close : 1885 17 | * open : 1960 18 | * high : 1985 19 | * low : 1856 20 | * amount : 81486.2926 21 | * count : 42122 22 | * vol : 1.57052744857082E8 23 | * ask : [1885,21.8804] 24 | * bid : [1884,1.6702] 25 | */ 26 | 27 | private int id; 28 | private long ts; 29 | private int close; 30 | private int open; 31 | private int high; 32 | private int low; 33 | private double amount; 34 | private int count; 35 | private double vol; 36 | private List ask; 37 | private List bid; 38 | 39 | public int getId() { 40 | return id; 41 | } 42 | 43 | public void setId(int id) { 44 | this.id = id; 45 | } 46 | 47 | public long getTs() { 48 | return ts; 49 | } 50 | 51 | public void setTs(long ts) { 52 | this.ts = ts; 53 | } 54 | 55 | public int getClose() { 56 | return close; 57 | } 58 | 59 | public void setClose(int close) { 60 | this.close = close; 61 | } 62 | 63 | public int getOpen() { 64 | return open; 65 | } 66 | 67 | public void setOpen(int open) { 68 | this.open = open; 69 | } 70 | 71 | public int getHigh() { 72 | return high; 73 | } 74 | 75 | public void setHigh(int high) { 76 | this.high = high; 77 | } 78 | 79 | public int getLow() { 80 | return low; 81 | } 82 | 83 | public void setLow(int low) { 84 | this.low = low; 85 | } 86 | 87 | public double getAmount() { 88 | return amount; 89 | } 90 | 91 | public void setAmount(double amount) { 92 | this.amount = amount; 93 | } 94 | 95 | public int getCount() { 96 | return count; 97 | } 98 | 99 | public void setCount(int count) { 100 | this.count = count; 101 | } 102 | 103 | public double getVol() { 104 | return vol; 105 | } 106 | 107 | public void setVol(double vol) { 108 | this.vol = vol; 109 | } 110 | 111 | public List getAsk() { 112 | return ask; 113 | } 114 | 115 | public void setAsk(List ask) { 116 | this.ask = ask; 117 | } 118 | 119 | public List getBid() { 120 | return bid; 121 | } 122 | 123 | public void setBid(List bid) { 124 | this.bid = bid; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/MergedResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | 4 | import com.quant.common.exception.ApiException; 5 | 6 | /** 7 | * @Author ISME 8 | * @Date 2018/1/14 9 | * @Time 14:15 10 | */ 11 | 12 | public class MergedResponse { 13 | 14 | /** 15 | * status : ok 16 | * ch : market.ethusdt.detail.merged 17 | * ts : 1499225276950 18 | * tick : {"id":1499225271,"ts":1499225271000,"close":1885,"open":1960,"high":1985,"low":1856,"amount":81486.2926,"count":42122,"vol":1.57052744857082E8,"ask":[1885,21.8804],"bid":[1884,1.6702]} 19 | */ 20 | 21 | private String status; 22 | private String ch; 23 | private long ts; 24 | public String errCode; 25 | public String errMsg; 26 | public T data; 27 | 28 | public T checkAndReturn() { 29 | if ("ok".equals(status)) { 30 | return data; 31 | } 32 | throw new ApiException(errCode, errMsg); 33 | } 34 | 35 | public String getStatus() { 36 | return status; 37 | } 38 | 39 | public void setStatus(String status) { 40 | this.status = status; 41 | } 42 | 43 | public String getCh() { 44 | return ch; 45 | } 46 | 47 | public void setCh(String ch) { 48 | this.ch = ch; 49 | } 50 | 51 | public long getTs() { 52 | return ts; 53 | } 54 | 55 | public void setTs(long ts) { 56 | this.ts = ts; 57 | } 58 | 59 | public String getErrCode() { 60 | return errCode; 61 | } 62 | 63 | public void setErrCode(String errCode) { 64 | this.errCode = errCode; 65 | } 66 | 67 | public String getErrMsg() { 68 | return errMsg; 69 | } 70 | 71 | public void setErrMsg(String errMsg) { 72 | this.errMsg = errMsg; 73 | } 74 | 75 | public T getData() { 76 | return data; 77 | } 78 | 79 | public void setData(T data) { 80 | this.data = data; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/OrdersDetail.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author cyy 7 | * @Date 2018/1/14 8 | * @Time 18:22 9 | */ 10 | @Data 11 | public class OrdersDetail { 12 | 13 | /** 14 | * id : 59378 15 | * symbol : ethusdt 16 | * account-id : 100009 17 | * amount : 10.1000000000 18 | * price : 100.1000000000 19 | * created-at : 1494901162595 20 | * type : buy-limit 21 | * field-amount : 10.1000000000 22 | * field-cash-amount : 1011.0100000000 23 | * field-fees : 0.0202000000 24 | * finished-at : 1494901400468 25 | * user-id : 1000 26 | * source : api 27 | * state : filled 28 | * canceled-at : 0 29 | * exchange : huobi 30 | * batch : 31 | */ 32 | 33 | private String id; 34 | private String symbol; 35 | private String accountId; 36 | private String amount; 37 | private String price; 38 | private long createdAt; 39 | private String type; 40 | private String fieldAmount; 41 | private String fieldCashAmount; 42 | private String fieldFees; 43 | private long finishedAt; 44 | private String userId; 45 | private String source; 46 | private String state; 47 | private long canceleAt; 48 | private String exchange; 49 | private String batch; 50 | } 51 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/OrdersDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 18:21 7 | */ 8 | 9 | public class OrdersDetailResponse { 10 | 11 | /** 12 | * status : ok 13 | * data : {"id":59378,"symbol":"ethusdt","account-id":100009,"amount":"10.1000000000","price":"100.1000000000","created-at":1494901162595,"type":"buy-limit","field-amount":"10.1000000000","field-cash-amount":"1011.0100000000","field-fees":"0.0202000000","finished-at":1494901400468,"user-id":1000,"source":"api","state":"filled","canceled-at":0,"exchange":"huobi","batch":""} 14 | */ 15 | 16 | private String status; 17 | public String errCode; 18 | public String errMsg; 19 | private T data; 20 | 21 | public String getStatus() { 22 | return status; 23 | } 24 | 25 | public void setStatus(String status) { 26 | this.status = status; 27 | } 28 | 29 | public T getData() { 30 | return data; 31 | } 32 | 33 | public void setData(T data) { 34 | this.data = data; 35 | } 36 | 37 | public static class DataBean { 38 | 39 | } 40 | 41 | public String getErrCode() { 42 | return errCode; 43 | } 44 | 45 | public void setErrCode(String errCode) { 46 | this.errCode = errCode; 47 | } 48 | 49 | public String getErrMsg() { 50 | return errMsg; 51 | } 52 | 53 | public void setErrMsg(String errMsg) { 54 | this.errMsg = errMsg; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Place.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:10 7 | */ 8 | 9 | public class Place { 10 | } 11 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/SubmitcancelResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:15 7 | */ 8 | 9 | public class SubmitcancelResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * data : 59378 15 | */ 16 | 17 | private String status; 18 | public String errCode; 19 | public String errMsg; 20 | private String data; 21 | 22 | public String getStatus() { 23 | return status; 24 | } 25 | 26 | public void setStatus(String status) { 27 | this.status = status; 28 | } 29 | 30 | public String getData() { 31 | return data; 32 | } 33 | 34 | public void setData(String data) { 35 | this.data = data; 36 | } 37 | 38 | public String getErrCode() { 39 | return errCode; 40 | } 41 | 42 | public void setErrCode(String errCode) { 43 | this.errCode = errCode; 44 | } 45 | 46 | public String getErrMsg() { 47 | return errMsg; 48 | } 49 | 50 | public void setErrMsg(String errMsg) { 51 | this.errMsg = errMsg; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Symbol { 7 | 8 | private String baseCurrency; 9 | private String quoteCurrency; 10 | private String symbol; 11 | private Integer pricePrecision; 12 | private Integer amountPrecision; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Symbols.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:39 7 | */ 8 | 9 | public class Symbols { 10 | 11 | /** 12 | * amount : 4316.4346 13 | * open : 8090.54 14 | * close : 7962.62 15 | * high : 8119 16 | * ts : 1489464451000 17 | * id : 1489464451 18 | * count : 9595 19 | * low : 7875 20 | * vol : 3.449727690576E7 21 | */ 22 | 23 | private double amount; 24 | private double open; 25 | private double close; 26 | private int high; 27 | private long ts; 28 | private int id; 29 | private int count; 30 | private int low; 31 | private double vol; 32 | 33 | public double getAmount() { 34 | return amount; 35 | } 36 | 37 | public void setAmount(double amount) { 38 | this.amount = amount; 39 | } 40 | 41 | public double getOpen() { 42 | return open; 43 | } 44 | 45 | public void setOpen(double open) { 46 | this.open = open; 47 | } 48 | 49 | public double getClose() { 50 | return close; 51 | } 52 | 53 | public void setClose(double close) { 54 | this.close = close; 55 | } 56 | 57 | public int getHigh() { 58 | return high; 59 | } 60 | 61 | public void setHigh(int high) { 62 | this.high = high; 63 | } 64 | 65 | public long getTs() { 66 | return ts; 67 | } 68 | 69 | public void setTs(long ts) { 70 | this.ts = ts; 71 | } 72 | 73 | public int getId() { 74 | return id; 75 | } 76 | 77 | public void setId(int id) { 78 | this.id = id; 79 | } 80 | 81 | public int getCount() { 82 | return count; 83 | } 84 | 85 | public void setCount(int count) { 86 | this.count = count; 87 | } 88 | 89 | public int getLow() { 90 | return low; 91 | } 92 | 93 | public void setLow(int low) { 94 | this.low = low; 95 | } 96 | 97 | public double getVol() { 98 | return vol; 99 | } 100 | 101 | public void setVol(double vol) { 102 | this.vol = vol; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/SymbolsResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:39 7 | */ 8 | 9 | public class SymbolsResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * ch : market.btcusdt.detail 15 | * ts : 1489473538996 16 | * tick : {"amount":4316.4346,"open":8090.54,"close":7962.62,"high":8119,"ts":1489464451000,"id":1489464451,"count":9595,"low":7875,"vol":3.449727690576E7} 17 | */ 18 | 19 | private String status; 20 | private String ch; 21 | private long ts; 22 | public String errCode; 23 | public String errMsg; 24 | private T tick; 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | 34 | public String getCh() { 35 | return ch; 36 | } 37 | 38 | public void setCh(String ch) { 39 | this.ch = ch; 40 | } 41 | 42 | public long getTs() { 43 | return ts; 44 | } 45 | 46 | public void setTs(long ts) { 47 | this.ts = ts; 48 | } 49 | 50 | public String getErrCode() { 51 | return errCode; 52 | } 53 | 54 | public void setErrCode(String errCode) { 55 | this.errCode = errCode; 56 | } 57 | 58 | public String getErrMsg() { 59 | return errMsg; 60 | } 61 | 62 | public void setErrMsg(String errMsg) { 63 | this.errMsg = errMsg; 64 | } 65 | 66 | public T getTick() { 67 | return tick; 68 | } 69 | 70 | public void setTick(T tick) { 71 | this.tick = tick; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/TimestampResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | /** 7 | * @Author ISME 8 | * @Date 2018/1/14 9 | * @Time 15:53 10 | */ 11 | 12 | public class TimestampResponse { 13 | 14 | /** 15 | * status : ok 16 | * data : 1494900087029 17 | */ 18 | 19 | private String status; 20 | private long data; 21 | private String dateTime; 22 | 23 | public String getStatus() { 24 | return status; 25 | } 26 | 27 | public void setStatus(String status) { 28 | this.status = status; 29 | } 30 | 31 | public long getData() { 32 | return data; 33 | } 34 | 35 | public void setData(long data) { 36 | this.data = data; 37 | } 38 | 39 | public String getDateTime() { 40 | SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss"); 41 | Date date = new Date(data); 42 | return sdf.format(date); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/Trade.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 14:52 9 | */ 10 | @Data 11 | public class Trade { 12 | 13 | /** 14 | * id : 600848670 15 | * ts : 1489464451000 16 | * data : [{"id":600848670,"price":7962.62,"amount":0.0122,"direction":"buy","ts":1489464451000}] 17 | */ 18 | 19 | private String id; 20 | private long ts; 21 | private T data; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/TradeBean.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * @Author ISME 9 | * @Date 2018/1/14 10 | * @Time 14:57 11 | */ 12 | @Data 13 | public class TradeBean { 14 | 15 | /** 16 | * id : 600848670 17 | * price : 7962.62 18 | * amount : 0.0122 19 | * direction : buy 20 | * ts : 1489464451000 21 | */ 22 | 23 | private String id; 24 | private BigDecimal price; 25 | private BigDecimal amount; 26 | private String direction; 27 | private long ts; 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/response/TradeResponse.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 14:52 7 | */ 8 | 9 | public class TradeResponse { 10 | 11 | 12 | /** 13 | * status : ok 14 | * ch : market.btcusdt.trade.detail 15 | * ts : 1489473346905 16 | * tick : {"id":600848670,"ts":1489464451000,"data":[{"id":600848670,"price":7962.62,"amount":0.0122,"direction":"buy","ts":1489464451000}]} 17 | */ 18 | 19 | private String status; 20 | private String ch; 21 | private long ts; 22 | public String errCode; 23 | public String errMsg; 24 | private Trade tick; 25 | 26 | public String getStatus() { 27 | return status; 28 | } 29 | 30 | public void setStatus(String status) { 31 | this.status = status; 32 | } 33 | 34 | public String getCh() { 35 | return ch; 36 | } 37 | 38 | public void setCh(String ch) { 39 | this.ch = ch; 40 | } 41 | 42 | public long getTs() { 43 | return ts; 44 | } 45 | 46 | public void setTs(long ts) { 47 | this.ts = ts; 48 | } 49 | 50 | public String getErrCode() { 51 | return errCode; 52 | } 53 | 54 | public void setErrCode(String errCode) { 55 | this.errCode = errCode; 56 | } 57 | 58 | public String getErrMsg() { 59 | return errMsg; 60 | } 61 | 62 | public void setErrMsg(String errMsg) { 63 | this.errMsg = errMsg; 64 | } 65 | 66 | public Trade getTick() { 67 | return tick; 68 | } 69 | 70 | public void setTick(Trade tick) { 71 | this.tick = tick; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/to/IndicatorBean.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.to; 2 | 3 | /** 4 | * Created by yang on 2019/5/28. 5 | */ 6 | public interface IndicatorBean { 7 | 8 | String getCondition(); 9 | 10 | BuyAndSellIndicatorTo.CompareBean getCompare(); 11 | 12 | BuyAndSellIndicatorTo.RuleFirstBean getRuleFirst(); 13 | 14 | BuyAndSellIndicatorTo.RuleSecondBean getRuleSecond(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/to/RobotRunMessage.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.to; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author yang 7 | * @desc 机器人实时日志 8 | * @date 2019/5/26 9 | */ 10 | @Data 11 | public class RobotRunMessage { 12 | 13 | int userId; 14 | int robotId; 15 | String msg; 16 | String date; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/to/RuleBean.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.to; 2 | 3 | /** 4 | * Created by yang on 2019/5/28. 5 | */ 6 | public interface RuleBean { 7 | 8 | public String getName(); 9 | 10 | public String getValue(); 11 | 12 | public String getParams(); 13 | 14 | BuyAndSellIndicatorTo.SourceBean getSource(); 15 | } 16 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/to/llIndicatorTo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.to; 2 | 3 | import com.quant.common.domain.vo.BaseInfoEntity; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by yang on 2019/5/28. 11 | */ 12 | @NoArgsConstructor 13 | @Data 14 | public class llIndicatorTo { 15 | private Integer id; 16 | private BaseInfoEntity baseInfo; 17 | private BuyAndSellIndicatorTo baseData; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/Account.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Account { 7 | 8 | String id; 9 | String type; 10 | String state; 11 | 12 | String accessKey; 13 | 14 | String secretKey; 15 | 16 | String userId; 17 | 18 | } 19 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/AccountVo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | 7 | @Data 8 | public class AccountVo { 9 | Integer id; 10 | @NotBlank(message = "名称 不能为空") 11 | String name; 12 | 13 | @NotBlank(message = "accessKey 不能为空") 14 | String accessKey; 15 | 16 | @NotBlank(message = "secretKey 不能为空") 17 | String secretKey; 18 | 19 | @NotBlank(message = "用户id 不能为空") 20 | int userId; 21 | 22 | String info; 23 | String type; 24 | String state; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/BaseInfoEntity.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | 7 | @Data 8 | public class BaseInfoEntity { 9 | /** 10 | * buyPrice : 1.0E-8 11 | * sleep : 3 12 | * strategyName : 13 | * buyAmount : 14 | * buyAllWeights : 1 15 | * sellAmount : 16 | * isAllBuy : true 17 | * sellPrice : 1.0E-8 18 | * isAllSell : true 19 | * isLimitPrice : true 20 | * sellAllWeights : 1 21 | */ 22 | private BigDecimal buyPrice; 23 | private double sleep; 24 | private String strategyName; 25 | private BigDecimal buyAmount; 26 | private int buyAllWeights; 27 | private BigDecimal sellAmount; 28 | private int isAllBuy; 29 | private BigDecimal sellPrice; 30 | private BigDecimal buyQuotaPrice; 31 | private int isAllSell; 32 | private int isLimitPrice; 33 | private int sellAllWeights; 34 | private int profit; 35 | 36 | } -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/IndicatorCalParam.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import lombok.Data; 5 | 6 | /** 7 | * Created by yang on 2019/5/26. 8 | */ 9 | @Data 10 | public class IndicatorCalParam { 11 | private String indicatorName; 12 | private String[] params; 13 | private BuyAndSellIndicatorTo.SourceBean sourceBean; 14 | } 15 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/IndicatorStrategyVo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import com.quant.common.domain.to.llIndicatorTo; 5 | import lombok.Data; 6 | 7 | import java.math.BigDecimal; 8 | 9 | @Data 10 | public class IndicatorStrategyVo { 11 | 12 | //机器人id 13 | int robotId; 14 | 15 | //机器人托管地址 16 | String address; 17 | 18 | String appKey; 19 | 20 | String appSecret; 21 | 22 | String symbol; 23 | 24 | llIndicatorTo indicatorTo; 25 | 26 | Account accountConfig; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/Market.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class Market { 9 | 10 | String marketName; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/OrderTaskMessage.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @AllArgsConstructor 7 | @Data 8 | public class OrderTaskMessage { 9 | 10 | private Long orderId; 11 | 12 | private String accessKey; 13 | 14 | private String secretKey; 15 | 16 | private int robotId; 17 | 18 | private String userId; 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/ProfitMessage.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | 7 | @Data 8 | public class ProfitMessage { 9 | 10 | 11 | long sellOrderId; 12 | long buyOrderId; 13 | int robot_id; 14 | 15 | BigDecimal buyPrice; 16 | BigDecimal sellPrice; 17 | 18 | BigDecimal buyAmount; 19 | BigDecimal sellAmount; 20 | 21 | BigDecimal buyCashAmount; 22 | BigDecimal sellCashAmount; 23 | //是否盈利 24 | int isProfit; 25 | 26 | BigDecimal diff; 27 | 28 | BigDecimal divide; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/RobotStrategyVo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class RobotStrategyVo { 8 | 9 | //机器人id 10 | int robotId; 11 | 12 | //机器人托管地址 13 | String address; 14 | 15 | String appKey; 16 | 17 | String appSecret; 18 | 19 | String symbol; 20 | //策略信息 21 | StrategyVo strategyVo; 22 | 23 | Account accountConfig; 24 | 25 | @Override 26 | public String toString() { 27 | return "RobotStrategyVo{" + 28 | "robotId=" + robotId + 29 | ", address='" + address + '\'' + 30 | ", strategyVo=" + strategyVo + 31 | '}'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/domain/vo/RobotVo.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.domain.vo; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotNull; 6 | 7 | @Data 8 | public class RobotVo { 9 | Integer id; 10 | @NotNull 11 | String robotName; 12 | @NotNull 13 | String symbol; 14 | @NotNull 15 | int strategyId; 16 | @NotNull 17 | String nodeAddress; 18 | @NotNull 19 | String userId; 20 | @NotNull 21 | int accountId; 22 | } 23 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/AType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | 4 | /** 5 | * spot:现货账户, margin:杠杆账户,otc:OTC 账户,point:点卡账户 6 | */ 7 | 8 | public enum AType { 9 | 10 | 11 | SPOT("spot"), 12 | MARGIN("margin"), 13 | OTC("otc"), 14 | POINT("point"); 15 | 16 | 17 | String str; 18 | 19 | AType(String str) { 20 | this.str = str; 21 | } 22 | 23 | public String getStr() { 24 | return str; 25 | } 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/HBOrderType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | public enum HBOrderType { 4 | /** 5 | * 限价买入 6 | */ 7 | BUY_LIMIT("buy-limit"), 8 | /** 9 | * 限价卖出 10 | */ 11 | SELL_LIMIT("sell-limit"), 12 | 13 | /** 14 | * 市价买入 15 | */ 16 | BUY_MARKET("buy-market"), 17 | /** 18 | * 市价卖出 19 | */ 20 | SELL_MARKET("sell-market"); 21 | 22 | String tyoe; 23 | 24 | HBOrderType(String tyoe) { 25 | this.tyoe = tyoe; 26 | } 27 | 28 | public String getTyoe() { 29 | return tyoe; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/OrderType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.common.enums; 25 | 26 | /** 27 | * @author yang 28 | 29 | * @desc OrderType 30 | * @date 2019/7/9 31 | */ 32 | public enum OrderType { 33 | 34 | /** 35 | * Buy order. 36 | */ 37 | BUY("Buy"), 38 | 39 | /** 40 | * Sell order. 41 | */ 42 | SELL("Sell"); 43 | 44 | private final String orderType; 45 | 46 | OrderType(String orderType) { 47 | this.orderType = orderType; 48 | } 49 | 50 | public String getStringValue() { 51 | return orderType; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/PirceType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | public enum PirceType { 4 | isLimit(1), 5 | notLimit(0); 6 | 7 | 8 | Integer type; 9 | 10 | PirceType(Integer type) { 11 | this.type = type; 12 | } 13 | 14 | public Integer getType() { 15 | return type; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/RobotState.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | /** 4 | * 机器人启动状态 5 | */ 6 | public enum RobotState { 7 | 8 | start(1), 9 | stop(0); 10 | 11 | 12 | int str; 13 | 14 | RobotState(int str) { 15 | this.str = str; 16 | } 17 | 18 | public int getStr() { 19 | return str; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/SellType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | public enum SellType { 4 | sellAll(1), 5 | sellCustom(0); 6 | 7 | 8 | Integer type; 9 | 10 | SellType(Integer type) { 11 | this.type = type; 12 | } 13 | 14 | public Integer getType() { 15 | return type; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/Status.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | 4 | /** 5 | * 返回骂 6 | */ 7 | public enum Status { 8 | 9 | SUCCESS(20000, "请求成功"), 10 | USER_NOT_EXIST(1001, "用户不存在"), 11 | KEYS_NOT_Available(1002, "accesskey和秘钥 不可用"), 12 | Account_maybe_exist(1003, "该api已经存在或者数据服务器异常"), 13 | getRobotListError(1004, "获取机器人列表发生错误"), 14 | startRobotError(1005, "启动client端机器人失败"), 15 | Login_out(50014, "登录过期"), 16 | ERROR(1000, "请求参数异常"); 17 | 18 | int code; 19 | String msg; 20 | 21 | Status(int code, String msg) { 22 | this.code = code; 23 | this.msg = msg; 24 | } 25 | 26 | public int getCode() { 27 | return code; 28 | } 29 | 30 | public void setCode(int code) { 31 | this.code = code; 32 | } 33 | 34 | public String getMsg() { 35 | return msg; 36 | } 37 | 38 | public void setMsg(String msg) { 39 | this.msg = msg; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/StrategyType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | /** 4 | * Created by yang on 2019/8/24. 5 | */ 6 | public enum StrategyType { 7 | /** 8 | * 简单数值 9 | */ 10 | simple(0), 11 | /** 12 | * 指标 13 | */ 14 | indicator(1); 15 | 16 | 17 | Integer type; 18 | 19 | StrategyType(Integer type) { 20 | this.type = type; 21 | } 22 | 23 | public Integer getType() { 24 | return type; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/enums/TraceType.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.enums; 2 | 3 | public enum TraceType { 4 | up("1"), 5 | down("2"); 6 | 7 | 8 | String str; 9 | 10 | TraceType(String str) { 11 | this.str = str; 12 | } 13 | 14 | public String getStr() { 15 | return str; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/exception/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.exception; 2 | 3 | /** 4 | * ApiException if api returns error. 5 | * 6 | * @Date 2018/1/14 7 | * @Time 16:02 8 | */ 9 | 10 | public class ApiException extends RuntimeException { 11 | 12 | final String errCode; 13 | 14 | public ApiException(String errCode, String errMsg) { 15 | super(errMsg); 16 | this.errCode = errCode; 17 | } 18 | 19 | public ApiException(Exception e) { 20 | super(e); 21 | this.errCode = e.getClass().getName(); 22 | } 23 | 24 | public String getErrCode() { 25 | return this.errCode; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/exception/ExchangeNetworkException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2016 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.common.exception; 25 | 26 | /** 27 | * @author yang 28 | 29 | * @desc ExchangeNetworkException 30 | * @date 2019/7/9 31 | */ 32 | public final class ExchangeNetworkException extends Exception { 33 | 34 | private static final long serialVersionUID = 1090595894948829893L; 35 | 36 | /** 37 | * Constructor builds exception with error message. 38 | * 39 | * @param msg the error message. 40 | */ 41 | public ExchangeNetworkException(String msg) { 42 | super(msg); 43 | } 44 | 45 | /** 46 | * Constructor builds exception with error message and original throwable. 47 | * 48 | * @param msg the error message. 49 | * @param e the original exception. 50 | */ 51 | public ExchangeNetworkException(String msg, Throwable e) { 52 | super(msg, e); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/exception/IndicatorException.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.exception; 2 | 3 | /** 4 | * @author yang 5 | * @desc IndicatorException 6 | * @date 2019/5/28 7 | */ 8 | 9 | public class IndicatorException extends RuntimeException { 10 | 11 | final String errCode; 12 | 13 | public IndicatorException(String errCode, String errMsg) { 14 | super(errMsg); 15 | this.errCode = errCode; 16 | } 17 | 18 | public IndicatorException(Exception e) { 19 | super(e); 20 | this.errCode = e.getClass().getName(); 21 | } 22 | 23 | public String getErrCode() { 24 | return this.errCode; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/exception/TradingApiException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.common.exception; 25 | 26 | /** 27 | * @author yang 28 | 29 | * @desc TradingApiException 30 | * @date 2019/7/9 31 | */ 32 | public class TradingApiException extends Exception { 33 | 34 | private static final long serialVersionUID = -8279304672615688060L; 35 | 36 | /** 37 | * Constructor builds exception with error message. 38 | * 39 | * @param msg the error message. 40 | */ 41 | public TradingApiException(String msg) { 42 | super(msg); 43 | } 44 | 45 | /** 46 | * Constructor builds exception with error message and original throwable. 47 | * 48 | * @param msg the error message. 49 | * @param e the original exception. 50 | */ 51 | public TradingApiException(String msg, Throwable e) { 52 | super(msg, e); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/utils/ComputeUtil.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.utils; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | public class ComputeUtil { 7 | 8 | /** 9 | * 根据已有平均值、总量、新增值递推新平均值的公共函数, 计算公式: newAvg = (oldAvg * oldCount)/(oldCount+1) + newVal/(oldCount+1); 10 | * 另外由于目前的需求是保留2位小数,所以当oldCount大到一定程度时,oldCount/(oldCount+1) 趋近于 1 且 1/(oldCount+1) 趋近于 0,就不必执行某些实际计算以减少不必要操作 11 | * 12 | * @param oldAvg 老平均值 13 | * @param oldCount 老的总量 14 | * @param newVal 新值 15 | * @return 新平均值 16 | */ 17 | public static BigDecimal proceedAvg(BigDecimal oldAvg, long oldCount, long newVal) { 18 | if (oldAvg == null) return new BigDecimal(newVal).setScale(2); 19 | // 要保留2位小数, 即需要舍入第三位小数,则若'+'前半部分计算对结果造成的影响小于0.0001, 则不必计算, 即: oldAvg - oldAvg * (oldCount/(oldCount+1)) < 0.0001 20 | // => oldAvg < 0.0001 * (oldCount+1) 21 | // 同理,后半部分若满足 newVal * (1/(oldCount+1)) < 0.0001 也不用算了, 即: newVal < (oldCount+1) * 0.0001 22 | // 且由于:newAvg = oldAvg - oldAvg/(oldCount+1) + newVal/(oldCount+1), 23 | // 那么,若: |newVal - oldAvg|/(oldCount+1) < 0.0001 整个式子就不用算了 24 | double delta = 0.0001 * (oldCount + 1); 25 | if (Math.abs(newVal - oldAvg.doubleValue()) < delta) return oldAvg; 26 | BigDecimal firstPart = null; 27 | if (oldAvg.doubleValue() < delta) { 28 | firstPart = oldAvg; 29 | } else { 30 | firstPart = oldAvg.multiply(new BigDecimal(oldCount)).divide(new BigDecimal(oldCount + 1), 4, 31 | RoundingMode.HALF_UP); 32 | } 33 | 34 | BigDecimal secondPart = null; 35 | if (newVal < delta) { 36 | secondPart = BigDecimal.ZERO; 37 | } else { 38 | secondPart = new BigDecimal(newVal).divide(new BigDecimal(oldCount + 1), 4, RoundingMode.HALF_UP); 39 | } 40 | return firstPart.add(secondPart).setScale(2, RoundingMode.HALF_UP); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.utils; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | public class DateUtils { 7 | 8 | /** 9 | * @author yang 10 | * @desc 使用ThreadLocal保证线程安全 11 | * @date 2019/5/26 12 | */ 13 | private static final ThreadLocal local = new ThreadLocal<>(); 14 | 15 | public static void main(String[] args) { 16 | long time = System.currentTimeMillis(); 17 | Date date = parseTimeMillisToDate(time); 18 | System.out.println(date); 19 | } 20 | 21 | public static Date parseTimeMillisToDate(Long timeStamp) { 22 | return new Date(Long.parseLong(String.valueOf(timeStamp))); 23 | } 24 | 25 | public static String formateDate(Date date, String format) { 26 | if (local.get() != null) { 27 | return local.get().format(date); 28 | } 29 | if (format == null) { 30 | format = "yyyy-MM-dd HH:mm:ss"; 31 | } 32 | final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); 33 | local.set(simpleDateFormat); 34 | return simpleDateFormat.format(date); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/quant/common/utils/JsonFormate.java: -------------------------------------------------------------------------------- 1 | package com.quant.common.utils; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.HashMap; 5 | 6 | public class JsonFormate { 7 | 8 | public static String parseJsonToString(String message) { 9 | message = message.replaceAll("\\\\", ""); 10 | message = message.substring(1, message.length() - 1); 11 | return message; 12 | } 13 | 14 | /** 15 | * 16 | * 使用java.lang.reflect进行转换 17 | * @param object 18 | * @return map 19 | */ 20 | public static HashMap objToHashMap(Object object){ 21 | HashMap map = new HashMap<>(); 22 | try{ 23 | Field[] declaredFields = object.getClass().getDeclaredFields(); 24 | for (Field field : declaredFields) { 25 | field.setAccessible(true); 26 | try { 27 | map.put(field.getName(), field.get(object)); 28 | } catch (IllegalArgumentException | IllegalAccessException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | }catch(SecurityException e){ 33 | e.printStackTrace(); 34 | } 35 | return map; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /qt-common/src/main/resources/libs/opslabJutil-2.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IndexOutOfBounds998/quant4j/cc3af971a3bb96c37c1e87479ef90628176c19b1/qt-common/src/main/resources/libs/opslabJutil-2.0.3.jar -------------------------------------------------------------------------------- /qt-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qt-parent 7 | com.quant 8 | 0.0.1-SNAPSHOT 9 | ../pom.xml 10 | 11 | 4.0.0 12 | jar 13 | qt-core 14 | 15 | 16 | 17 | 18 | com.fasterxml.jackson.core 19 | jackson-databind 20 | ${jackson.version} 21 | 22 | 23 | com.squareup.okhttp3 24 | okhttp 25 | ${okhttp.version} 26 | 27 | 28 | org.slf4j 29 | slf4j-api 30 | ${slf4j.version} 31 | 32 | 33 | com.google.code.gson 34 | gson 35 | 2.3 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter 41 | 42 | 43 | * 44 | * 45 | 46 | 47 | 48 | 49 | com.quant 50 | qt-common 51 | 0.0.1-SNAPSHOT 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | sonatype-oss-snapshot 61 | 62 | https://oss.sonatype.org/content/repositories/snapshots 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-maven-plugin 73 | 74 | exec 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/api/ApiResult.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.api; 2 | 3 | import com.quant.common.enums.Status; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | 7 | 8 | /** 9 | * @author yang 10 | * @desc 返回的数据结构 11 | * @date 2019/7/9 12 | */ 13 | @Data 14 | @AllArgsConstructor 15 | public class ApiResult { 16 | 17 | int code; 18 | 19 | String message; 20 | 21 | Object data; 22 | 23 | public ApiResult() { 24 | } 25 | 26 | public ApiResult(Status status, Object res) { 27 | this.data = res; 28 | this.message = status.getMsg(); 29 | this.code = status.getCode(); 30 | } 31 | 32 | public ApiResult(Status status) { 33 | this.message = status.getMsg(); 34 | this.code = status.getCode(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/AccountConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config; 2 | 3 | 4 | /** 5 | * @author yang 6 | * @desc 账号扩展 7 | * @date 2019/7/9 8 | */ 9 | public interface AccountConfig { 10 | 11 | 12 | String accountId(); 13 | 14 | String getAccessKey(); 15 | 16 | String getSecretKey(); 17 | 18 | String getUserId(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/KlineConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config; 2 | 3 | /** 4 | * @author yang 5 | * @desc k线扩展 6 | * @date 2019/7/9 7 | */ 8 | public interface KlineConfig { 9 | /** 10 | * 每次获取数据的大小 11 | * @return 12 | */ 13 | String size(); 14 | 15 | /** 16 | * 返回数据时间粒度,也就是每根蜡烛的时间区间 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year 17 | * @return 18 | */ 19 | String period(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/MarketConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config; 2 | 3 | /** 4 | * @author yang 5 | * @desc 市场扩展 6 | * @date 2019/7/9 7 | */ 8 | public interface MarketConfig { 9 | /** 10 | * 市场交易对名称 11 | */ 12 | String markName(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/StrategyConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.core.config; 25 | 26 | import com.quant.common.domain.to.llIndicatorTo; 27 | import com.quant.common.domain.vo.StrategyVo; 28 | 29 | /** 30 | * @author yang 31 | * @desc 策略配置扩展 32 | * @date 2019/7/9 33 | */ 34 | public interface StrategyConfig { 35 | 36 | StrategyVo getStrategyVo(); 37 | 38 | llIndicatorTo getIndicatorStrategy(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/imp/HuoBiAccountConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config.imp; 2 | 3 | import com.quant.common.domain.vo.Account; 4 | import com.quant.core.config.AccountConfig; 5 | import lombok.Data; 6 | 7 | @Data 8 | public class HuoBiAccountConfigImpl implements AccountConfig { 9 | 10 | private Account account; 11 | 12 | public HuoBiAccountConfigImpl(Account account) { 13 | this.account = account; 14 | } 15 | 16 | @Override 17 | public String accountId() { 18 | return account.getId(); 19 | } 20 | 21 | @Override 22 | public String getAccessKey() { 23 | return account.getAccessKey(); 24 | } 25 | 26 | @Override 27 | public String getSecretKey() { 28 | return account.getSecretKey(); 29 | } 30 | 31 | @Override 32 | public String getUserId() { 33 | return account.getUserId(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/imp/HuoBiKlineConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config.imp; 2 | 3 | import com.quant.core.config.KlineConfig; 4 | 5 | 6 | public class HuoBiKlineConfigImpl implements KlineConfig { 7 | 8 | String size; 9 | String period; 10 | 11 | public HuoBiKlineConfigImpl(String size, String period) { 12 | this.size = size; 13 | this.period = period; 14 | } 15 | 16 | @Override 17 | public String size() { 18 | return size; 19 | } 20 | 21 | @Override 22 | public String period() { 23 | return period; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/imp/HuoBiMarketConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config.imp; 2 | 3 | import com.quant.core.config.MarketConfig; 4 | import com.quant.common.domain.vo.Market; 5 | 6 | public class HuoBiMarketConfigImpl implements MarketConfig { 7 | private Market market; 8 | 9 | public HuoBiMarketConfigImpl(Market market) { 10 | this.market = market; 11 | } 12 | 13 | 14 | @Override 15 | public String markName() { 16 | return market.getMarketName(); 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/imp/HuoboIndicatorStragegyConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config.imp; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import com.quant.common.domain.to.llIndicatorTo; 5 | import com.quant.common.domain.vo.StrategyVo; 6 | import com.quant.core.config.StrategyConfig; 7 | 8 | /** 9 | * Created by yang on 2019/5/31. 10 | */ 11 | public class HuoboIndicatorStragegyConfig implements StrategyConfig { 12 | 13 | 14 | public HuoboIndicatorStragegyConfig(llIndicatorTo strategyVo) { 15 | this.strategyVo = strategyVo; 16 | } 17 | 18 | private llIndicatorTo strategyVo; 19 | 20 | @Override 21 | public StrategyVo getStrategyVo() { 22 | return null; 23 | } 24 | 25 | @Override 26 | public llIndicatorTo getIndicatorStrategy() { 27 | return strategyVo; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/config/imp/HuoboSimpleStragegyConfig.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.config.imp; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import com.quant.common.domain.to.llIndicatorTo; 5 | import com.quant.common.domain.vo.StrategyVo; 6 | import com.quant.core.config.StrategyConfig; 7 | 8 | /** 9 | * Created by yang on 2019/5/31. 10 | */ 11 | public class HuoboSimpleStragegyConfig implements StrategyConfig { 12 | 13 | 14 | public HuoboSimpleStragegyConfig(StrategyVo strategyVo) { 15 | this.strategyVo = strategyVo; 16 | } 17 | 18 | private StrategyVo strategyVo; 19 | 20 | @Override 21 | public StrategyVo getStrategyVo() { 22 | return strategyVo; 23 | } 24 | 25 | @Override 26 | public llIndicatorTo getIndicatorStrategy() { 27 | return null; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/exchangeAdapter/BaseExchangeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.exchangeAdapter; 2 | 3 | /** 4 | * @author yang 5 | 6 | * @desc 交换器基类 7 | * @date 2019/7/9 8 | */ 9 | public abstract class BaseExchangeAdapter { 10 | 11 | protected static final String status = "ok"; 12 | protected static final String buySign = "buy"; 13 | protected static final String sellSign = "sell"; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/factory/AbsIndicatorFactory.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.factory; 2 | 3 | 4 | import com.quant.common.domain.vo.IndicatorCalParam; 5 | import org.ta4j.core.Indicator; 6 | import org.ta4j.core.TimeSeries; 7 | 8 | /** 9 | * 指标工厂基类 10 | * Created by yang on 2019/5/26. 11 | */ 12 | public abstract class AbsIndicatorFactory { 13 | 14 | protected volatile TimeSeries timeSeries; 15 | 16 | AbsIndicatorFactory(TimeSeries timeSeries) { 17 | this.timeSeries = timeSeries; 18 | } 19 | 20 | /** 21 | * 通过指标名称获取指标 22 | * 23 | * @param indicatorName 24 | * @return 25 | */ 26 | public abstract Indicator getIndicator(String indicatorName); 27 | 28 | public abstract Indicator getIndicator(IndicatorCalParam simpleIndicatorVo); 29 | 30 | public abstract void updateTimeSeries(TimeSeries timeSeries); 31 | } 32 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/ADXIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.indicatorAdapter; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import org.ta4j.core.Indicator; 5 | import org.ta4j.core.TimeSeries; 6 | import org.ta4j.core.indicators.adx.ADXIndicator; 7 | 8 | /** 9 | * 计算adx指标 10 | * Created by yang on 2019/5/26. 11 | */ 12 | public class ADXIndicatorAdapter extends IndicatorAdapter { 13 | 14 | public ADXIndicatorAdapter(TimeSeries timeSeries, int barCount, BuyAndSellIndicatorTo.SourceBean sourceBean) { 15 | super(timeSeries, barCount,sourceBean); 16 | } 17 | 18 | @Override 19 | public Indicator indicatorCalculation() { 20 | return new ADXIndicator(timeSeries, barCount); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/AoIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.quant.core.indicatorAdapter; 3 | 4 | 5 | import org.ta4j.core.Indicator; 6 | import org.ta4j.core.TimeSeries; 7 | import org.ta4j.core.indicators.AwesomeOscillatorIndicator; 8 | import org.ta4j.core.indicators.helpers.MedianPriceIndicator; 9 | 10 | 11 | /** 12 | * cci指标计算 13 | */ 14 | public class AoIndicatorAdapter extends IndicatorAdapter { 15 | 16 | 17 | public AoIndicatorAdapter(TimeSeries timeSeries, Integer barCount, Integer barCount2) { 18 | super(timeSeries, barCount, barCount2); 19 | } 20 | 21 | /** 22 | * 计算并返回Indicator 23 | * 24 | * @return 25 | */ 26 | @Override 27 | public Indicator indicatorCalculation() { 28 | 29 | if (barCount != null && barCount2 == null) { 30 | return new AwesomeOscillatorIndicator(new MedianPriceIndicator(timeSeries), barCount, 34); 31 | } else if (barCount != null) { 32 | return new AwesomeOscillatorIndicator(new MedianPriceIndicator(timeSeries), barCount, barCount2); 33 | } else { 34 | return new AwesomeOscillatorIndicator(timeSeries); 35 | } 36 | 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/CciIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.quant.core.indicatorAdapter; 3 | 4 | 5 | import org.ta4j.core.Indicator; 6 | import org.ta4j.core.TimeSeries; 7 | import org.ta4j.core.indicators.CCIIndicator; 8 | 9 | 10 | /** 11 | * cci指标计算 12 | */ 13 | public class CciIndicatorAdapter extends IndicatorAdapter { 14 | 15 | 16 | public CciIndicatorAdapter(TimeSeries timeSeries, int barCount) { 17 | super(timeSeries, barCount); 18 | } 19 | 20 | /** 21 | * 计算并返回Indicator 22 | * 23 | * @return 24 | */ 25 | @Override 26 | public Indicator indicatorCalculation() { 27 | return new CCIIndicator(timeSeries, barCount); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/EmaIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.quant.core.indicatorAdapter; 3 | 4 | 5 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 6 | import org.ta4j.core.Indicator; 7 | import org.ta4j.core.TimeSeries; 8 | import org.ta4j.core.indicators.EMAIndicator; 9 | import org.ta4j.core.indicators.helpers.ClosePriceIndicator; 10 | 11 | 12 | /** 13 | * ema指标计算 14 | */ 15 | public class EmaIndicatorAdapter extends IndicatorAdapter { 16 | 17 | 18 | public EmaIndicatorAdapter(TimeSeries timeSeries, int barCount, BuyAndSellIndicatorTo.SourceBean sourceBean) { 19 | super(timeSeries, barCount, sourceBean); 20 | } 21 | 22 | /** 23 | * 计算并返回Indicator 24 | * 25 | * @return 26 | */ 27 | @Override 28 | public Indicator indicatorCalculation() { 29 | final Indicator indicator = defaultIndicatorFromSource(); 30 | return new EMAIndicator(indicator, barCount); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/MacdIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.indicatorAdapter; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import org.ta4j.core.Indicator; 5 | import org.ta4j.core.TimeSeries; 6 | import org.ta4j.core.indicators.MACDIndicator; 7 | import org.ta4j.core.indicators.adx.ADXIndicator; 8 | import org.ta4j.core.indicators.helpers.ClosePriceIndicator; 9 | 10 | /** 11 | * 计算madc指标 12 | * Created by yang on 2019/5/26. 13 | */ 14 | public class MacdIndicatorAdapter extends IndicatorAdapter { 15 | 16 | public MacdIndicatorAdapter(TimeSeries timeSeries, Integer barCount, Integer barCount2, BuyAndSellIndicatorTo.SourceBean sourceBean) { 17 | super(timeSeries, barCount, barCount2, sourceBean); 18 | } 19 | 20 | @Override 21 | public Indicator indicatorCalculation() { 22 | final Indicator indicator = defaultIndicatorFromSource(); 23 | if (barCount != null && barCount2 == null) { 24 | return new MACDIndicator(indicator, barCount, 26); 25 | } 26 | if (barCount != null && barCount2 != null) { 27 | return new MACDIndicator(indicator, barCount, barCount2); 28 | } else { 29 | return new MACDIndicator(indicator); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/RsiIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.quant.core.indicatorAdapter; 3 | 4 | 5 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 6 | import org.ta4j.core.Indicator; 7 | import org.ta4j.core.TimeSeries; 8 | import org.ta4j.core.indicators.RSIIndicator; 9 | 10 | 11 | /** 12 | * Rsi指标计算 13 | */ 14 | public class RsiIndicatorAdapter extends IndicatorAdapter { 15 | 16 | 17 | public RsiIndicatorAdapter(TimeSeries timeSeries, int barCount, BuyAndSellIndicatorTo.SourceBean sourceBean) { 18 | super(timeSeries, barCount, sourceBean); 19 | } 20 | 21 | /** 22 | * 计算并返回Indicator 23 | * 24 | * @return 25 | */ 26 | @Override 27 | public Indicator indicatorCalculation() { 28 | final Indicator indicator =defaultIndicatorFromSource(); 29 | return new RSIIndicator(indicator, barCount); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/SmaIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.quant.core.indicatorAdapter; 3 | 4 | 5 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 6 | import org.ta4j.core.Indicator; 7 | import org.ta4j.core.TimeSeries; 8 | import org.ta4j.core.indicators.SMAIndicator; 9 | import org.ta4j.core.indicators.helpers.ClosePriceIndicator; 10 | 11 | 12 | /** 13 | * sma指标计算 14 | */ 15 | public class SmaIndicatorAdapter extends IndicatorAdapter { 16 | 17 | 18 | public SmaIndicatorAdapter(TimeSeries timeSeries, int barCount, BuyAndSellIndicatorTo.SourceBean sourceBean) { 19 | super(timeSeries, barCount,sourceBean); 20 | } 21 | 22 | /** 23 | * 计算并返回Indicator 24 | * 25 | * @return 26 | */ 27 | @Override 28 | public Indicator indicatorCalculation() { 29 | final Indicator indicator =defaultIndicatorFromSource(); 30 | return new SMAIndicator(indicator, barCount); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/StochasticDIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.indicatorAdapter; 2 | 3 | import org.ta4j.core.Indicator; 4 | import org.ta4j.core.TimeSeries; 5 | import org.ta4j.core.indicators.SMAIndicator; 6 | import org.ta4j.core.indicators.StochasticOscillatorDIndicator; 7 | import org.ta4j.core.indicators.StochasticOscillatorKIndicator; 8 | import org.ta4j.core.indicators.StochasticRSIIndicator; 9 | import org.ta4j.core.num.Num; 10 | 11 | /** 12 | * Created by yang on 2019/5/30. 13 | */ 14 | public class StochasticDIndicatorAdapter extends IndicatorAdapter { 15 | 16 | 17 | public StochasticDIndicatorAdapter(TimeSeries timeSeries, int barCount) { 18 | super(timeSeries, barCount); 19 | } 20 | 21 | 22 | @Override 23 | public Indicator indicatorCalculation() { 24 | Indicator stochRSI = new StochasticRSIIndicator(timeSeries, 14); 25 | return new SMAIndicator(stochRSI, barCount); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/StochasticKiIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.indicatorAdapter; 2 | 3 | import org.ta4j.core.Indicator; 4 | import org.ta4j.core.TimeSeries; 5 | import org.ta4j.core.indicators.StochasticOscillatorKIndicator; 6 | 7 | /** 8 | * Created by yang on 2019/5/30. 9 | */ 10 | public class StochasticKiIndicatorAdapter extends IndicatorAdapter { 11 | 12 | 13 | public StochasticKiIndicatorAdapter(TimeSeries timeSeries, int barCount) { 14 | super(timeSeries, barCount); 15 | } 16 | 17 | 18 | @Override 19 | public Indicator indicatorCalculation() { 20 | return new StochasticOscillatorKIndicator(timeSeries, barCount); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/indicatorAdapter/StochasticRsiiIndicatorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.indicatorAdapter; 2 | 3 | import com.quant.common.domain.to.BuyAndSellIndicatorTo; 4 | import org.ta4j.core.Indicator; 5 | import org.ta4j.core.TimeSeries; 6 | import org.ta4j.core.indicators.RSIIndicator; 7 | import org.ta4j.core.indicators.SMAIndicator; 8 | import org.ta4j.core.indicators.StochasticOscillatorKIndicator; 9 | import org.ta4j.core.indicators.StochasticRSIIndicator; 10 | import org.ta4j.core.indicators.helpers.ClosePriceIndicator; 11 | 12 | /** 13 | * Created by yang on 2019/5/30. 14 | */ 15 | public class StochasticRsiiIndicatorAdapter extends IndicatorAdapter { 16 | 17 | 18 | public StochasticRsiiIndicatorAdapter(TimeSeries timeSeries, int barCount, int barCount2, BuyAndSellIndicatorTo.SourceBean sourceBean) { 19 | super(timeSeries, barCount, barCount2,sourceBean); 20 | } 21 | 22 | 23 | @Override 24 | public Indicator indicatorCalculation() { 25 | final Indicator indicator =defaultIndicatorFromSource(); 26 | RSIIndicator r = new RSIIndicator(indicator, barCount); 27 | return new StochasticRSIIndicator(r, barCount2); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/redisMq/OrderIdRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.redisMq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.quant.common.config.RedisUtil; 5 | import com.quant.common.constans.RobotRedisKeyConfig; 6 | import com.quant.core.config.AccountConfig; 7 | import com.quant.common.domain.vo.OrderTaskMessage; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | /** 11 | * @author yang 12 | 13 | * @desc 订单推送到admin 处理 14 | * @date 2019/7/9 15 | */ 16 | @Slf4j 17 | public class OrderIdRedisMqServiceImpl implements RedisMqService { 18 | 19 | private RedisUtil redisUtil; 20 | 21 | private AccountConfig accountConfig; 22 | 23 | private int robotId; 24 | 25 | public OrderIdRedisMqServiceImpl(RedisUtil redisUtil, AccountConfig accountConfig, int robotId) { 26 | this.redisUtil = redisUtil; 27 | this.accountConfig = accountConfig; 28 | this.robotId = robotId; 29 | } 30 | 31 | @Override 32 | public void sendMsg(Object orderId) { 33 | OrderTaskMessage message = new OrderTaskMessage(Long.parseLong(orderId.toString()), this.accountConfig.getAccessKey(), this.accountConfig.getSecretKey(), this.robotId, this.accountConfig.getUserId()); 34 | redisUtil.convertAndSend(RobotRedisKeyConfig.getQueue(), JSON.toJSONString(message)); 35 | log.info("机器人订单信息日志:" + JSON.toJSONString(message)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/redisMq/OrderProfitRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.redisMq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.quant.common.config.RedisUtil; 5 | import com.quant.common.constans.RobotRedisKeyConfig; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | /** 9 | * @author yang 10 | 11 | * @desc 订单盈利推送到admin 12 | * @date 2019/7/9 13 | */ 14 | @Slf4j 15 | public class OrderProfitRedisMqServiceImpl implements RedisMqService { 16 | 17 | private RedisUtil redisUtil; 18 | 19 | 20 | public OrderProfitRedisMqServiceImpl(RedisUtil redisUtil) { 21 | this.redisUtil = redisUtil; 22 | 23 | } 24 | 25 | @Override 26 | public void sendMsg(Object msg) { 27 | redisUtil.convertAndSend(RobotRedisKeyConfig.getOrder_profit(), JSON.toJSONString(msg)); 28 | log.info("机器人盈利信息日志:" + JSON.toJSONString(msg)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/redisMq/RedisMqService.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.redisMq; 2 | 3 | public interface RedisMqService { 4 | 5 | 6 | void sendMsg(Object msg); 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/redisMq/RobotLogsRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.redisMq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.quant.common.config.RedisUtil; 5 | import com.quant.common.constans.RobotRedisKeyConfig; 6 | import com.quant.common.domain.to.RobotRunMessage; 7 | import lombok.extern.slf4j.Slf4j; 8 | 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.util.concurrent.ExecutorService; 12 | import java.util.concurrent.Executors; 13 | 14 | /** 15 | * @author yang 16 | 17 | * @desc 机器人实时日志 推送admin 18 | * @date 2019/7/9 19 | */ 20 | @Slf4j 21 | public class RobotLogsRedisMqServiceImpl implements RedisMqService { 22 | 23 | private ExecutorService executorService = Executors.newFixedThreadPool(3); 24 | 25 | private RedisUtil redisUtil; 26 | private int robotId; 27 | private int userId; 28 | 29 | public RobotLogsRedisMqServiceImpl(RedisUtil redisUtil, int robotId, int userId) { 30 | this.redisUtil = redisUtil; 31 | this.robotId = robotId; 32 | this.userId = userId; 33 | } 34 | 35 | private ThreadLocal simpleDateFormatThreadLocal = new ThreadLocal<>(); 36 | 37 | 38 | /** 39 | * 异步方式提交 40 | * 41 | * @param msg 42 | */ 43 | @Override 44 | public void sendMsg(Object msg) { 45 | log.info("机器人{}日志:{}", robotId, msg.toString()); 46 | executorService.execute(() -> { 47 | if (simpleDateFormatThreadLocal.get() == null) { 48 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 49 | simpleDateFormatThreadLocal.set(simpleDateFormat); 50 | } 51 | try { 52 | RobotRunMessage robotRunMessage = new RobotRunMessage(); 53 | robotRunMessage.setMsg(msg.toString()); 54 | robotRunMessage.setRobotId(robotId); 55 | robotRunMessage.setDate(simpleDateFormatThreadLocal.get().format(new Date())); 56 | robotRunMessage.setUserId(userId); 57 | redisUtil.convertAndSend(RobotRedisKeyConfig.getRobot_msg_queue(), JSON.toJSONString(robotRunMessage)); 58 | } catch (Exception e) { 59 | e.printStackTrace(); 60 | } 61 | }); 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/strategy/StrategyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.core.strategy; 25 | 26 | /** 27 | * @author yang 28 | 29 | * @desc StrategyException 30 | * @date 2019/7/9 31 | */ 32 | public final class StrategyException extends Exception { 33 | 34 | private static final long serialVersionUID = -5066890753686004758L; 35 | 36 | /** 37 | * Constructor builds exception with error message. 38 | * 39 | * @param msg the error message. 40 | */ 41 | public StrategyException(String msg) { 42 | super(msg); 43 | } 44 | 45 | /** 46 | * Constructor builds exception from original throwable. 47 | * 48 | * @param e the original exception. 49 | */ 50 | public StrategyException(Throwable e) { 51 | super(e); 52 | } 53 | 54 | /** 55 | * Constructor builds exception with error message and original throwable. 56 | * 57 | * @param msg the error message. 58 | * @param e the original exception. 59 | */ 60 | public StrategyException(String msg, Throwable e) { 61 | super(msg, e); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/strategy/TradingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.core.strategy; 25 | 26 | 27 | import com.quant.core.builder.StrategyBuilder; 28 | import com.quant.core.config.AccountConfig; 29 | import com.quant.core.config.MarketConfig; 30 | import com.quant.core.trading.TradingApi; 31 | import com.quant.core.config.StrategyConfig; 32 | 33 | /** 34 | * @author yang 35 | * @desc TradingStrategy 36 | * @date 2019/7/9 37 | */ 38 | public interface TradingStrategy { 39 | 40 | 41 | // void init(TradingApi tradingApi, MarketConfig market, StrategyConfig config, AccountConfig accountConfig); 42 | 43 | /** 44 | * 初始化数据 45 | * @param builder 46 | */ 47 | void init(StrategyBuilder builder); 48 | 49 | /** 50 | * 执行策略 51 | * @throws StrategyException 52 | */ 53 | void execute() throws StrategyException; 54 | } 55 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/strategy/handle/HuobiNotLimitBuyPriceHandle.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.strategy.handle; 2 | 3 | import com.quant.common.domain.vo.BaseInfoEntity; 4 | import com.quant.common.enums.HBOrderType; 5 | import com.quant.common.enums.PirceType; 6 | import com.quant.common.enums.SellType; 7 | import com.quant.core.config.AccountConfig; 8 | import com.quant.core.config.MarketConfig; 9 | import com.quant.core.config.StrategyConfig; 10 | import com.quant.core.trading.TradingApi; 11 | import lombok.extern.slf4j.Slf4j; 12 | 13 | import java.math.BigDecimal; 14 | import java.math.RoundingMode; 15 | 16 | /** 17 | * 火币市价 18 | * Created by yang on 2019/8/23. 19 | */ 20 | @Slf4j 21 | public class HuobiNotLimitBuyPriceHandle extends StrategyHandle { 22 | 23 | 24 | public HuobiNotLimitBuyPriceHandle(StrategyHandle handle) { 25 | super(handle); 26 | } 27 | 28 | @Override 29 | public HandleResult strategyRequest(TradingApi tradingApi, 30 | MarketConfig marketConfig, 31 | StrategyConfig config, 32 | AccountConfig accountConfig, 33 | int pricePrecision, 34 | int amountPrecision, 35 | BigDecimal baseBalance) { 36 | if (getHandle() == null) { 37 | return null; 38 | } 39 | final BaseInfoEntity baseInfo = config.getIndicatorStrategy().getBaseInfo(); 40 | if (baseInfo.getIsLimitPrice() == PirceType.notLimit.getType()) { 41 | //市价卖出 价格直接填0 计算交易额度 42 | BigDecimal buyAmount = BigDecimal.ZERO; 43 | if (baseInfo.getIsAllSell() == SellType.sellAll.getType()) { 44 | //如果市价全部卖出 卖出为币 卖出所有的币 就是价格就是交易额度 quotaBalance; 45 | buyAmount = baseBalance.setScale(amountPrecision, RoundingMode.DOWN); 46 | } else { 47 | //不是全部购买 自定义交易额 购买 48 | buyAmount = buyAmount.add(baseInfo.getSellAmount()).setScale(amountPrecision, RoundingMode.DOWN); 49 | } 50 | HBOrderType hbOrderType = HBOrderType.BUY_MARKET; 51 | //非限价模式的时候 价格不需要填写 交易所会根据最优价格去计算价格 52 | return new HandleResult(hbOrderType, BigDecimal.ZERO, buyAmount); 53 | } else { 54 | 55 | return getHandle().strategyRequest(tradingApi, 56 | marketConfig, 57 | config, 58 | accountConfig, 59 | pricePrecision, 60 | amountPrecision, 61 | baseBalance); 62 | 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/strategy/handle/StrategyHandle.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.strategy.handle; 2 | 3 | import com.quant.common.domain.vo.BaseInfoEntity; 4 | import com.quant.common.enums.HBOrderType; 5 | import com.quant.core.config.AccountConfig; 6 | import com.quant.core.config.MarketConfig; 7 | import com.quant.core.config.StrategyConfig; 8 | import com.quant.core.trading.TradingApi; 9 | import lombok.AllArgsConstructor; 10 | import lombok.Data; 11 | 12 | import java.math.BigDecimal; 13 | 14 | /** 15 | * StrategyHandle 16 | * Created by yang on 2019/8/23. 17 | */ 18 | public abstract class StrategyHandle { 19 | 20 | 21 | public StrategyHandle(StrategyHandle handle) { 22 | this.handle = handle; 23 | 24 | } 25 | 26 | private StrategyHandle handle; 27 | 28 | 29 | public abstract HandleResult strategyRequest(TradingApi tradingApi, 30 | MarketConfig market, 31 | StrategyConfig config, 32 | AccountConfig accountConfig, 33 | int pricePrecision, 34 | int amountPrecision, 35 | BigDecimal baseBalance); 36 | 37 | 38 | public StrategyHandle getHandle() { 39 | return handle; 40 | } 41 | 42 | public void setHandle(StrategyHandle handle) { 43 | this.handle = handle; 44 | } 45 | 46 | @AllArgsConstructor 47 | @Data 48 | public static class HandleResult { 49 | 50 | /** 51 | * 订单类型 52 | */ 53 | HBOrderType hbOrderType; 54 | 55 | /** 56 | * 计算后的价格 只针对限价 市价不需要传递价格 57 | */ 58 | BigDecimal Price; 59 | 60 | BigDecimal Amount; 61 | 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/strategy/impl/StrategyDelegate.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.strategy.impl; 2 | 3 | import com.quant.common.enums.HBOrderType; 4 | import com.quant.common.enums.OrderType; 5 | import com.quant.core.trading.TradingApi; 6 | 7 | import java.math.BigDecimal; 8 | 9 | /** 10 | * StrategyDelegate 11 | * Created by yang on 2019/8/23. 12 | */ 13 | public interface StrategyDelegate { 14 | 15 | /** 16 | * 计算盈利 17 | */ 18 | void CalculateProfit(); 19 | 20 | /** 21 | * 下单 22 | * 23 | * @param tradingApi 24 | * @param sellAmount 25 | * @param sellPrice 26 | * @param HBOrderType 27 | * @param type 28 | */ 29 | void orderPlace(TradingApi tradingApi, BigDecimal sellAmount, BigDecimal sellPrice, HBOrderType HBOrderType, OrderType type); 30 | } 31 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/trading/BalanceInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2015 Gareth Jon Lynch 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | * this software and associated documentation files (the "Software"), to deal in 8 | * the Software without restriction, including without limitation the rights to 9 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | * the Software, and to permit persons to whom the Software is furnished to do so, 11 | * subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | package com.quant.core.trading; 25 | 26 | import java.math.BigDecimal; 27 | import java.util.Map; 28 | 29 | /** 30 | * @author yang 31 | 32 | * @desc BalanceInfo 33 | * @date 2019/7/9 34 | */ 35 | public interface BalanceInfo { 36 | 37 | 38 | /** 39 | * 获取可用余额 40 | * @return 41 | */ 42 | Map getBalancesAvailable(); 43 | 44 | 45 | Map getBalancesOnHold(); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/quant/core/trading/impl/HuoBiOpenOrderImpl.java: -------------------------------------------------------------------------------- 1 | package com.quant.core.trading.impl; 2 | 3 | import com.quant.common.domain.response.OrdersDetail; 4 | import com.quant.core.trading.OpenOrder; 5 | import com.quant.common.utils.DateUtils; 6 | 7 | import java.math.BigDecimal; 8 | import java.util.Date; 9 | 10 | public class HuoBiOpenOrderImpl implements OpenOrder { 11 | 12 | private OrdersDetail ordersDetail; 13 | 14 | public HuoBiOpenOrderImpl(OrdersDetail ordersDetail) { 15 | this.ordersDetail = ordersDetail; 16 | } 17 | 18 | @Override 19 | public String getId() { 20 | return String.valueOf(ordersDetail.getId()); 21 | } 22 | 23 | @Override 24 | public Date getCreationDate() { 25 | 26 | return DateUtils.parseTimeMillisToDate(ordersDetail.getCreatedAt()); 27 | } 28 | 29 | @Override 30 | public String getMarketId() { 31 | return ordersDetail.getSymbol(); 32 | } 33 | 34 | @Override 35 | public String getType() { 36 | return ordersDetail.getType(); 37 | } 38 | 39 | @Override 40 | public BigDecimal getPrice() { 41 | return new BigDecimal(ordersDetail.getPrice()); 42 | } 43 | 44 | @Override 45 | public String getFilledAmount() { 46 | return ordersDetail.getFieldAmount(); 47 | } 48 | 49 | @Override 50 | public String getFilledCashAmount() { 51 | return ordersDetail.getFieldCashAmount(); 52 | } 53 | 54 | @Override 55 | public String getFilledFees() { 56 | return ordersDetail.getFieldFees(); 57 | } 58 | 59 | @Override 60 | public String getSource() { 61 | return ordersDetail.getSource(); 62 | } 63 | 64 | @Override 65 | public String getState() { 66 | return ordersDetail.getState(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /qt-register/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qt-parent 7 | com.quant 8 | 0.0.1-SNAPSHOT 9 | ../pom.xml 10 | 11 | 4.0.0 12 | 13 | qt-register 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-server 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-maven-plugin 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /qt-register/src/main/java/com/quant/center/AppRegister.java: -------------------------------------------------------------------------------- 1 | package com.quant.center; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaServer 9 | public class AppRegister { 10 | 11 | 12 | /** 13 | * 注册中心 可以移至 admin 为了方便管理 还是单独使用、 14 | * 注册中心只是为了注册节点 获取节点的ip 无其他意义 15 | * @param args 16 | */ 17 | public static void main(String[] args) { 18 | SpringApplication.run(AppRegister.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /qt-register/src/main/java/com/quant/center/te.java: -------------------------------------------------------------------------------- 1 | package com.quant.center; 2 | 3 | public class te { 4 | } 5 | -------------------------------------------------------------------------------- /qt-register/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: ${EUREKA_PORT:8761} 3 | 4 | eureka: 5 | client: 6 | registerWithEureka: false 7 | fetchRegistry: false 8 | serviceUrl: 9 | defaultZone: http://${EUREKA_ZONE_HOST:localhost}:${EUREKA_ZONE_PORT:8761}/eureka/ 10 | 11 | spring: 12 | application: 13 | name: eureka-server 14 | -------------------------------------------------------------------------------- /qt-register/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: ${EUREKA_PORT:8762} 3 | address: 0.0.0.0 4 | eureka: 5 | client: 6 | registerWithEureka: false 7 | fetchRegistry: false 8 | serviceUrl: 9 | defaultZone: http://${EUREKA_ZONE_HOST:0.0.0.0}:${EUREKA_ZONE_PORT:8762}/eureka/ 10 | 11 | spring: 12 | application: 13 | name: eureka-server 14 | -------------------------------------------------------------------------------- /qt-register/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | -------------------------------------------------------------------------------- /qt-register/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | __ _ _ _ __ 2 | / / | | (_) | | \ \ 3 | / / __ _ _ _ __ _ _ __ | |_ ______ _ __ ___ __ _ _ ___| |_ ___ _ _\ \ 4 | < < / _` | | | |/ _` | '_ \| __|______| '__/ _ \/ _` | / __| __/ _ | '__> > 5 | \ | (_| | |_| | (_| | | | | |_ | | | __| (_| | \__ | || __| | / / 6 | \_\__, |\__,_|\__,_|_| |_|\__| |_| \___|\__, |_|___/\__\___|_|/_/ 7 | | | __/ | 8 | |_| |___/ --------------------------------------------------------------------------------