├── .gitignore ├── README.md ├── pom.xml ├── qt-admin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── qklx │ │ │ └── qt │ │ │ └── admin │ │ │ ├── QtAdminApplication.java │ │ │ ├── component │ │ │ ├── OrderIdReceiver.java │ │ │ ├── ProfitReceiver.java │ │ │ └── RobotMsgReceiver.java │ │ │ ├── config │ │ │ ├── AsyncConfig.java │ │ │ ├── GlobalCorsConfig.java │ │ │ ├── MybatisPlusConfig.java │ │ │ ├── SubscriberConfig.java │ │ │ └── WebSocketConfig.java │ │ │ ├── controller │ │ │ ├── AccountController.java │ │ │ ├── BalanceController.java │ │ │ ├── BaseController.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 │ │ │ ├── entity │ │ │ ├── Account.java │ │ │ ├── Balance.java │ │ │ ├── OrderProfit.java │ │ │ ├── Orders.java │ │ │ ├── Robot.java │ │ │ ├── Strategy.java │ │ │ ├── Symbol.java │ │ │ └── User.java │ │ │ ├── model │ │ │ └── RobotListModel.java │ │ │ ├── rest │ │ │ ├── RobotClientService.java │ │ │ └── impl │ │ │ │ └── RobotClientServiceImpl.java │ │ │ ├── service │ │ │ ├── AccountService.java │ │ │ ├── BalanceService.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 │ │ │ ├── BalanceTask.java │ │ │ ├── RobotCheckTask.java │ │ │ └── SymbolTask.java │ │ │ └── utils │ │ │ └── MysqlGenerator.java │ └── resources │ │ ├── application-dev.yml │ │ ├── application-prod.yml │ │ ├── application.yml │ │ ├── logback-spring.xml │ │ └── mapper │ │ ├── AccountMapper.xml │ │ ├── BalanceMapper.xml │ │ ├── OrderProfitMapper.xml │ │ ├── OrdersMapper.xml │ │ ├── RobotMapper.xml │ │ ├── StrategyMapper.xml │ │ ├── SymbolMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── qklx │ └── qt │ └── admin │ └── QtParentApplicationTests.java ├── qt-client ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── qklx │ │ │ └── client │ │ │ ├── AppClient.java │ │ │ ├── Task │ │ │ └── RobotOperate.java │ │ │ ├── config │ │ │ └── ThreadPool.java │ │ │ ├── controller │ │ │ └── BotController.java │ │ │ └── service │ │ │ ├── RobotService.java │ │ │ └── impl │ │ │ └── RobotServiceImpl.java │ └── resources │ │ ├── application-dev.yml │ │ ├── application-prod.yml │ │ ├── application.yml │ │ └── logback-spring.xml │ └── test │ └── java │ └── Test.java ├── qt-common ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── qklx │ │ └── qt │ │ └── common │ │ ├── config │ │ ├── JsonConfig.java │ │ ├── RedisConfig.java │ │ ├── RedisUtil.java │ │ ├── RestTemplateConfig.java │ │ └── VpnProxyConfig.java │ │ ├── constans │ │ └── RobotRedisKeyConfig.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 │ └── qklx │ └── qt │ └── core │ ├── MainTest.java │ ├── api │ ├── ApiClient.java │ ├── ApiException.java │ └── ApiResult.java │ ├── config │ ├── AccountConfig.java │ ├── KlineConfig.java │ ├── MarketConfig.java │ ├── StrategyConfig.java │ └── imp │ │ ├── HuoBiAccountConfigImpl.java │ │ ├── HuoBiKlineConfigImpl.java │ │ └── HuoBiMarketConfigImpl.java │ ├── domain │ ├── Account.java │ ├── ArConfig.java │ ├── Market.java │ ├── MineConfig.java │ └── Option.java │ ├── enums │ ├── AType.java │ ├── OrderType.java │ ├── RobotState.java │ ├── Status.java │ └── TraceType.java │ ├── exchangeAdapter │ ├── BaseExchangeAdapter.java │ └── HuobiExchangeAdapter.java │ ├── mq │ ├── OrderIdRedisMqServiceImpl.java │ ├── OrderProfitRedisMqServiceImpl.java │ ├── RedisMqService.java │ └── RobotLogsRedisMqServiceImpl.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 │ ├── strategy │ ├── AbstractStrategy.java │ ├── StrategyException.java │ ├── TradingStrategy.java │ └── impl │ │ ├── ArStrategyImpl.java │ │ └── HuoBiStrategyImpl.java │ ├── to │ └── RobotRunMessage.java │ ├── trading │ ├── BalanceInfo.java │ ├── ExchangeNetworkException.java │ ├── MarketOrder.java │ ├── OpenOrder.java │ ├── OrderType.java │ ├── Ticker.java │ ├── TradingApi.java │ ├── TradingApiException.java │ └── impl │ │ └── HuoBiOpenOrderImpl.java │ └── vo │ ├── AccountVo.java │ ├── OrderTaskMessage.java │ ├── ProfitMessage.java │ ├── RobotStrategyVo.java │ ├── RobotVo.java │ └── StrategyVo.java ├── qt-register ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── qklx │ │ └── center │ │ └── AppRegister.java │ └── resources │ ├── application-dev.yml │ ├── application-prod.yml │ └── application.yml └── temp └── src └── main ├── java └── com │ └── qklx │ └── temp │ ├── controller │ ├── AccountController.java │ ├── BalanceController.java │ ├── LogsController.java │ ├── OrderController.java │ ├── OrdersController.java │ ├── RobotController.java │ ├── StrategyController.java │ ├── SymbolController.java │ └── UserController.java │ ├── dao │ ├── AccountMapper.java │ ├── BalanceMapper.java │ ├── LogsMapper.java │ ├── OrderMapper.java │ ├── OrdersMapper.java │ ├── RobotMapper.java │ ├── StrategyMapper.java │ ├── SymbolMapper.java │ └── UserMapper.java │ ├── entity │ ├── Account.java │ ├── Balance.java │ ├── Logs.java │ ├── Order.java │ ├── Orders.java │ ├── Robot.java │ ├── Strategy.java │ ├── Symbol.java │ └── User.java │ └── service │ ├── AccountService.java │ ├── BalanceService.java │ ├── LogsService.java │ ├── OrderService.java │ ├── OrdersService.java │ ├── RobotService.java │ ├── StrategyService.java │ ├── SymbolService.java │ ├── UserService.java │ └── impl │ ├── AccountServiceImpl.java │ ├── BalanceServiceImpl.java │ ├── LogsServiceImpl.java │ ├── OrderServiceImpl.java │ ├── OrdersServiceImpl.java │ ├── RobotServiceImpl.java │ ├── StrategyServiceImpl.java │ ├── SymbolServiceImpl.java │ └── UserServiceImpl.java └── resources └── mapper ├── AccountMapper.xml ├── BalanceMapper.xml ├── LogsMapper.xml ├── OrderMapper.xml ├── OrdersMapper.xml ├── RobotMapper.xml ├── StrategyMapper.xml ├── SymbolMapper.xml └── UserMapper.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 | #qt量化交易java版本目前只支持火币的所有币币交易 2 | #qt-admin 量化控制中心 qt-client 机器人节点 支持动态添加节点 3 | ![image](https://github.com/tokenIsme/images/blob/master/1557888795(1).jpg) 4 | 5 | ![image](https://github.com/tokenIsme/images/blob/master/1557888642(1).jpg) 6 | 7 | ![image](https://github.com/tokenIsme/images/blob/master/1557888658(1).jpg) 8 | 9 | ![image](https://github.com/tokenIsme/images/blob/master/1557888693(1).jpg) 10 | 11 | ![image](https://github.com/tokenIsme/images/blob/master/1557888732(1).jpg) 12 | 13 | 14 | ![image](https://github.com/tokenIsme/images/blob/master/1557888747(1).jpg) 15 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/QtAdminApplication.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | 10 | 11 | @SpringBootApplication 12 | @MapperScan("com.qklx.qt.admin.dao") 13 | @EnableEurekaClient 14 | @ComponentScan({"com.qklx.qt.common", "com.qklx.qt.admin"}) 15 | @EnableScheduling 16 | public class QtAdminApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(QtAdminApplication.class, args); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/component/ProfitReceiver.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.admin.entity.OrderProfit; 7 | import com.qklx.qt.core.vo.ProfitMessage; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | import static com.qklx.qt.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/qklx/qt/admin/component/RobotMsgReceiver.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.component; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.qklx.qt.core.to.RobotRunMessage; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.messaging.simp.SimpMessagingTemplate; 7 | 8 | import static com.qklx.qt.common.utils.JsonFormate.parseJsonToString; 9 | 10 | /*** 11 | * 消息接收者(订阅者) 需要注入到springboot中 12 | */ 13 | @Slf4j 14 | public class RobotMsgReceiver { 15 | 16 | private SimpMessagingTemplate simpMessageSendingOperations;//消息发送模板 17 | 18 | public RobotMsgReceiver(SimpMessagingTemplate simpMessageSendingOperations) { 19 | this.simpMessageSendingOperations = simpMessageSendingOperations; 20 | } 21 | 22 | /** 23 | * 收到通道的消息之后执行的方法 24 | * 25 | * @param message 26 | */ 27 | public void receiveMessage(String message) { 28 | try { 29 | //这里是收到通道的消息之后执行的方法?? 30 | RobotRunMessage msg = JSON.parseObject(parseJsonToString(message), RobotRunMessage.class); 31 | simpMessageSendingOperations.convertAndSend("/topic/" + msg.getRobotId(), parseJsonToString(message)); 32 | } catch (NumberFormatException e) { 33 | e.printStackTrace(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/config/AsyncConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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 = 5; 15 | private final static int maxPoolSize = 10; 16 | private final static int queueCapacity = 10; 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/qklx/qt/admin/config/GlobalCorsConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/admin/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.admin.dao.*.mapper*") 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/qklx/qt/admin/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/admin/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | 4 | import com.qklx.qt.admin.service.AccountService; 5 | import com.qklx.qt.core.vo.AccountVo; 6 | import com.qklx.qt.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/qklx/qt/admin/controller/BalanceController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | import com.qklx.qt.admin.service.BalanceService; 4 | import com.qklx.qt.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/qklx/qt/admin/controller/BaseController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/admin/controller/NodeController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.core.enums.Status; 9 | import com.qklx.qt.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 | for (Application application : apps) { 35 | if (application.getName().toLowerCase().equals(clientStr)) { 36 | try { 37 | List instanceInfos = new CopyOnWriteArrayList<>(application.getInstances()); 38 | for (InstanceInfo instanceInfo : instanceInfos) { 39 | JSONObject obj = new JSONObject(); 40 | obj.put("ipo", instanceInfo.getIPAddr() + ":" + instanceInfo.getPort()); 41 | list.add(obj); 42 | } 43 | } catch (Exception ex) { 44 | ex.printStackTrace(); 45 | return new ApiResult(Status.ERROR); 46 | } 47 | } 48 | 49 | } 50 | return new ApiResult(Status.SUCCESS, list); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | 4 | import com.qklx.qt.admin.service.OrdersService; 5 | import com.qklx.qt.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 | import javax.validation.constraints.NotBlank; 16 | 17 | /** 18 | *

