Giter Site home page Giter Site logo

sun0x00 / redtorch Goto Github PK

View Code? Open in Web Editor NEW
754.0 754.0 371.0 47.07 MB

Kotlin(Java)开源量化交易开发框架

Home Page: http://redtorch.io

Java 92.17% CSS 0.01% Kotlin 7.82%
algotrading cta ctp finance investment java kotlin quant redtorch trading

redtorch's Issues

可否考虑去掉对 mongo 的依赖

mongo 对于 Tick 这种类似时间序列的存储貌似不是很高效呢。
如果要存上两年以上的数据,mongo 的性能可能会有问题。

有没有架构文档?

大佬呀,想学习一下你项目的设计和架构,有没有文档呀。 随便给点就好。

计划拆分策略模块为独立JVM进程

当前系统存在耦合问题,当需要更新单个策略时,需要重启JVM,影响其他策略的正常运行。

计划采用mmap或socket等技术对这一部分内容解耦,策略运行时存在于单独的jvm实例。

平台和策略将实现分离。

关于配置

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:
docs
A /config subdirectory of the current directory.
The current directory
A classpath /config package
The classpath root

所以只要在当前运行目录下,创建config目录,app;ication,properties 或者直接放在当前目录下,可以覆盖classpath里的properties文件。 RtConfig.properties 需要改下加载程序,这样也可以符合springboot的约定。logback.xml LOG_HOME无需指定盘符,会自动创建log目录。``

在CtpGateway中一个可能的问题

在CtpGateway.class中,有这样一个TimerTask:
`class QueryTimerTask extends TimerTask{

    @Override
    public void run() {
    	try {
	    	if(isConnected()) {
		        queryAccount();
	    	}
		    Thread.sleep(1250);
		    if(isConnected()) {
			    queryPosition();
		    }
		    Thread.sleep(1250);
    	}catch (Exception e) {
			log.error(gatewayLogInfo+"定时查询发生异常",e);
		}
    }
}

这个定时任务的执行,仅仅休眠就有2500ms,没有加上执行查询的耗时。 而这个任务执行的间隔仅仅1000ms:timer.schedule(new QueryTimerTask(), new Date(), 1000);`
这会导致任务队列大量堆积,不知这是一个问题,还是特意如此设计?
能否请作者解答一下?

建议使用Gradle wrapper

一个很微小的改动,但是能够避免将来用户不同gradle版本的问题。gradle的best practice是用gradlew,其他知名的开源项目disruptor sbe等都是gradlew 谢谢~

mac下System.load so文件报异常

java.lang.UnsatisfiedLinkError: /private/tmp/xyz/redtorch/api/jctp/lib/libthostmduserapi.so: dlopen(/private/tmp/xyz/redtorch/api/jctp/lib/libthostmduserapi.so, 1): no suitable image found. Did find:
/private/tmp/xyz/redtorch/api/jctp/lib/libthostmduserapi.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
/private/tmp/xyz/redtorch/api/jctp/lib/libthostmduserapi.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00

稳定性欠佳

image
连接中断,到了交易时间不能自动重连,这对于“无人职守”的场景就完了

关于FastEvent的设计与使用困惑

在GatewayAbstract的代码中看到FastEvent的event与eventType用的都是一样的值,那么event与eventType的区别是什么呢?为什么要设计两个字段呢?

socketio的跨域问题如何解决

web页面服务端口为9099,socketio的端口为9098,为什么没有报跨域呢?我的其他项目正好有用到这块,想学习一下

dev分支暂时还编译不过 期待更新~

❯ ./gradlew build

> Task :rt-strategy:compileTestJava FAILED
/private/tmp/RedTorch/rt-strategy/src/test/java/xyz/redtorch/startegy/backtesting/StrategyDemoBacktesting.java:15: error: package xyz.redtorch.core does not exist
import xyz.redtorch.core.CoreRunConfiguration;
                        ^
