构建基于 Java 的股票交易应用程序,需要使用技术指南

发布于 2024-07-25 18:36:53 字数 552 浏览 31 评论 0 原文

我正在用 Java(带有 jQ​​uery 前端)构建一个需要与第三方应用程序通信的应用程序。 最多需要每两秒更新一次界面。

使用彗星是个好主意吗? 如果是这样,它们如何融入图片中?

我还可以使用哪些其他方法/技术来使应用程序变得更好?

该应用程序将从第三方应用程序轮询股票价格,将其写入数据库,然后每秒将其推送到前端,对于轮询,我有一个每秒运行的计时器来调用第三方应用程序获取数据,我然后必须使用 JSP 或其他东西将其显示到前端,

此时我不确定是否应该使用 servlet 将其写到前端,您会推荐什么? 我该怎么办?

有什么新技术可以代替 servlet 使用吗?

我也在使用 Berkeley db 来存储数据,你认为这是一个不错的选择吗? 使用伯克利有什么缺点(如果有的话)……

我完全无能为力,所以任何建议将不胜感激。

谢谢!

编辑:我计划这样做,以便桌面应用程序不断从第三部分轮询并写入数据库,而网络应用程序仅从数据库读取和显示,这将减少网络应用程序的负载及其所需的一切do是从db读取的。

I am building an application in Java (with a jQuery frontend) that needs to talk to a third party application. it needs to update the interface every two seconds at the most.

Would it be a good idea to use comets? If so, how do they fit into the picture?

What other means/technologies can I use to make the application better?

The application will poll stock prices from a third party app, write it to a database and then push it to the front end every second, for the polling, I have a timer that runs every second to call the third party app for data, I then have to display it to the front end using JSP or something,

well at this point im not sure if I should use a servlet to write this out to the front end, what would you recommend? how should I go about it?

is there any new technology that I can use instead of servlets?

I am also using Berkeley db to store the data, do you think its a good option? what would be the drawbacks, if any for using berkeley..

im absolutely clueless so any advice will be much appreciated.

Thanks!

edit : I am planning to do this so that a deskop app constantly polls from the thrid part and writes to the database and a web app only reads and displays from the database, this will reduce the load on the web app and all it has to do is read from db.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

〗斷ホ乔殘χμё〖 2024-08-01 18:36:53

考虑一下使用 Web 应用程序框架而不是 Servlet - 除非它是一个只有一个屏幕的非常基本的项目。 不幸的是,Java 世界中有很多东西,它可能有点像雷区。 坚持使用 SpringMVC 或 Struts 2,最糟糕的部分是设置它们,但是看一下示例应用程序以及一两个教程,然后从那里开始工作。

http://www.springsource.org/about

http://struts.apache.org/2.x/index.html

另一种选择是使用模板框架例如 Appfuse 即可启动并运行,而无需将大量框架集成在一起,请参阅:

http://appfuse.org/display/APF/AppFuse+QuickStart

它为您提供了一个模板来设置 SpringMVC,其中 MySQL 作为数据库,Spring 作为 POJO 框架。 这可能是开始、建立和构建原型的快速方法。

从 2 秒的延迟要求来看,明智的做法是查看某种 AJAX 框架 - JQuery 或 Prototype/Scriptaculous 都是不错的起点。

http://jquery.com/

http://www.prototypejs.org/

就其他使事情变得更好的技术而言,您需要考虑构建系统,Ant/Maven 与 Maven 都很好,稍微复杂一点他们俩。

http://ant.apache.org/

http://maven.apache.org/download.html

另外,请考虑使用 JUnit 来测试应用程序。 您可能需要考虑使用 Selenium 进行前端的功能测试。

http://www.junit.org

http://seleniumhq.org/

Take a look at using a web application framework instead of Servlets - unless it's a really basic project with one screen. There are lots in the Java world unfortunately and it can be a bit of a minefield. Stick with maybe SpringMVC or Struts 2, the worst part is setting these up, but take a look at a sample application plus a tutorial or two and work from there.

http://www.springsource.org/about

http://struts.apache.org/2.x/index.html

Another option to look at is using a template framework such as Appfuse to get yourself up and running without having to integrate a lot of the framework together, see:

http://appfuse.org/display/APF/AppFuse+QuickStart

It provides you with a template to setup SpringMVC with MySQL as a database plus Spring as an POJO framework. It may be a quick way to get started and up and building a prototype.

Judging by your latency requirement of 2 seconds it would be wise to look at some sort of AJAX framework - JQuery or Prototype/Scriptaculous are both good places to start.

http://jquery.com/

http://www.prototypejs.org/