19 | * 前端控制器 20 | *

21 | * 22 | * @author yang 23 | * @since 2019-04-22 24 | */ 25 | @RestController 26 | @RequestMapping("/order") 27 | public class OrderController extends AbstractController { 28 | 29 | @Autowired 30 | private OrdersService ordersService; 31 | 32 | /** 33 | * 订单列表 34 | * 35 | * @return 36 | */ 37 | @GetMapping("/list") 38 | public ApiResult list(int rid, int page, int limit) { 39 | return ordersService.getOrderByRobotId(rid,page,limit); 40 | } 41 | 42 | @Override 43 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 44 | return null; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/controller/OrderProfitController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | 4 | import com.qklx.qt.admin.service.OrderProfitService; 5 | import com.qklx.qt.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/qklx/qt/admin/controller/RobotController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | 4 | import com.qklx.qt.admin.service.RobotService; 5 | import com.qklx.qt.core.api.ApiResult; 6 | import com.qklx.qt.core.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("/addRobot") 31 | public ApiResult addRobot(@RequestBody RobotVo vo, HttpServletRequest request) { 32 | @NotBlank 33 | String uid = getUid(request); 34 | vo.setUserId(uid); 35 | return robotService.addRobot(vo); 36 | } 37 | 38 | /** 39 | * 获取我的机器人 40 | * 41 | * @return 42 | */ 43 | @GetMapping("/list") 44 | public ApiResult list(HttpServletRequest request) { 45 | @NotBlank 46 | String uid = getUid(request); 47 | return robotService.list(uid); 48 | } 49 | /** 50 | * 删除我的机器人 51 | * 52 | * @return 53 | */ 54 | @GetMapping("/deleteRobot") 55 | public ApiResult deleteRobot(HttpServletRequest request,int id) { 56 | @NotBlank 57 | String uid = getUid(request); 58 | return robotService.deleteRobot(uid,id); 59 | } 60 | 61 | 62 | /** 63 | * 启动或者关闭机器人 64 | * 65 | * @param id 机器人编号 66 | * @return 67 | */ 68 | @GetMapping("/operatingRobot") 69 | public ApiResult operatingRobot(@NotNull Integer id, @NotBlank Integer state, HttpServletRequest request) { 70 | @NotBlank 71 | String uid = getUid(request); 72 | return robotService.operatingRobot(id, state, uid); 73 | } 74 | 75 | @Override 76 | protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { 77 | return null; 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/controller/StrategyController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | import com.qklx.qt.admin.service.StrategyService; 4 | import com.qklx.qt.core.api.ApiResult; 5 | import com.qklx.qt.core.enums.Status; 6 | import com.qklx.qt.core.vo.StrategyVo; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | @RestController 13 | @RequestMapping("/strategy") 14 | public class StrategyController extends BaseController{ 15 | @Autowired 16 | StrategyService strategyService; 17 | 18 | /** 19 | * 添加一个策略 20 | * 21 | * @return 22 | */ 23 | @PostMapping("/addOrUpdateStrategy") 24 | public ApiResult addOrUpdateStrategy(@RequestBody StrategyVo strategyVo, HttpServletRequest httpRequest) { 25 | String uid = getUid(httpRequest); 26 | if (uid == null) { 27 | return new ApiResult(Status.Login_out); 28 | } else { 29 | return strategyService.addOrUpdateStrategy(strategyVo, uid); 30 | } 31 | } 32 | 33 | /** 34 | * 获取我的策略列表 35 | * 36 | * @return 37 | */ 38 | @GetMapping("/strategyList") 39 | public ApiResult strategyList(HttpServletRequest httpRequest) { 40 | String uid = getUid(httpRequest); 41 | if (uid == null) { 42 | return new ApiResult(Status.Login_out); 43 | } else { 44 | return strategyService.strategyList(uid); 45 | } 46 | } 47 | 48 | /** 49 | * 获取我的策略列表 50 | * 51 | * @return 52 | */ 53 | @GetMapping("/simpleStrategyList") 54 | public ApiResult simpleStrategyList(HttpServletRequest httpRequest) { 55 | String uid = getUid(httpRequest); 56 | if (uid == null) { 57 | return new ApiResult(Status.Login_out); 58 | } else { 59 | return strategyService.simpleStrategyList(uid); 60 | } 61 | } 62 | 63 | 64 | @GetMapping("/getStrategyById") 65 | public ApiResult getStrategyById(HttpServletRequest httpRequest,int id) { 66 | String uid = getUid(httpRequest); 67 | if (uid == null) { 68 | return new ApiResult(Status.Login_out); 69 | } else { 70 | return strategyService.getStrategyById(id,uid); 71 | } 72 | } 73 | 74 | @GetMapping("/deleteStrategy") 75 | public ApiResult deleteStrategy(HttpServletRequest httpRequest,int id) { 76 | String uid = getUid(httpRequest); 77 | if (uid == null) { 78 | return new ApiResult(Status.Login_out); 79 | } else { 80 | return strategyService.deleteStrategy(id,uid); 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/controller/SymbolController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | import com.qklx.qt.admin.service.SymbolService; 4 | import com.qklx.qt.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/qklx/qt/admin/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.controller; 2 | 3 | 4 | import com.qklx.qt.admin.entity.User; 5 | import com.qklx.qt.admin.service.UserService; 6 | import com.qklx.qt.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 | @Override 65 | protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { 66 | logger.info("method====" + httpServletRequest.getMethod()); 67 | return null; 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/dao/AccountMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/BalanceMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/OrderProfitMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/OrdersMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/RobotMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.model.RobotListModel; 5 | import com.qklx.qt.admin.entity.Robot; 6 | import org.apache.ibatis.annotations.Mapper; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author yang 16 | * @since 2019-04-17 17 | */ 18 | 19 | public interface RobotMapper extends BaseMapper { 20 | 21 | 22 | List getRobotList(String uid); 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/dao/StrategyMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/SymbolMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.baomidou.mybatisplus.mapper.BaseMapper; 4 | import com.qklx.qt.admin.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/qklx/qt/admin/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.dao; 2 | 3 | import com.qklx.qt.admin.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/qklx/qt/admin/entity/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.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-admin/src/main/java/com/qklx/qt/admin/model/RobotListModel.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.model; 2 | 3 | import com.baomidou.mybatisplus.activerecord.Model; 4 | import com.baomidou.mybatisplus.annotations.TableField; 5 | import com.baomidou.mybatisplus.annotations.TableId; 6 | import com.baomidou.mybatisplus.enums.IdType; 7 | import lombok.Data; 8 | 9 | import java.io.Serializable; 10 | import java.util.Date; 11 | 12 | @Data 13 | public class RobotListModel { 14 | private static final long serialVersionUID = 1L; 15 | 16 | 17 | private Integer id; 18 | 19 | private String robotName; 20 | 21 | private String symbol; 22 | 23 | private String userId; 24 | 25 | private Integer strategyId; 26 | 27 | private String clientAddress; 28 | 29 | private Date createTime; 30 | 31 | private Integer isDelete; 32 | 33 | private Integer isRun; 34 | 35 | private String strategyName; 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/rest/RobotClientService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.rest; 2 | 3 | import com.qklx.qt.core.api.ApiResult; 4 | import com.qklx.qt.core.vo.RobotStrategyVo; 5 | 6 | public interface RobotClientService { 7 | 8 | ApiResult operatingRobot(String url, RobotStrategyVo vo); 9 | } 10 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/rest/impl/RobotClientServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.rest.impl; 2 | 3 | import com.qklx.qt.admin.rest.RobotClientService; 4 | import com.qklx.qt.core.api.ApiResult; 5 | import com.qklx.qt.core.vo.RobotStrategyVo; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | /** 11 | * 调用机器人节点服务器 传递数据给机器人 12 | */ 13 | @Service 14 | public class RobotClientServiceImpl implements RobotClientService { 15 | 16 | @Autowired 17 | RestTemplate restTemplate; 18 | 19 | /** 20 | * 发送信息到client端 21 | * 22 | * @param url 23 | * @param vo 24 | * @return 25 | */ 26 | @Override 27 | public ApiResult operatingRobot(String url, RobotStrategyVo vo) { 28 | return restTemplate.postForEntity(url, vo, ApiResult.class).getBody(); 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.qklx.qt.admin.entity.Account; 4 | import com.baomidou.mybatisplus.service.IService; 5 | import com.qklx.qt.core.vo.AccountVo; 6 | import com.qklx.qt.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/qklx/qt/admin/service/BalanceService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.Balance; 5 | import com.qklx.qt.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/qklx/qt/admin/service/OrderProfitService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.OrderProfit; 5 | import com.qklx.qt.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/qklx/qt/admin/service/OrdersService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.Orders; 5 | import com.qklx.qt.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/qklx/qt/admin/service/RobotService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.Robot; 5 | import com.qklx.qt.core.api.ApiResult; 6 | import com.qklx.qt.core.vo.RobotVo; 7 | 8 | /** 9 | *

10 | * 服务类 11 | *

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

10 | * 服务类 11 | *

12 | * 13 | * @author yang 14 | * @since 2019-04-15 15 | */ 16 | public interface StrategyService extends IService { 17 | 18 | ApiResult addOrUpdateStrategy(StrategyVo strategyVo, String uid); 19 | 20 | ApiResult strategyList(String uid); 21 | 22 | ApiResult simpleStrategyList(String uid); 23 | 24 | ApiResult getStrategyById(int id, String uid); 25 | 26 | ApiResult deleteStrategy(int id, String uid); 27 | } 28 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/service/SymbolService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.Symbol; 5 | import com.qklx.qt.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/qklx/qt/admin/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service; 2 | 3 | import com.baomidou.mybatisplus.service.IService; 4 | import com.qklx.qt.admin.entity.User; 5 | import com.qklx.qt.core.api.ApiResult; 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author yang 13 | * @since 2019-04-08 14 | */ 15 | public interface UserService extends IService { 16 | 17 | /** 18 | * simple登录 19 | * @param params 20 | * @return 21 | */ 22 | ApiResult login(User params); 23 | 24 | 25 | ApiResult info(String token); 26 | 27 | ApiResult logout(); 28 | } 29 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/service/impl/BalanceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.admin.dao.BalanceMapper; 7 | import com.qklx.qt.admin.entity.Balance; 8 | import com.qklx.qt.admin.service.BalanceService; 9 | import com.qklx.qt.core.enums.Status; 10 | import com.qklx.qt.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/qklx/qt/admin/service/impl/OrderProfitServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.admin.dao.OrderProfitMapper; 8 | import com.qklx.qt.admin.entity.OrderProfit; 9 | import com.qklx.qt.admin.service.OrderProfitService; 10 | import com.qklx.qt.core.api.ApiResult; 11 | import com.qklx.qt.core.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/qklx/qt/admin/service/impl/OrdersServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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.qklx.qt.admin.dao.OrdersMapper; 8 | import com.qklx.qt.admin.entity.Orders; 9 | import com.qklx.qt.admin.service.OrdersService; 10 | import com.qklx.qt.core.api.ApiResult; 11 | import com.qklx.qt.core.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/qklx/qt/admin/service/impl/SymbolServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 4 | import com.qklx.qt.admin.dao.SymbolMapper; 5 | import com.qklx.qt.admin.entity.Symbol; 6 | import com.qklx.qt.admin.service.SymbolService; 7 | import com.qklx.qt.core.enums.Status; 8 | import com.qklx.qt.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/qklx/qt/admin/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.service.impl; 2 | 3 | import com.baomidou.mybatisplus.mapper.EntityWrapper; 4 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 5 | import com.qklx.qt.admin.dao.UserMapper; 6 | import com.qklx.qt.admin.entity.User; 7 | import com.qklx.qt.admin.service.UserService; 8 | import com.qklx.qt.core.enums.Status; 9 | import com.qklx.qt.core.api.ApiResult; 10 | import org.springframework.stereotype.Service; 11 | 12 | /** 13 | *

14 | * 服务实现类 15 | *

16 | * 17 | * @author yang 18 | * @since 2019-04-08 19 | */ 20 | @Service 21 | public class UserServiceImpl extends ServiceImpl implements UserService { 22 | 23 | @Override 24 | public ApiResult login(User params) { 25 | EntityWrapper wrapper = new EntityWrapper<>(); 26 | User user = new User(); 27 | wrapper.eq("username", params.getUsername()); 28 | wrapper.eq("password", params.getPassword()); 29 | wrapper.eq("is_delete", 0); 30 | User u = user.selectOne(wrapper); 31 | if (u != null) { 32 | return new ApiResult(Status.SUCCESS, u.getId()); 33 | } else { 34 | return new ApiResult(Status.USER_NOT_EXIST); 35 | } 36 | 37 | } 38 | 39 | @Override 40 | public ApiResult info(String token) { 41 | EntityWrapper wrapper = new EntityWrapper<>(); 42 | User user = new User(); 43 | wrapper.eq("id", token); 44 | wrapper.eq("is_delete", 0); 45 | User u = user.selectOne(wrapper); 46 | if (u != null) { 47 | u.setPassword(null); 48 | return new ApiResult(Status.SUCCESS, u); 49 | } else { 50 | return new ApiResult(Status.USER_NOT_EXIST); 51 | } 52 | 53 | } 54 | 55 | @Override 56 | public ApiResult logout() { 57 | return new ApiResult(Status.SUCCESS); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/task/RobotCheckTask.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.task; 2 | 3 | import com.qklx.qt.admin.entity.Robot; 4 | import com.qklx.qt.common.config.RedisUtil; 5 | import com.qklx.qt.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 RobotCheckTask { 17 | 18 | @Autowired 19 | RedisUtil redisUtil; 20 | 21 | /** 22 | * 更新机器人的运行状态 23 | */ 24 | @Async 25 | @Scheduled(fixedDelay = 5000, initialDelay = 5000) 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 | String startKey = RobotRedisKeyConfig.getRobotIsStartStateKey() + r.getId(); 32 | Object o = redisUtil.get(key); 33 | if (o == null) { 34 | //已经取消了机器人的运行 35 | r.setIsRun(0); 36 | redisUtil.set(startKey, false); 37 | } else { 38 | r.setIsRun(1); 39 | } 40 | try { 41 | r.updateById(); 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | log.error("更新机器人状态失败"); 45 | } 46 | } 47 | 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /qt-admin/src/main/java/com/qklx/qt/admin/task/SymbolTask.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin.task; 2 | 3 | import com.qklx.qt.common.config.RedisUtil; 4 | import com.qklx.qt.common.config.VpnProxyConfig; 5 | import com.qklx.qt.common.constans.RobotRedisKeyConfig; 6 | import com.qklx.qt.core.api.ApiClient; 7 | import com.qklx.qt.core.response.Symbol; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.beans.factory.annotation.Value; 12 | import org.springframework.scheduling.annotation.Async; 13 | import org.springframework.scheduling.annotation.Scheduled; 14 | import org.springframework.stereotype.Component; 15 | 16 | import java.util.Comparator; 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | @Component 21 | public class SymbolTask { 22 | 23 | private static Logger logger = LoggerFactory.getLogger(SymbolTask.class); 24 | @Autowired 25 | VpnProxyConfig vpnProxyConfig; 26 | @Autowired 27 | RedisUtil redisUtil; 28 | 29 | /** 30 | * 收集交易对信息存到数据库 /v1/common/symbols 31 | */ 32 | @Async 33 | @Scheduled(fixedDelay = 1000 * 60 * 60 * 24, initialDelay = 5000) 34 | public void symbolCollects() { 35 | logger.info("=========数据 redis 同步交易对信息开始========="); 36 | ApiClient apiClient = new ApiClient(vpnProxyConfig); 37 | List symbols = apiClient.getSymbols(); 38 | //获取到交易对 进行排序操作 防止每次都插入不一致 39 | symbols = symbols.stream().sorted(Comparator.comparing(Symbol::getSymbol)).collect(Collectors.toList()); 40 | int i = 0; 41 | for (Symbol s : symbols) { 42 | ++i; 43 | com.qklx.qt.admin.entity.Symbol symbol = new com.qklx.qt.admin.entity.Symbol(); 44 | symbol.setId(i); 45 | symbol.setAmountPrecision(s.getAmountPrecision()); 46 | symbol.setBaseCurrency(s.getBaseCurrency()); 47 | symbol.setPricePrecision(s.getPricePrecision()); 48 | symbol.setQuoteCurrency(s.getQuoteCurrency()); 49 | symbol.setSymbol(s.getSymbol()); 50 | if (symbol.insertOrUpdate()) { 51 | //将交易对的quote保存redis 52 | redisUtil.set(RobotRedisKeyConfig.getSymbol() + symbol.getSymbol(), symbol.getBaseCurrency() + "_" + symbol.getQuoteCurrency() + "_" + symbol.getPricePrecision() + "_" + symbol.getAmountPrecision()); 53 | } 54 | } 55 | 56 | logger.info("=========同步交易对信息完毕========="); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | #添加数据源 4 | spring: 5 | datasource: 6 | type: com.alibaba.druid.pool.DruidDataSource 7 | driver-class-name: com.mysql.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/quant?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | druid: 12 | initial-size: 5 13 | min-idle: 10 14 | max-active: 20 15 | max-wait: 60000 16 | min-evictable-idle-time-millis: 6000 17 | time-between-eviction-runs-millis: 3000 18 | validation-query: SELECT 1 FROM DUAL 19 | test-while-idle: true 20 | test-on-borrow: false 21 | test-on-return: false 22 | filters: stat,wall 23 | use-global-data-source-stat: true 24 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 25 | jackson: 26 | date-format: yyyy-MM-dd HH:mm:ss 27 | time-zone: GMT+8 28 | application: 29 | name: qt-admin 30 | redis: 31 | database: 0 32 | host: 127.0.0.1 33 | port: 6379 34 | password: 35 | jedis: 36 | pool: 37 | max-active: 8 38 | max-wait: -1 39 | max-idle: 8 40 | min-idle: 0 41 | timeout: 15000 42 | # mapper-locations: classpath:/mapper/* 43 | eureka: 44 | client: 45 | serviceUrl: 46 | defaultZone: http://${EUREKA_ZONE_HOST:localhost}:${EUREKA_ZONE_PORT:8761}/eureka/ 47 | mybatis-plus: 48 | mapper-locations: classpath*:mapper/*Mapper.xml 49 | 50 | vpnproxy: 51 | enable: true 52 | ip: 127.0.0.1 53 | port: 64035 54 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | address: 192.168.0.119 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/qt?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 | eureka: 44 | client: 45 | serviceUrl: 46 | defaultZone: http://${EUREKA_ZONE_HOST:localhost}:${EUREKA_ZONE_PORT:8761}/eureka/ 47 | mybatis-plus: 48 | mapper-locations: classpath*:mapper/*Mapper.xml 49 | 50 | vpnproxy: 51 | enable: true 52 | ip: 127.0.0.1 53 | port: 64035 54 | -------------------------------------------------------------------------------- /qt-admin/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | -------------------------------------------------------------------------------- /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/qklx/qt/admin/QtParentApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.admin; 2 | 3 | public class QtParentApplicationTests { 4 | 5 | public static void main(String[] args) { 6 | String a = "30775841911"; 7 | int b = Integer.parseInt(a); 8 | System.out.println(b); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /qt-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qt-parent 7 | com.qklx.qt 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | qt-client 13 | 14 | 15 | com.qklx.qt 16 | qt-core 17 | 0.0.1-SNAPSHOT 18 | compile 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | org.yaml 27 | snakeyaml 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-data-redis 32 | 33 | 34 | 35 | redis.clients 36 | jedis 37 | 2.7.3 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-maven-plugin 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/AppClient.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.scheduling.annotation.EnableScheduling; 9 | 10 | @SpringBootApplication 11 | @EnableEurekaClient 12 | @EnableScheduling 13 | @ComponentScan({"com.qklx.qt.common", "com.qklx.client"}) 14 | public class AppClient { 15 | public static void main(String[] args) { 16 | 17 | SpringApplication.run(AppClient.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/Task/RobotOperate.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client.Task; 2 | 3 | import com.qklx.qt.common.config.RedisUtil; 4 | import com.qklx.qt.common.config.VpnProxyConfig; 5 | import com.qklx.qt.core.api.ApiClient; 6 | import com.qklx.qt.core.config.AccountConfig; 7 | import com.qklx.qt.core.config.MarketConfig; 8 | import com.qklx.qt.core.config.StrategyConfig; 9 | import com.qklx.qt.core.config.imp.HuoBiAccountConfigImpl; 10 | import com.qklx.qt.core.config.imp.HuoBiMarketConfigImpl; 11 | import com.qklx.qt.core.domain.Market; 12 | import com.qklx.qt.core.exchangeAdapter.HuobiExchangeAdapter; 13 | import com.qklx.qt.core.strategy.StrategyException; 14 | import com.qklx.qt.core.strategy.TradingStrategy; 15 | import com.qklx.qt.core.strategy.impl.HuoBiStrategyImpl; 16 | import com.qklx.qt.core.trading.TradingApi; 17 | import com.qklx.qt.core.vo.RobotStrategyVo; 18 | import lombok.extern.slf4j.Slf4j; 19 | 20 | @Slf4j 21 | public class RobotOperate { 22 | 23 | private RedisUtil redisUtil; 24 | 25 | 26 | private VpnProxyConfig vpnProxyConfig; 27 | 28 | public RobotOperate(RedisUtil redisUtil, VpnProxyConfig vpnProxyConfig) { 29 | this.redisUtil = redisUtil; 30 | this.vpnProxyConfig = vpnProxyConfig; 31 | } 32 | 33 | public void doRobotTask(RobotStrategyVo vo) { 34 | log.info("启动机器人{}>>>>>>", vo.getRobotId()); 35 | TradingStrategy huobiStrategy = new HuoBiStrategyImpl(redisUtil, vo.getRobotId()); 36 | ApiClient apiClient = new ApiClient(vo.getAppKey(), vo.getAppSecret(), vpnProxyConfig); 37 | TradingApi api = new HuobiExchangeAdapter(apiClient); 38 | MarketConfig marketConfig = new HuoBiMarketConfigImpl(new Market(vo.getSymbol())); 39 | StrategyConfig strategyConfig = new StrategyConfig(vo.getStrategyVo()); 40 | AccountConfig accountConfig = new HuoBiAccountConfigImpl(vo.getAccountConfig()); 41 | log.info("加载机器人{}>>>>>>", vo.getRobotId()); 42 | huobiStrategy.init(api, marketConfig, strategyConfig, accountConfig); 43 | try { 44 | huobiStrategy.execute(); 45 | } catch (StrategyException e) { 46 | e.printStackTrace(); 47 | } 48 | 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/config/ThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | 9 | @Configuration 10 | public class ThreadPool { 11 | 12 | @Bean 13 | public ExecutorService initPool() { 14 | return Executors.newFixedThreadPool(100); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/controller/BotController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client.controller; 2 | 3 | import com.qklx.client.service.RobotService; 4 | import com.qklx.qt.core.api.ApiResult; 5 | import com.qklx.qt.core.vo.RobotStrategyVo; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.PostMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | @Slf4j 14 | @RestController 15 | @RequestMapping("/robot") 16 | public class BotController { 17 | 18 | @Autowired 19 | RobotService robotService; 20 | 21 | @PostMapping("/operatingRobot") 22 | public ApiResult operatingRobot(@RequestBody RobotStrategyVo vo) { 23 | log.info("获取到机器人的配置信息:{}", vo.toString()); 24 | return robotService.operatingRobot(vo); 25 | } 26 | 27 | 28 | } 29 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/service/RobotService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client.service; 2 | 3 | import com.qklx.qt.core.api.ApiResult; 4 | import com.qklx.qt.core.vo.RobotStrategyVo; 5 | 6 | public interface RobotService { 7 | 8 | 9 | ApiResult operatingRobot(RobotStrategyVo vo); 10 | } 11 | -------------------------------------------------------------------------------- /qt-client/src/main/java/com/qklx/client/service/impl/RobotServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.client.service.impl; 2 | 3 | import com.qklx.client.Task.RobotOperate; 4 | import com.qklx.client.service.RobotService; 5 | import com.qklx.qt.common.config.RedisUtil; 6 | import com.qklx.qt.common.config.VpnProxyConfig; 7 | import com.qklx.qt.core.api.ApiResult; 8 | import com.qklx.qt.core.enums.Status; 9 | import com.qklx.qt.core.vo.RobotStrategyVo; 10 | import lombok.extern.slf4j.Slf4j; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.concurrent.ExecutorService; 16 | 17 | @Slf4j 18 | @Service 19 | public class RobotServiceImpl implements RobotService { 20 | @Autowired 21 | VpnProxyConfig vpnProxyConfig; 22 | @Autowired 23 | RedisUtil redisUtil; 24 | @Autowired 25 | ExecutorService executorService; 26 | 27 | @Override 28 | public ApiResult operatingRobot(RobotStrategyVo vo) { 29 | //启动机器人 30 | try { 31 | executorService.execute(() -> { 32 | RobotOperate robotOperate = new RobotOperate(redisUtil, vpnProxyConfig); 33 | robotOperate.doRobotTask(vo); 34 | }); 35 | return new ApiResult(Status.SUCCESS); 36 | } catch (Exception e) { 37 | e.printStackTrace(); 38 | log.error("client端启动机器人发生错误:机器人编号:{},client端地址:{}", vo.getRobotId(), vo.getAddress()); 39 | log.error("错误信息:" + e.getMessage()); 40 | return new ApiResult(Status.startRobotError); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8024 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://${EUREKA_ZONE_HOST:localhost}:${EUREKA_ZONE_PORT:8761}/eureka/ 7 | 8 | spring: 9 | application: 10 | name: qt-client 11 | # rabbitmq: 12 | # host: ${RABBIT_MQ_HOST:localhost} 13 | # port: ${RABBIT_MQ_PORT:5672} 14 | # username: ${RABBIT_MQ_USERNAME:yang} 15 | # password: ${RABBIT_MQ_PASSWORD:yang} 16 | redis: 17 | database: 0 18 | host: 127.0.0.1 19 | port: 6379 20 | password: 21 | jedis: 22 | pool: 23 | max-active: 8 24 | max-wait: -1 25 | max-idle: 8 26 | min-idle: 0 27 | timeout: 15000 28 | feign: 29 | hystrix: 30 | enabled: true 31 | 32 | management: 33 | endpoints: 34 | web: 35 | exposure: 36 | include: '*' 37 | base-path: / 38 | vpnproxy: 39 | enable: true 40 | ip: 127.0.0.1 41 | port: 64035 42 | 43 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application-prod.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8024 3 | address: 192.168.0.119 4 | eureka: 5 | client: 6 | serviceUrl: 7 | defaultZone: http://${EUREKA_ZONE_HOST:192.168.0.119}:${EUREKA_ZONE_PORT:8761}/eureka/ 8 | 9 | spring: 10 | application: 11 | name: qt-client 12 | # rabbitmq: 13 | # host: ${RABBIT_MQ_HOST:localhost} 14 | # port: ${RABBIT_MQ_PORT:5672} 15 | # username: ${RABBIT_MQ_USERNAME:yang} 16 | # password: ${RABBIT_MQ_PASSWORD:yang} 17 | redis: 18 | database: 0 19 | host: 127.0.0.1 20 | port: 6379 21 | password: 22 | jedis: 23 | pool: 24 | max-active: 8 25 | max-wait: -1 26 | max-idle: 8 27 | min-idle: 0 28 | timeout: 15000 29 | feign: 30 | hystrix: 31 | enabled: true 32 | 33 | management: 34 | endpoints: 35 | web: 36 | exposure: 37 | include: '*' 38 | base-path: / 39 | vpnproxy: 40 | enable: true 41 | ip: 127.0.0.1 42 | port: 64035 43 | 44 | -------------------------------------------------------------------------------- /qt-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: dev 4 | -------------------------------------------------------------------------------- /qt-client/src/test/java/Test.java: -------------------------------------------------------------------------------- 1 | import com.alibaba.fastjson.JSON; 2 | import com.qklx.qt.core.enums.OrderType; 3 | import com.qklx.qt.core.strategy.impl.HuoBiStrategyImpl; 4 | 5 | public class Test { 6 | 7 | public static void main(String[] args) { 8 | 9 | HuoBiStrategyImpl.OrderState orderState=new HuoBiStrategyImpl.OrderState(); 10 | orderState.setId(31862982431l); 11 | orderState.setOrderType(OrderType.BUY_MARKET); 12 | orderState.setType(com.qklx.qt.core.trading.OrderType.BUY); 13 | 14 | 15 | String s = JSON.toJSONString(orderState); 16 | System.out.println(s); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/qklx/qt/common/config/JsonConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/common/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/common/config/VpnProxyConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/common/constans/RobotRedisKeyConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/common/utils/ComputeUtil.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/qklx/qt/common/utils/DateUtils.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.common.utils; 2 | 3 | import java.util.Date; 4 | 5 | public class DateUtils { 6 | 7 | public static void main(String[] args) { 8 | long time = System.currentTimeMillis(); 9 | Date date = parseTimeMillisToDate(time); 10 | System.out.println(date); 11 | } 12 | 13 | public static Date parseTimeMillisToDate(Long timeStamp) { 14 | return new Date(Long.parseLong(String.valueOf(timeStamp))); 15 | } 16 | 17 | 18 | } 19 | -------------------------------------------------------------------------------- /qt-common/src/main/java/com/qklx/qt/common/utils/JsonFormate.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.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/bitted/qt/93c6139641b287ffa0151eca8ce9bf4ada904692/qt-common/src/main/resources/libs/opslabJutil-2.0.3.jar -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/MainTest.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.RoundingMode; 5 | 6 | public class MainTest { 7 | static final String access_key = "ce9f0744-3fc8eea2-6bc64c6f-865ff"; 8 | static final String secret_key = "f1f2003f-4c8ee5d3-9178be8a-25d54"; 9 | private static Integer a = 0; 10 | private static Integer b = 0; 11 | 12 | private static void total(Integer a, Integer b) { 13 | a = a + 1; 14 | b = b + 1; 15 | } 16 | 17 | public static void main(String[] args) { 18 | 19 | BigDecimal buyPrice = new BigDecimal(164.0001); 20 | BigDecimal sellPrice = new BigDecimal(162.0002); 21 | BigDecimal diff = sellPrice.subtract(buyPrice).divide(buyPrice, 4, RoundingMode.DOWN).multiply(new BigDecimal(100)); 22 | System.out.println("abs " + diff.abs()); 23 | 24 | System.out.println(diff.toPlainString()); 25 | 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/api/ApiException.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.api; 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-core/src/main/java/com/qklx/qt/core/api/ApiResult.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.api; 2 | 3 | import com.qklx.qt.core.enums.Status; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | 7 | /** 8 | * 返回的数据结构 9 | */ 10 | @Data 11 | @AllArgsConstructor 12 | public class ApiResult { 13 | 14 | int code; 15 | 16 | String message; 17 | 18 | Object data; 19 | 20 | public ApiResult() { 21 | } 22 | 23 | public ApiResult(Status status, Object res) { 24 | this.data = res; 25 | this.message = status.getMsg(); 26 | this.code = status.getCode(); 27 | } 28 | 29 | public ApiResult(Status status) { 30 | this.message = status.getMsg(); 31 | this.code = status.getCode(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/config/AccountConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config; 2 | 3 | public interface AccountConfig { 4 | 5 | 6 | String accountId(); 7 | 8 | String getAccessKey(); 9 | 10 | String getSecretKey(); 11 | 12 | String getUserId(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/config/KlineConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config; 2 | 3 | public interface KlineConfig { 4 | /** 5 | * 每次获取数据的大小 6 | * @return 7 | */ 8 | String size(); 9 | 10 | /** 11 | * 返回数据时间粒度,也就是每根蜡烛的时间区间 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year 12 | * @return 13 | */ 14 | String period(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/config/MarketConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config; 2 | 3 | public interface MarketConfig { 4 | /** 5 | * 市场交易对名称 6 | */ 7 | String markName(); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/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.qklx.qt.core.config; 25 | 26 | import com.qklx.qt.core.vo.StrategyVo; 27 | import lombok.AllArgsConstructor; 28 | import lombok.Builder; 29 | import lombok.Data; 30 | 31 | /** 32 | *

33 | * Encapsulates any (optional) configuration for a Trading Strategy. 34 | * Basically just a map of key-value pairs. 35 | *

36 | * 37 | *

38 | * Configuration comes from the strategies.xml file. 39 | *

40 | * 41 | * @author gazbert 42 | * @since 1.0 43 | */ 44 | @Data 45 | @AllArgsConstructor 46 | public class StrategyConfig { 47 | StrategyVo strategyVo; 48 | } 49 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/config/imp/HuoBiAccountConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config.imp; 2 | 3 | import com.qklx.qt.core.domain.Account; 4 | import com.qklx.qt.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/qklx/qt/core/config/imp/HuoBiKlineConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config.imp; 2 | 3 | import com.qklx.qt.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/qklx/qt/core/config/imp/HuoBiMarketConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.config.imp; 2 | 3 | import com.qklx.qt.core.config.MarketConfig; 4 | import com.qklx.qt.core.domain.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/qklx/qt/core/domain/Account.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.domain; 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-core/src/main/java/com/qklx/qt/core/domain/ArConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.domain; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | @Data 7 | @Builder 8 | public class ArConfig { 9 | 10 | 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/domain/Market.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.domain; 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-core/src/main/java/com/qklx/qt/core/domain/MineConfig.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.domain; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class MineConfig { 7 | 8 | /** 9 | * 订单一段时间出现的买卖量 10 | */ 11 | int buySize; 12 | int sellSize; 13 | 14 | /** 15 | * 他们出现后分别各自的权重 16 | */ 17 | int buyWights; 18 | int sellWights; 19 | 20 | /** 21 | * 总的买入权重 22 | */ 23 | int allBuyWights; 24 | 25 | /** 26 | * 总的卖出权重 27 | */ 28 | int allSellWights; 29 | } 30 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/domain/Option.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.domain; 2 | 3 | import lombok.Builder; 4 | import lombok.Data; 5 | 6 | @Data 7 | @Builder 8 | public class Option { 9 | String size; 10 | 11 | String period; 12 | } 13 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/enums/AType.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/enums/OrderType.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.enums; 2 | 3 | public enum OrderType { 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 | OrderType(String tyoe) { 25 | this.tyoe = tyoe; 26 | } 27 | 28 | public String getTyoe() { 29 | return tyoe; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/enums/RobotState.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/enums/Status.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/enums/TraceType.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/exchangeAdapter/BaseExchangeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.exchangeAdapter; 2 | 3 | public abstract class BaseExchangeAdapter { 4 | 5 | protected static final String status = "ok"; 6 | protected static final String buySign = "buy"; 7 | protected static final String sellSign = "sell"; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/mq/OrderIdRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.mq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.qklx.qt.common.config.RedisUtil; 5 | import com.qklx.qt.common.constans.RobotRedisKeyConfig; 6 | import com.qklx.qt.core.config.AccountConfig; 7 | import com.qklx.qt.core.vo.OrderTaskMessage; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | @Slf4j 11 | public class OrderIdRedisMqServiceImpl implements RedisMqService { 12 | 13 | private RedisUtil redisUtil; 14 | 15 | private AccountConfig accountConfig; 16 | 17 | private int robotId; 18 | 19 | public OrderIdRedisMqServiceImpl(RedisUtil redisUtil, AccountConfig accountConfig, int robotId) { 20 | this.redisUtil = redisUtil; 21 | this.accountConfig = accountConfig; 22 | this.robotId = robotId; 23 | } 24 | 25 | @Override 26 | public void sendMsg(Object orderId) { 27 | OrderTaskMessage message = new OrderTaskMessage(Long.parseLong(orderId.toString()), this.accountConfig.getAccessKey(), this.accountConfig.getSecretKey(), this.robotId, this.accountConfig.getUserId()); 28 | redisUtil.convertAndSend(RobotRedisKeyConfig.getQueue(), JSON.toJSONString(message)); 29 | log.info("机器人订单信息日志:" + JSON.toJSONString(message)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/mq/OrderProfitRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.mq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.qklx.qt.common.config.RedisUtil; 5 | import com.qklx.qt.common.constans.RobotRedisKeyConfig; 6 | import lombok.extern.slf4j.Slf4j; 7 | 8 | @Slf4j 9 | public class OrderProfitRedisMqServiceImpl implements RedisMqService { 10 | 11 | private RedisUtil redisUtil; 12 | 13 | 14 | public OrderProfitRedisMqServiceImpl(RedisUtil redisUtil) { 15 | this.redisUtil = redisUtil; 16 | 17 | } 18 | 19 | @Override 20 | public void sendMsg(Object msg) { 21 | redisUtil.convertAndSend(RobotRedisKeyConfig.getOrder_profit(), JSON.toJSONString(msg)); 22 | log.info("机器人盈利信息日志:" + JSON.toJSONString(msg)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/mq/RedisMqService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.mq; 2 | 3 | public interface RedisMqService { 4 | 5 | 6 | void sendMsg(Object msg); 7 | 8 | 9 | } 10 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/mq/RobotLogsRedisMqServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.mq; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.qklx.qt.common.config.RedisUtil; 5 | import com.qklx.qt.common.constans.RobotRedisKeyConfig; 6 | import com.qklx.qt.core.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 | @Slf4j 15 | public class RobotLogsRedisMqServiceImpl implements RedisMqService { 16 | 17 | private ExecutorService executorService = Executors.newFixedThreadPool(3); 18 | 19 | private RedisUtil redisUtil; 20 | private int robotId; 21 | private int userId; 22 | 23 | public RobotLogsRedisMqServiceImpl(RedisUtil redisUtil, int robotId, int userId) { 24 | this.redisUtil = redisUtil; 25 | this.robotId = robotId; 26 | this.userId = userId; 27 | } 28 | 29 | private ThreadLocal simpleDateFormatThreadLocal = new ThreadLocal<>(); 30 | 31 | 32 | /** 33 | * 异步方式提交 34 | * 35 | * @param msg 36 | */ 37 | @Override 38 | public void sendMsg(Object msg) { 39 | log.info("机器人{}日志:{}", robotId, msg.toString()); 40 | executorService.execute(() -> { 41 | if (simpleDateFormatThreadLocal.get() == null) { 42 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 43 | simpleDateFormatThreadLocal.set(simpleDateFormat); 44 | } 45 | try { 46 | RobotRunMessage robotRunMessage = new RobotRunMessage(); 47 | robotRunMessage.setMsg(msg.toString()); 48 | robotRunMessage.setRobotId(robotId); 49 | robotRunMessage.setDate(simpleDateFormatThreadLocal.get().format(new Date())); 50 | robotRunMessage.setUserId(userId); 51 | redisUtil.convertAndSend(RobotRedisKeyConfig.getRobot_msg_queue(), JSON.toJSONString(robotRunMessage)); 52 | } catch (Exception e) { 53 | e.printStackTrace(); 54 | } 55 | }); 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/request/CreateOrderRequest.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/request/DepthRequest.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/request/IntrustOrdersDetailRequest.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Account.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Accounts.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/AccountsResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | import com.qklx.qt.core.api.ApiException; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 16:01 9 | */ 10 | 11 | public class AccountsResponse { 12 | 13 | /** 14 | * status : ok 15 | * data : [{"id":100009,"type":"spot","state":"working","user-id":1000}] 16 | */ 17 | 18 | private String status; 19 | public String errCode; 20 | public String errMsg; 21 | private T data; 22 | 23 | public T checkAndReturn() { 24 | if ("ok".equals(status)) { 25 | return data; 26 | } 27 | throw new ApiException(errCode, errMsg); 28 | } 29 | 30 | public String getStatus() { 31 | return status; 32 | } 33 | 34 | public void setStatus(String status) { 35 | this.status = status; 36 | } 37 | 38 | public T getData() { 39 | return data; 40 | } 41 | 42 | public void setData(T data) { 43 | this.data = data; 44 | } 45 | 46 | public String getErrCode() { 47 | return errCode; 48 | } 49 | 50 | public void setErrCode(String errCode) { 51 | this.errCode = errCode; 52 | } 53 | 54 | public String getErrMsg() { 55 | return errMsg; 56 | } 57 | 58 | public void setErrMsg(String errMsg) { 59 | this.errMsg = errMsg; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/response/ApiResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | import com.qklx.qt.core.api.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-core/src/main/java/com/qklx/qt/core/response/Balance.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/BalanceBean.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/BalanceResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Batchcancel.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/BatchcancelBean.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/BatchcancelResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Currencys.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 15:47 7 | */ 8 | 9 | public class Currencys { 10 | } 11 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/response/CurrencysResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Depth.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/DepthResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/DetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Details.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/HistoryTrade.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/HistoryTradeResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/HistoryTradess.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/IntrustDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Kline.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | import lombok.Data; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * @Author ISME 9 | * @Date 2018/1/14 10 | * @Time 11:35 11 | */ 12 | @Data 13 | public class Kline { 14 | 15 | 16 | private long id; 17 | private BigDecimal amount; 18 | private int count; 19 | private BigDecimal open; 20 | private BigDecimal close; 21 | private BigDecimal low; 22 | private BigDecimal high; 23 | private BigDecimal vol; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/response/KlineResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | import com.qklx.qt.core.api.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-core/src/main/java/com/qklx/qt/core/response/MatchresultsOrdersDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Merged.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/MergedResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | import com.qklx.qt.core.api.ApiException; 4 | 5 | /** 6 | * @Author ISME 7 | * @Date 2018/1/14 8 | * @Time 14:15 9 | */ 10 | 11 | public class MergedResponse { 12 | 13 | /** 14 | * status : ok 15 | * ch : market.ethusdt.detail.merged 16 | * ts : 1499225276950 17 | * 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]} 18 | */ 19 | 20 | private String status; 21 | private String ch; 22 | private long ts; 23 | public String errCode; 24 | public String errMsg; 25 | public T data; 26 | 27 | public T checkAndReturn() { 28 | if ("ok".equals(status)) { 29 | return data; 30 | } 31 | throw new ApiException(errCode, errMsg); 32 | } 33 | 34 | public String getStatus() { 35 | return status; 36 | } 37 | 38 | public void setStatus(String status) { 39 | this.status = status; 40 | } 41 | 42 | public String getCh() { 43 | return ch; 44 | } 45 | 46 | public void setCh(String ch) { 47 | this.ch = ch; 48 | } 49 | 50 | public long getTs() { 51 | return ts; 52 | } 53 | 54 | public void setTs(long ts) { 55 | this.ts = ts; 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 | public T getData() { 75 | return data; 76 | } 77 | 78 | public void setData(T data) { 79 | this.data = data; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/response/OrdersDetail.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/OrdersDetailResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Place.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.response; 2 | 3 | /** 4 | * @Author ISME 5 | * @Date 2018/1/14 6 | * @Time 17:10 7 | */ 8 | 9 | public class Place { 10 | } 11 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/response/SubmitcancelResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Symbols.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/SymbolsResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/TimestampResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/Trade.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/TradeBean.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/response/TradeResponse.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/strategy/AbstractStrategy.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.strategy; 2 | 3 | import com.qklx.qt.core.strategy.impl.HuoBiStrategyImpl; 4 | import com.qklx.qt.core.trading.OrderType; 5 | import com.qklx.qt.core.vo.StrategyVo; 6 | 7 | /** 8 | * 策略基类 9 | */ 10 | public abstract class AbstractStrategy { 11 | protected HuoBiStrategyImpl.OrderState orderState; 12 | protected StrategyVo.BaseInfoEntity baseInfo; 13 | 14 | /** 15 | * 权重计算 16 | */ 17 | protected void weightsCalculation() { 18 | 19 | if ((this.orderState.getType() == OrderType.SELL || this.orderState.getType() == null) && 20 | this.baseInfo.getBuyAllWeights() != 0) { 21 | buyCalculation(); 22 | } 23 | 24 | if (this.orderState.getType() == OrderType.BUY 25 | && this.baseInfo.getSellAllWeights() != 0) { 26 | sellCalculation(); 27 | } 28 | 29 | } 30 | 31 | /** 32 | * 买入权重计算 33 | */ 34 | protected abstract void buyCalculation(); 35 | 36 | /** 37 | * 卖出权重计算 38 | */ 39 | protected abstract void sellCalculation(); 40 | 41 | public static class Weights { 42 | private volatile Integer buyTotal = 0; 43 | private volatile Integer sellTotal = 0; 44 | 45 | 46 | public Integer getBuyTotal() { 47 | return buyTotal; 48 | } 49 | 50 | public Integer getSellTotal() { 51 | return sellTotal; 52 | } 53 | 54 | public void AddBuyTotal(Integer buyTotal) { 55 | this.buyTotal += buyTotal; 56 | } 57 | 58 | public void AddSellTotal(Integer sellTotal) { 59 | this.sellTotal += sellTotal; 60 | } 61 | 62 | public void reSet() { 63 | this.buyTotal = 0; 64 | this.sellTotal = 0; 65 | } 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/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.qklx.qt.core.strategy; 25 | 26 | /** 27 | * Trading Strategy implementations should throw this exception if they want the Trading Engine to shutdown the bot 28 | * immediately. 29 | * 30 | * @author gazbert 31 | * @since 1.0 32 | */ 33 | public final class StrategyException extends Exception { 34 | 35 | private static final long serialVersionUID = -5066890753686004758L; 36 | 37 | /** 38 | * Constructor builds exception with error message. 39 | * 40 | * @param msg the error message. 41 | */ 42 | public StrategyException(String msg) { 43 | super(msg); 44 | } 45 | 46 | /** 47 | * Constructor builds exception from original throwable. 48 | * 49 | * @param e the original exception. 50 | */ 51 | public StrategyException(Throwable e) { 52 | super(e); 53 | } 54 | 55 | /** 56 | * Constructor builds exception with error message and original throwable. 57 | * 58 | * @param msg the error message. 59 | * @param e the original exception. 60 | */ 61 | public StrategyException(String msg, Throwable e) { 62 | super(msg, e); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/strategy/impl/ArStrategyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | package com.qklx.qt.core.strategy.impl; 3 | 4 | import MarketConfig; 5 | import StrategyConfig; 6 | import Kline; 7 | import StrategyException; 8 | import TradingStrategy; 9 | import TradingApi; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import java.util.List; 14 | 15 | */ 16 | /** 17 | * ar 指标 AR = [N天所有(High-Open)的和/ N天所有(Open—Low)的和] * 100 18 | *//* 19 | 20 | public class ArStrategyImpl implements TradingStrategy { 21 | 22 | private static Logger logger = LoggerFactory.getLogger(ArStrategyImpl.class); 23 | 24 | 25 | TradingApi tradingApi; 26 | MarketConfig market; 27 | StrategyConfig strategyConfig; 28 | 29 | @Override 30 | public void init(TradingApi tradingApi, MarketConfig market, StrategyConfig config) { 31 | this.tradingApi = tradingApi; 32 | this.market = market; 33 | this.strategyConfig = config; 34 | } 35 | 36 | */ 37 | /** 38 | * ar 指标 AR = [N天所有(High-Open)的和/ N天所有(Open—Low)的和] * 100 39 | * 40 | * @throws StrategyException 41 | *//* 42 | 43 | @Override 44 | public void execute() throws StrategyException { 45 | boolean buySgin = false; 46 | boolean sellSgin = false; 47 | double ar = getAr(); 48 | while (true) { 49 | //获取k线 计算 ar 50 | System.out.println("Calculation res " + ar); 51 | if (ar < strategyConfig.getDataOverSell() && buySgin == false) { 52 | //"AR超过了超卖线,产生买入信号" 53 | logger.info("AR超过了超卖线,产生买入信号============"); 54 | logger.info("买入============"); 55 | buySgin = true; 56 | sellSgin = false; 57 | } else if (ar > strategyConfig.getDataOverBuy() && sellSgin == false) { 58 | //("AR超过了超买线,产生卖出信号") 59 | logger.info("AR超过了超买线,产生卖出信号============"); 60 | logger.info("卖出============"); 61 | sellSgin = true; 62 | buySgin = false; 63 | } 64 | try { 65 | Thread.sleep(3000); 66 | } catch (InterruptedException e) { 67 | e.printStackTrace(); 68 | } 69 | } 70 | 71 | 72 | } 73 | 74 | 75 | private double getAr() { 76 | 77 | List klines = tradingApi.getKline(market); 78 | 79 | double highOpenDiff = 0; 80 | double openLowDiff = 0; 81 | for (int i = 0; i < klines.size(); i++) { 82 | highOpenDiff += (klines.get(i).getHigh()) - (klines.get(i).getOpen()); 83 | openLowDiff += (klines.get(i).getOpen()) - (klines.get(i).getLow()); 84 | } 85 | return (highOpenDiff / openLowDiff) * 100; 86 | 87 | } 88 | 89 | 90 | } 91 | */ 92 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/to/RobotRunMessage.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.to; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class RobotRunMessage { 7 | 8 | int userId; 9 | int robotId; 10 | String msg; 11 | String date; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/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.qklx.qt.core.trading; 25 | 26 | import java.math.BigDecimal; 27 | import java.util.Map; 28 | 29 | /** 30 | * Encapsulates wallet balance info held on the exchange. 31 | * 32 | * @author gazbert 33 | * @since 1.0 34 | */ 35 | public interface BalanceInfo { 36 | 37 | /** 38 | * Returns map of available balances. 39 | *

40 | * The key is the currency id in UPPERCASE, e.g. LTC, BTC, USD 41 | *

42 | * 43 | * @return map of available balances. 44 | */ 45 | Map getBalancesAvailable(); 46 | 47 | /** 48 | * Returns map of balances on hold. 49 | *

50 | * Some exchangeAdapter do not provide this information and the returned map will be empty. 51 | *

52 | * The key is the currency id in UPPERCASE, e.g. LTC, BTC, USD 53 | *

54 | * 55 | * @return map of balances on hold. 56 | */ 57 | Map getBalancesOnHold(); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/trading/MarketOrder.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.trading; 2 | 3 | import com.qklx.qt.core.response.TradeBean; 4 | import lombok.Data; 5 | 6 | import java.util.List; 7 | 8 | @Data 9 | public class MarketOrder { 10 | 11 | List buy; 12 | List sell; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/trading/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.qklx.qt.core.trading; 25 | 26 | /** 27 | * Defines the different order types for sending to the exchange. 28 | * 29 | * @author gazbert 30 | * @since 1.0 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-core/src/main/java/com/qklx/qt/core/trading/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.qklx.qt.core.trading; 25 | 26 | /** 27 | *

28 | * This exception is thrown from Exchange Adapter implementations when there is a problem making an API call to the exchange. 29 | *

30 | *

31 | * If your Trading Strategy receives this exception, this means something bad as happened; you would probably want to 32 | * wrap this exception in a StrategyException and let the Trading Engine shutdown the bot immediately to prevent 33 | * unexpected losses. 34 | *

35 | *

36 | * If the Trading Engine receives one of these exceptions from directly calling an Exchange Adapter method, 37 | * it shuts down the bot immediately. 38 | *

39 | * 40 | * @author gazbert 41 | * @since 1.0 42 | */ 43 | public class TradingApiException extends Exception { 44 | 45 | private static final long serialVersionUID = -8279304672615688060L; 46 | 47 | /** 48 | * Constructor builds exception with error message. 49 | * 50 | * @param msg the error message. 51 | */ 52 | public TradingApiException(String msg) { 53 | super(msg); 54 | } 55 | 56 | /** 57 | * Constructor builds exception with error message and original throwable. 58 | * 59 | * @param msg the error message. 60 | * @param e the original exception. 61 | */ 62 | public TradingApiException(String msg, Throwable e) { 63 | super(msg, e); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/trading/impl/HuoBiOpenOrderImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.trading.impl; 2 | 3 | import com.qklx.qt.core.response.OrdersDetail; 4 | import com.qklx.qt.core.trading.OpenOrder; 5 | import com.qklx.qt.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-core/src/main/java/com/qklx/qt/core/vo/AccountVo.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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 | } 24 | -------------------------------------------------------------------------------- /qt-core/src/main/java/com/qklx/qt/core/vo/OrderTaskMessage.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/vo/ProfitMessage.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.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-core/src/main/java/com/qklx/qt/core/vo/RobotStrategyVo.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.vo; 2 | 3 | import com.qklx.qt.core.domain.Account; 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-core/src/main/java/com/qklx/qt/core/vo/RobotVo.java: -------------------------------------------------------------------------------- 1 | package com.qklx.qt.core.vo; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class RobotVo { 7 | String robotName; 8 | String symbol; 9 | int strategyId; 10 | String nodeAddress; 11 | String userId; 12 | int accountId; 13 | } 14 | -------------------------------------------------------------------------------- /qt-register/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qt-parent 7 | com.qklx.qt 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | qt-register 13 | 14 | 15 | 16 | 17 | org.springframework.cloud 18 | spring-cloud-starter-netflix-eureka-server 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-maven-plugin 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /qt-register/src/main/java/com/qklx/center/AppRegister.java: -------------------------------------------------------------------------------- 1 | package com.qklx.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 | public static void main(String[] args) { 12 | SpringApplication.run(AppRegister.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /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:8761} 3 | 4 | eureka: 5 | client: 6 | registerWithEureka: false 7 | fetchRegistry: false 8 | serviceUrl: 9 | defaultZone: http://${EUREKA_ZONE_HOST:192.168.0.119}:${EUREKA_ZONE_PORT:8761}/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 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/account") 19 | public class AccountController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/BalanceController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/balance") 19 | public class BalanceController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/LogsController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/logs") 19 | public class LogsController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-25 16 | */ 17 | @RestController 18 | @RequestMapping("/order") 19 | public class OrderController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/OrdersController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/orders") 19 | public class OrdersController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/RobotController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/robot") 19 | public class RobotController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/StrategyController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/strategy") 19 | public class StrategyController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/SymbolController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/symbol") 19 | public class SymbolController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | import com.qklx.temp.controller.AbstractController; 8 | 9 | /** 10 | *

11 | * 前端控制器 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @RestController 18 | @RequestMapping("/user") 19 | public class UserController extends AbstractController { 20 | 21 | } 22 | 23 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/dao/AccountMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.dao; 2 | 3 | import com.qklx.temp.entity.Account; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

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

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface BalanceMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/dao/LogsMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.dao; 2 | 3 | import com.qklx.temp.entity.Logs; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface LogsMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/dao/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.dao; 2 | 3 | import com.qklx.temp.entity.Order; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

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

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface OrdersMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/dao/RobotMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.dao; 2 | 3 | import com.qklx.temp.entity.Robot; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface RobotMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/dao/StrategyMapper.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.dao; 2 | 3 | import com.qklx.temp.entity.Strategy; 4 | import com.baomidou.mybatisplus.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

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

8 | * Mapper 接口 9 | *

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

8 | * Mapper 接口 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/entity/Logs.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.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-30 16 | */ 17 | public class Logs extends Model { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | @TableId(value = "id", type = IdType.AUTO) 22 | private Integer id; 23 | private String message; 24 | @TableField("robot_id") 25 | private Integer robotId; 26 | 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getMessage() { 37 | return message; 38 | } 39 | 40 | public void setMessage(String message) { 41 | this.message = message; 42 | } 43 | 44 | public Integer getRobotId() { 45 | return robotId; 46 | } 47 | 48 | public void setRobotId(Integer robotId) { 49 | this.robotId = robotId; 50 | } 51 | 52 | @Override 53 | protected Serializable pkVal() { 54 | return this.id; 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "Logs{" + 60 | ", id=" + id + 61 | ", message=" + message + 62 | ", robotId=" + robotId + 63 | "}"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/entity/Symbol.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.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-30 16 | */ 17 | public class Symbol extends Model { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | @TableId(value = "id", type = IdType.AUTO) 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 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/AccountService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Account; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface AccountService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/BalanceService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Balance; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface BalanceService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/LogsService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Logs; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface LogsService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Order; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-25 13 | */ 14 | public interface OrderService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/OrdersService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Orders; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface OrdersService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/RobotService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Robot; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface RobotService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/StrategyService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Strategy; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface StrategyService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/SymbolService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.Symbol; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface SymbolService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service; 2 | 3 | import com.qklx.temp.entity.User; 4 | import com.baomidou.mybatisplus.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author yang 12 | * @since 2019-04-30 13 | */ 14 | public interface UserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/AccountServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Account; 4 | import com.qklx.temp.dao.AccountMapper; 5 | import com.qklx.temp.service.AccountService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class AccountServiceImpl extends ServiceImpl implements AccountService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/BalanceServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Balance; 4 | import com.qklx.temp.dao.BalanceMapper; 5 | import com.qklx.temp.service.BalanceService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class BalanceServiceImpl extends ServiceImpl implements BalanceService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/LogsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Logs; 4 | import com.qklx.temp.dao.LogsMapper; 5 | import com.qklx.temp.service.LogsService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class LogsServiceImpl extends ServiceImpl implements LogsService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Order; 4 | import com.qklx.temp.dao.OrderMapper; 5 | import com.qklx.temp.service.OrderService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-25 16 | */ 17 | @Service 18 | public class OrderServiceImpl extends ServiceImpl implements OrderService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/OrdersServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Orders; 4 | import com.qklx.temp.dao.OrdersMapper; 5 | import com.qklx.temp.service.OrdersService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class OrdersServiceImpl extends ServiceImpl implements OrdersService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/RobotServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Robot; 4 | import com.qklx.temp.dao.RobotMapper; 5 | import com.qklx.temp.service.RobotService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class RobotServiceImpl extends ServiceImpl implements RobotService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/StrategyServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Strategy; 4 | import com.qklx.temp.dao.StrategyMapper; 5 | import com.qklx.temp.service.StrategyService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class StrategyServiceImpl extends ServiceImpl implements StrategyService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/SymbolServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.Symbol; 4 | import com.qklx.temp.dao.SymbolMapper; 5 | import com.qklx.temp.service.SymbolService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class SymbolServiceImpl extends ServiceImpl implements SymbolService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/src/main/java/com/qklx/temp/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.qklx.temp.service.impl; 2 | 3 | import com.qklx.temp.entity.User; 4 | import com.qklx.temp.dao.UserMapper; 5 | import com.qklx.temp.service.UserService; 6 | import com.baomidou.mybatisplus.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author yang 15 | * @since 2019-04-30 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements UserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /temp/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, name, user_id AS userId, access_key AS accessKey, secret_key AS secretKey, type, state, info, create_time AS createTime, is_delete AS isDelete 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /temp/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 | -------------------------------------------------------------------------------- /temp/src/main/resources/mapper/LogsMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | id, message, robot_id AS robotId 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /temp/src/main/resources/mapper/OrderMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | id, order_id AS orderId, symbol, robot_id AS robotId, account_id AS accountId, amount, price, create_time AS createTime, order_type AS orderType 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /temp/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 | 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 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /temp/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, account_id AS accountId, 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 | 25 | -------------------------------------------------------------------------------- /temp/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 | 36 | -------------------------------------------------------------------------------- /temp/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 | -------------------------------------------------------------------------------- /temp/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 | --------------------------------------------------------------------------------