/private/tmp/RedTorch/rt-strategy/src/test/java/xyz/redtorch/startegy/backtesting/StrategyDemoBacktesting.java:22: error: cannot find symbol
@SpringBootTest(classes = CoreRunConfiguration.class)
                          ^
  symbol: class CoreRunConfiguration
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rt-strategy:compileTestJava'.
> Compilation failed; see the compiler error output for details.

有开发者问项目是否还在更新,在这里统一回答一下

1.项目还在更新
2.接下来的变动比较大,会采用进程解耦,以便于提高策略调试效率
3.界面会重写,可能会降低刷新速率,比如从实时降低为500ms,但提高巨量数据下的稳定性,提高视觉效果和低分辨率兼容性
4.Gateway接口将会拆分为行情MD和交易TD
5.更新时间待定。。预计10月8日之前

dev分支访问不了网页

❯ java -jar  ./rt-front-web/build/libs/rt-front-web-0.1.war

顺利启动有如下的log

2018-11-21 09:50:41.113 [main] INFO  Jdk14Logger >>> Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.114 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.css] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.114 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.html] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.114 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.js] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.114 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.jsx] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.114 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.png] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.115 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.ttf] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.115 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.woff] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.115 [main] INFO  Jdk14Logger >>> Mapped URL path [/**/*.woff2] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.115 [main] INFO  Jdk14Logger >>> Root mapping to handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-11-21 09:50:41.292 [main] INFO  Jdk14Logger >>> Registering beans for JMX exposure on startup
2018-11-21 09:50:41.389 [main] INFO  Jdk14Logger >>> Undertow started on port(s) 9099 (http) with context path ''
2018-11-21 09:50:41.393 [main] INFO  Jdk14Logger >>> Started RtApplication in 3.675 seconds (JVM running for 4.091)
2018-11-21 09:50:41.394 [main] INFO  SocketIOServer >>> Session store / pubsub factory used: MemoryStoreFactory (local session store only)
2018-11-21 09:50:41.558 [main] INFO  SocketIOCommandLineRunner >>> SocketIO服务启动成功!
2018-11-21 09:50:41.558 [nioEventLoopGroup-2-1] INFO  SocketIOServer$1 >>> SocketIO server started at port: 9098

但是 不能通过
http://127.0.0.1:9099/static/html/index.html 访问
有如下错误

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Nov 21 09:51:23 CST 2018
There was an unexpected error (type=Not Found, status=404).
Not Found

master branch 没问题

行情订阅出错

在用dev版订阅行情时出错:
2018-10-24 12:12:05.612 [Thread-1053] INFO MdSpi >>> 接口ID-[JjDiofQNRVSojS_J_QQJOg] 名称-[ctpdemo] >>> 行情接口错误回报!ErrorID:77,ErrorMsg:CTP:无此功能,RequestID:0,isLasttrue

请教RedTorch的运行机制

如果我没理解错的话,CTP接口的订阅都需要有一个“容器”维护MdSpi与TdSpi对象的生命周期,而从源码我看到RedTorch用CtpGateway来维护,但却找不到是什么来维护CtpGateway对象。可否补充说明一下?

BaseConfig.Patch

``
diff --git a/src/main/java/xyz/redtorch/trader/base/BaseConfig.java b/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
index 293ee63..e6da1f1 100644
--- a/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
+++ b/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
@@ -1,9 +1,13 @@
package xyz.redtorch.trader.base;