In terms of other technoloqies to make things better you will want to consider a build system, Ant/Maven are fine with Maven the slightly more complex of the two.

http://ant.apache.org/

http://maven.apache.org/download.html

Also, consider JUnit for testing the application. You might want to consider Selenium for functional testing of the front end.

http://www.junit.org

http://seleniumhq.org/

浅忆 2024-08-01 18:36:53

这真的是股票交易应用程序吗? 或者只是一个股票价格显示应用程序? 我这么问是因为从你的描述来看,这听起来像是后者。

每秒轮询数据有多重要? 具体来说,如果某些民意调查晚了一两秒,会有什么影响吗?

如果您正在构建股票交易应用程序(时间安排绝对至关重要),或者如果您无法承受轮询的延迟,我建议您看一下 Java Real Time 解决方案之一:

除此之外,我唯一的建议是你坚持良好的 OO 设计实践。 例如,使用 DAO 写入数据库,这样,如果您发现 Berkeley DB 不太适合您,您可以相对轻松地切换到关系数据库系统。 它还使您可以轻松地转向某些数据库分区解决方案(例如,Hibernate Shards )如果您决定需要它。

虽然我可能有自己的技术偏好(例如,我会选择 Spring MVC 对于前端,正如其他人提到的,我会尝试使用 Hibernate 来实现持久性),我真的不能说这些会比其他技术更好。 如果符合要求,请选择您熟悉的东西。

Is this really a stock trading application? Or just a stock price display application? I am asking because from your description it sounds like the latter.

How critical is it that data is polled every second? Specifically would it matter if some polls are a second or two late?

If you are building a stock trading application (where the timing is absolutely critical), or if you cannot afford to be delayed on your polling, I'd recommend you have a look at one of the Java Real Time solutions:

Other than that, my only advice is that you stick to good OO design practices. For instance, use a DAO to write to your database, this way, if you find that Berkeley DB isn't quite for you, you can switch to a relational database system with relative ease. It also makes it easy for you to move on to some database partitioning solutions (e.g., Hibernate Shards) if you decide you need it.

While I may have my own technology preferences (for instance, I'd choose Spring MVC for the front end as others have mentioned, I'd try and use Hibernate for persistance), I really cannot claim that these would be better than other technologies out there. Go with something you are familiar with, if it fits the bill.

纸伞微斜 2024-08-01 18:36:53

我认为在选择注重可扩展性和可扩展性的技术之前,您应该专注于架构设计。 一旦架构设计到位,您就可以查看可用的内容和需要构建的内容,所有这些都应该非常明显。

虽然不能直接比较,但看看 Google、eBay 和 YouTube 如何处理他们面临的可扩展性问题。 虽然交易系统不会遇到这些人在用户数量方面遇到的问题,但您会在数据量和及时处理价格变动方面遇到类似的问题。

伦敦证交所 (LSE) 拥有 3000 个名称,将其乘以全球大约 10 个受欢迎的交易所,您将获得在每个市场开放期间不断更新的大量数据。 为了让您了解从单个交易所捕获数据所涉及的内容,请查看 http://kx.com/

从数据库的角度来看,您将需要一些工业实力,允许集群并具有可靠的复制 - 对我来说这意味着 Oracle。 您还想看看时间序列数据库设计,根据我的经验,这是最好的构建此类系统的方法。