+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.apache.commons.configuration2.CompositeConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
+import org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.slf4j.Logger;
@@ -16,19 +20,56 @@
public static CompositeConfiguration rtConfig;
static {
rtConfig = new CompositeConfiguration();

  •    try {
    
  •    	FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
    
  •    		    new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
    
  •    		    .configure(new Parameters().properties()
    
  •    		        .setFileName("RtConfig.properties")
    
  •    		        .setThrowExceptionOnMissing(true)
    
  •    		        .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
    
  •    		        .setIncludesAllowed(false));
    
  •    		PropertiesConfiguration propertiesConfiguration = builder.getConfiguration();
    
  •    		rtConfig.addConfiguration(propertiesConfiguration);
    
  •    } catch (ConfigurationException e) {
    
  •    	log.error("配置文件RtConfig.properties加载失败",e);
    
  •    	throw new Error("配置文件RtConfig.properties加载失败");
    
  •    }
    
  •   PropertiesBuilderParameters params =  new Parameters().properties()   
    
  •    .setThrowExceptionOnMissing(true)
    
  •    .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
    
  •    .setIncludesAllowed(false);
    
  •   if(!tryConfig(params,"file:./config/RtConfig.properties"))
    
  •   {
    
  •   	if(!tryConfig(params,"file:./RtConfig.properties"))
    
  •   	{
    
  •   		if(!tryConfig(params,"classpath:/config/RtConfig.properties"))
    
  •   		{
    
  •   			if(!tryConfig(params,"classpath:/RtConfig.properties"))
    
  •   			{
    
  •   				log.error("配置文件RtConfig.properties加载失败");
    
  •   	        	throw new Error("配置文件RtConfig.properties加载失败");
    
  •   			}
    
  •   		}
    
  •   	}
    
  •   }
    
  • }
  • static boolean tryConfig(PropertiesBuilderParameters params,String config_url_txt)
  • {
  •    try {
    
  •   	 URL configFileUrl = new URL(config_url_txt);
    
  •       FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
    
  •       		    new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
    
  •       		    .configure(params.setURL(configFileUrl));
    
  •       PropertiesConfiguration propertiesConfiguration = builder.getConfiguration();
    
  •       		rtConfig.addConfiguration(propertiesConfiguration);
    
  •       return true;
    
  •       } catch (ConfigurationException e) {
    
  •       	log.debug("配置文件RtConfig.properties加载失败",e);
    
  •       	return false;
    
  •       }catch (MalformedURLException e)
    
  •    	{
    
  •       	log.debug("配置文件RtConfig.properties加载失败",e);
    
  •       	return false;
    
  •    	}
    
    }
    }

📢准备弃用Ant Design前端框架,改为Microsoft Office UI Fabric

在过去的一段事件中很多朋友反映操作界面不够友好,无论是交互逻辑还是视觉感受,经过一段时间的总结,目前认为主要有两个方面原因,一是Ant Design字号过大,界面空间利用率不足,二是局限于单个html页面。除此之外,dva的开发模式过于复杂,学习成本太高,函数命名混乱,不利于推广和二次开发。因此接下来考虑采用MobX替换Dva,使用Microsoft Office UI Fabric统一UI样式开发Web App。同时推进使用Electron开发的统一样式的支持多窗口的Desktop App。

SpringApplication.run(ZeusApplication.class, args) 执行出错

因为登录不成功,有404错误。所以尝试在ZeusApplication中执行main函数,里面就是 SpringApplication.run(ZeusApplication.class, args);
执行出错:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zeusApplication': Unsatisfied dependency expressed through field 'tokenService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tokenServiceImpl': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'rt.web.username' in value "${rt.web.username}"

请注意,页面渲染仍然存在性能问题

当前问题:

浏览器不支持多线程,因此存在以下两种情况

  1. 当委托数据超过5000笔,首次连接接口会有明显的卡滞

  2. 日志数量超过8000笔,会造成页面卡死

已经使用的临时的解决方案:

定时刷新,数据仍然通过websocket推送至前端,前端通过定时器刷新,避免频繁刷新

长期计划:

使用React重构前端页面,根据功能进行拆解

最后一步保命的手段

软件使用过程中总会有各种各样的异常,而做为最后一步保�命的手段,我觉得“全部平掉”应该是一个一下就可以保命的东西。
然后没有这样一个命令,比如:

  1. 账号有多个
  2. 每个账号有多个持仓
  3. 有多单有空单
  4. 有需要“平今”的,有需要“平昨”的

所有的这些,都是程序擅长的事情,所以如果有一个“一键全平”的功能,可以在最关键的时候救一命,不然到时手忙脚乱,就不好搞了。

几个安全隐患

有几个安全隐患,希望考虑一下

  1. mongo 帐号密码放在配置里而且是明文,而 jar 是可以直接解开的,所以如果机器会攻破,打开这个 jar ,就什么都有了。
  2. 交易账号放在 mongo 里而且是明文,mongo 万一被攻破,就可以交易了。
  3. web 页面的权限太高,像启动/停止策略/直接交易 这样危险的操作,万一哪个 api 有个漏洞,就危险了。我觉得 web 最好只有“看”的权限,所有操作的权限都放到后面去。

接口实现过于耦合

目前正在使用redTorch实现一个用于币圈的量化交易. 但是在实现过程中发现现有接口的耦合度太高了,很难定制实现自己的业务逻辑, 希望作者予以改进,谢谢.
建议:
方案1: 直接使用spring的依赖注入方式实现接口与实现代码的绑定.

  • 在实现代码Impl类上使用@component注解声明服务;
  • 在使用字段上使用@Autowired注解;
    这样的好处是代码相对标准,但是过于依赖spring ioc. 造成RunBacktestingForStrategyBK类似的回测方法不能直接使用main方法,而只能使用spring boot的测试用例模式

方案2: 使用Factory模式创建一个工厂类,统一初始化各个接口的实现.

关于CTP帐号登录问题

在项目正常启动后,通过web页面添加一个网关后点击连接,假如此时所填写的密码错误,目前项目会一直在循环的进行登录,CTP返回 交易接口登录回报错误 错误ID:3,错误信息:CTP:不合法的登录 ,最终会出现 交易接口登录回报错误 错误ID:75,错误信息:CTP:连续登录失败次数超限,登录被禁止 。
是否可以做个登录失败次数的限制,请问这个问题如何解决,谢谢!

导入项目所出现的几个问题

导入项目,启动不了,提示如下:
2019-08-24 16:23:37.266 [main ] [WARN ] jsr >>> UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used

我是win7操作系统,按照GitHub文档步骤安装,
1,安装MongoDB
2,安装vs2013x64运行库
3,安装JDK11 x64并设置环境变量(JAVA_HOME=C:\Java\jdk-11.0.2 ,PATH=%JAVA_HOME%\bin)
4,eclipse-jee-2019-06-R-win32-x86_64.zip
在Eclipse中使用File->Import->Existing Gradle Projects导入本项目
5,通过rt-node-master中的RtNodeMasterApplication.java启动主节点
启动主节点卡在这个问题,请不吝指教,那里步骤有问题,如何顺利项目运行?谢谢

再次run一下,提示如下:

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////
:: Spring Boot :: (v2.1.5.RELEASE)

2019-08-24 16:34:32.423 [main ] [WARN ] jsr >>> UT026010: Buffer pool was not set on WebSocketDeploymentInfo, the default pool will be used
2019-08-24 16:34:33.777 [main ] [ERROR] LoggingFailureAnalysisReporter >>>


APPLICATION FAILED TO START


Description:

Web server failed to start. Port 9099 was already in use.

Action:

Identify and stop the process that's listening on port 9099 or configure this application to listen on another port.

image

FastEvent使用的一个问题

FastEvent 中Order Trade等对象都是预先New分配的,在CoreEngineServiceImpl类中onOrder方法直接使用 orderMap.put(order.getRtOrderID(), order);
缓存该Order。
这会导致如果RingBuf重复使用的时候, orderMap之前的order的值会被后续的事件给修改掉。虽然你目前缓存buf是65536 , 对于order没有类似问题, 但对于tick可能会有隐患。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.