相同的扩展和可靠性要求将适用于您的应用程序服务器,JBoss 是那里的逻辑选择,尽管我也会考虑 OSGi Spring Server (http://www.springsource.com/products/dmserver),因为它的轻量级特性可以使其速度更快。

您还需要 Apache 服务器来实现负载平衡并提供静态内容 - 快速 Google 一下就会找到大量相关信息,因此我不会在这里重复。

也忘记轮询,它无法扩展。 考虑使用消息传递和消费者进程进行跨进程通信,使用事件和工作线程进行进程内通信。 这两种技术都实现了自然的负载平衡效果,可以根据需要通过增加消费者进程或工作线程的数量来调整。

恕我直言,静态前端也无法满足要求。 看看市场上已有的产品 - CNC Markets、IG Index 等都有令人印象深刻的实时交易应用程序。

顺便说一句,假设这是一个商业项目,并且无意让整个事情变得沮丧,像 CNC Markets、IG Index 等公司通过交易费用赚钱,该软件是达到目的的手段,你可以得到只需拥有一个帐户即可免费访问。 交易软件的另一个目标是商业机构,例如银行、投资经理等。在花费太多时间和精力之前,我希望有一个非常严密的计划来说明如何打入这些市场。

I think you should focus on your architectural design before picking technologies with a focus on scalability and extendability. Once an architectural design is in place you can look to see what's available and what you need to build, all of which should be pretty obvious.

While not directly comparable look at how Google, eBay and YouTube deal with the scalability problems they face. While a trading system won't have the issues these guys have with sheer numbers of users, you'll get similar problems with data volumes and being able to process price ticks in a timely fashion.

The LSE has getting on for 3000 names, multiply this by the 10 or so popular exchanges round the world and you've got a lot of data being updated continuously over the period each market is open. To give you an idea of what involved in capturing data from a single exchange take a look at http://kx.com/.

From a database perspective you've going to need something industrial strength that allows clustering and has reliable replication - for me this means Oracle. You also want to look at a Time-series Database Design, which in my experience is the best way to build this sort of system.

The same scaling and reliability requirements will apply to your app servers, with JBoss being the logical choice there, although I'd also consider the OSGi Spring Server (http://www.springsource.com/products/dmserver) as its lightweight nature could make it faster.

You'll also want Apache servers for load balancing and to serve static content - a quick Google will turn up stacks of information on that so I won't repeat it here.

Also forget polling, it doesn't scale. Look at using messaging and consumer processes for the cross-process communication, events and worker threads for the in-process communication. Both techniques achieve a natural load balancing effect that can be tuned by increasing the number of consumer processes or worker threads as need be.

Also a static front-end isn't going to cut the mustard, IMHO. Take a look at what's out in the market already - CNC Markets, IG Index, etc all have pretty impressive real-time trading apps.

As an aside, assuming this is a commercial project and not meaning to put a downer on the whole thing, companies like CNC Markets, IG Index, etc make their money from trading fees, the software being a means to an end, which you get access to for free simply by having an account. The other target for the trading software is commercial institutions such as the banks, investment managers, etc. I'd want a pretty watertight plan for how I was going to break into either of these markets before expending too much time and effort.

失退 2024-08-01 18:36:53

PostgreSQL 可能是正确的数据库。 它比 MySQL 更具进取性。 至于前端,有很多东西可以放在 servlet、SpringMVC、Tapestry 等“之上”。 实际的 servlet 实现将对您隐藏。

许多人会建议,使用 Spring 来配置应用程序并进行任何依赖项注入可能不是一个坏建议。

如果您正在寻找更轻量级的东西,您可以考虑 grails。 它发展很快并变得成熟。

但实际上,在不知道这是什么样的“生产”环境的情况下,很难推荐东西。 我们谈论的是大量交易吗? (当然,这是一个股票交易程序,但它是一个只有少量用户的模拟等等...)提出建议很有趣,但如果你是认真的,我不确定我会开始一个像这样的大型项目这。 有很多方法可以做到这一点,也有很多方法会做错。

PostgreSQL is probably the right database. It's a little more enterprisy than MySQL. As for the front-end, there's lots of stuff that can go "on top" of servlets, SpringMVC, Tapestry, and so on and so forth. The actual servlet implementation will be hidden from you.

Many will suggest, and it's probably not a bad suggestion to use Spring to configure the application and to do any dependency injection.

If you're looking for something a little more lightweight, you might consider grails. It's quick to develop with and becoming mature.

Really though, it's kind of hard to recommend things without knowing what kind of "production" environment this would be. Are we talking lots of transactions? (sure, it's a stock trading program, but is it a simulation with a small number of users etc...) It's fun to suggest things, but if you're serious, I'm not sure I would start a major project like this. There are lots of ways to do this, and lots of ways to do this wrong.

余生一个溪 2024-08-01 18:36:53

您的目的是构建一个显示实时数据的 Web UI,例如:时间、市场数据等...

我个人使用的技术之一是 Web Firm Framework,一个基于 Apache License 2.0 的开源框架。 它是一个用于构建 Web UI 的 Java 服务器端框架。 对于每个标签和 属性有一个对应的java类。 我们只是使用 Java 代码而不是纯 HTML 和 JavaScript 构建 UI。 优点是我们在服务器标签和内容中所做的任何更改。 属性对象将反映到浏览器页面,而无需客户端的任何显式触发。 在您的情况下,我们可以简单地使用 ScheduledExecutorService 在 UI 中进行数据更改。

例如:

AtomicReference<BigDecimal> oneUSDToOneGBPRef = new AtomicReference<>(new BigDecimal("0.77"));

SharedTagContent<BigDecimal> amountInBaseCurrencyUSD = new SharedTagContent<>(BigDecimal.ZERO);

Div usdToGBPDataDiv = new Div(null).give(dv -> {

    //the second argument is formatter
    new Span(dv).subscribeTo(amountInBaseCurrencyUSD, content -> {
        BigDecimal amountInUSD = content.getContent();
        if (amountInUSD != null) {
            return new SharedTagContent.Content<>(amountInUSD.toPlainString(), false);
        }
        return new SharedTagContent.Content<>("-", false);
    });

    new Span(dv).give(spn -> {
        new NoTag(spn, " USD to GBP: ");
    });

    new Span(dv).subscribeTo(amountInBaseCurrencyUSD, content -> {

        BigDecimal amountInUSD = content.getContent();
        if (amountInUSD != null) {

            BigDecimal oneUSDToOneGBP = oneUSDToOneGBPRef.get();

            BigDecimal usdToGBP = amountInUSD.multiply(oneUSDToOneGBP);

            return new SharedTagContent.Content<>(usdToGBP.toPlainString(), false);
        }
        return new SharedTagContent.Content<>("-", false);
    });
});

amountInBaseCurrencyUSD.setContent(BigDecimal.ONE);

//just to test
// will print <div><span>1</span><span> USD to GBP: </span><span>0.77</span></div>
System.out.println(usdToGBPDataDiv.toHtmlString());


ScheduledExecutorService scheduledExecutorService =
        Executors.newScheduledThreadPool(1);

Runnable task = () -> {

    //dynamically get USD to GBP exchange value
    oneUSDToOneGBPRef.set(new BigDecimal("0.77"));

    //to update latest converted value
    amountInBaseCurrencyUSD.setContent(amountInBaseCurrencyUSD.getContent());
};
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(task, 1, TimeUnit.SECONDS);

//to cancel the realtime update
//scheduledFuture.cancel(false);

要实时显示时间,您可以使用 SharedTagContentContentFormatter 显示特定时区的时间。 您可以观看此视频以更好地理解。 您还可以从此 github 存储库下载示例项目。

Your intention is to build a web UI which shows realtime data eg: time, market data etc...

One of the technologies I have personally used is Web Firm Framework, an opensource framework under Apache License 2.0. It is a java server side framework to build web UI. For each and every tag & attribute there is a corresponding java class. We are just building the UI with Java code instead of pure HTML and JavaScript. The advantage is whatever changes we are making in the server tag & attribute objects will be reflected to the browser page without any explicit trigger from the client. In your case we can simply use ScheduledExecutorService to make data changes in the UI.

Eg:

AtomicReference<BigDecimal> oneUSDToOneGBPRef = new AtomicReference<>(new BigDecimal("0.77"));

SharedTagContent<BigDecimal> amountInBaseCurrencyUSD = new SharedTagContent<>(BigDecimal.ZERO);

Div usdToGBPDataDiv = new Div(null).give(dv -> {

    //the second argument is formatter
    new Span(dv).subscribeTo(amountInBaseCurrencyUSD, content -> {
        BigDecimal amountInUSD = content.getContent();
        if (amountInUSD != null) {
            return new SharedTagContent.Content<>(amountInUSD.toPlainString(), false);
        }
        return new SharedTagContent.Content<>("-", false);
    });

    new Span(dv).give(spn -> {
        new NoTag(spn, " USD to GBP: ");
    });

    new Span(dv).subscribeTo(amountInBaseCurrencyUSD, content -> {

        BigDecimal amountInUSD = content.getContent();
        if (amountInUSD != null) {

            BigDecimal oneUSDToOneGBP = oneUSDToOneGBPRef.get();

            BigDecimal usdToGBP = amountInUSD.multiply(oneUSDToOneGBP);

            return new SharedTagContent.Content<>(usdToGBP.toPlainString(), false);
        }
        return new SharedTagContent.Content<>("-", false);
    });
});

amountInBaseCurrencyUSD.setContent(BigDecimal.ONE);

//just to test
// will print <div><span>1</span><span> USD to GBP: </span><span>0.77</span></div>
System.out.println(usdToGBPDataDiv.toHtmlString());


ScheduledExecutorService scheduledExecutorService =
        Executors.newScheduledThreadPool(1);

Runnable task = () -> {

    //dynamically get USD to GBP exchange value
    oneUSDToOneGBPRef.set(new BigDecimal("0.77"));

    //to update latest converted value
    amountInBaseCurrencyUSD.setContent(amountInBaseCurrencyUSD.getContent());
};
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(task, 1, TimeUnit.SECONDS);

//to cancel the realtime update
//scheduledFuture.cancel(false);

For displaying time in real-time you can use SharedTagContent<Date> and ContentFormatter<Date> to show time in specific timezone. You can watch this video for better understanding. You can also download sample projects from this github repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文