程序员的量化交易之路(25)--Cointrader之MarketData市场数据实体(12)
转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top/
前面一节我们说到了远端事件。其中,市场数据就属于远端事件。市场数据有什么?我们通过代码来回答这个问题:
package org.cryptocoinpartners.schema;import javax.annotation.Nullable;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;import org.joda.time.Instant;/*** @author Tim Olson*/
@Entity //实体,在数据库中会创建表格
public abstract class MarketData extends RemoteEvent {protected MarketData(Instant time, @Nullable String remoteKey, Market market) {this(time, Instant.now(), remoteKey, market);}protected MarketData(Instant time, Instant timeReceived, String remoteKey, Market market) {super(time, timeReceived, remoteKey);this.market = market;}@ManyToOne(optional = false)public Market getMarket() {return market;}// JPAprotected MarketData() {super();}protected void setMarket(Market market) {this.market = market;}private Market market;//市场
}
市场数据里面只有一个成员,市场。也即是说市场数据是某一时刻的市场。
我们接下来看看市场又有什么数据,Market。
我们通过注释代码来学习。
package org.cryptocoinpartners.schema;import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.NoResultException;
import javax.persistence.PostPersist;
import javax.persistence.Table;
import javax.persistence.Transient;import org.cryptocoinpartners.enumeration.FeeMethod;
import org.cryptocoinpartners.util.PersistUtil;
import org.cryptocoinpartners.util.RemainderHandler;/*** Represents the possibility to trade one Asset for another at a specific Exchange.** @author Tim Olson*/
@Entity //表格
@Cacheable // 缓存
@NamedQuery(name = "Market.findByMarket", query = "select m from Market m where exchange=?1 and listing=?2") // 命名查询
@Table(indexes = { @Index(columnList = "exchange"), @Index(columnList = "listing"), @Index(columnList = "active") }) //编织索引
public class Market extends EntityBase {public static Collection<Market> findAll() {//查询所有市场数据return PersistUtil.queryList(Market.class, "select m from Market m");}/** adds the Market to the database if it does not already exist */public static Market findOrCreate(Exchange exchange, Listing listing) {return findOrCreate(exchange, listing, listing.getPriceBasis(), listing.getVolumeBasis());}@PostPersistprivate void postPersist() {//PersistUtil.detach(this);}
//查询或创建市场数据public static Market findOrCreate(Exchange exchange, Listing listing, double quoteBasis, double volumeBasis) {// final String queryStr = "select m from Market m where exchange=?1 and listing=?2";try {return PersistUtil.namedQueryOne(Market.class, "Market.findByMarket", exchange, listing);} catch (NoResultException e) {final Market ml = new Market(exchange, listing, quoteBasis, volumeBasis);PersistUtil.insert(ml);return ml;}}/**@return active Markets for the given exchange*/public static Collection<Market> find(Exchange exchange) {return PersistUtil.queryList(Market.class, "select s from Market s where exchange=?1 and active=?2", exchange, true);}/**@return active Markets for the given listing*/public static Collection<Market> find(Listing listing) {return PersistUtil.queryList(Market.class, "select s from Market s where listing=?1 and active=?2", listing, true);}@ManyToOne(optional = false)public Exchange getExchange() {return exchange;}@ManyToOne(optional = false)public Listing getListing() {return listing;}@Basic(optional = false)public double getPriceBasis() {return listing.getPriceBasis() == 0 ? priceBasis : listing.getPriceBasis();}@Transientpublic int getScale() {int length = (int) (Math.log10(getPriceBasis()));return length;}@Basic(optional = false)public double getVolumeBasis() {return listing.getVolumeBasis() == 0 ? volumeBasis : listing.getVolumeBasis();}/** @return true iff the Listing is currently traded at the Exchange. The Market could have been retired. */public boolean isActive() {return active;}@Transientpublic Asset getBase() {return listing.getBase();}@Transientpublic Asset getQuote() {return listing.getQuote();}@Transientpublic int getMargin() {return listing.getMargin() == 0 ? exchange.getMargin() : listing.getMargin();}@Transientpublic double getFeeRate() {return listing.getFeeRate() == 0 ? exchange.getFeeRate() : listing.getFeeRate();}@Transientpublic FeeMethod getMarginFeeMethod() {return listing.getMarginFeeMethod() == null ? exchange.getMarginFeeMethod() : listing.getMarginFeeMethod();}@Transientpublic FeeMethod getFeeMethod() {return listing.getFeeMethod() == null ? exchange.getFeeMethod() : listing.getFeeMethod();}@Transientpublic double getMultiplier() {return listing.getMultiplier();}@Transientpublic double getTickValue() {return listing.getTickValue();}@Transientpublic double getContractSize() {return listing.getContractSize();}@Transientpublic double getTickSize() {return listing.getTickSize();}@Transientpublic Asset getTradedCurrency() {return listing.getTradedCurrency();}@Transientpublic String getSymbol() {return exchange.toString() + ':' + listing.toString();}@Overridepublic String toString() {return getSymbol();}public static Market forSymbol(String marketSymbol) {for (Market market : findAll()) {if (market.getSymbol().equalsIgnoreCase(marketSymbol))return market;}return null;}public static List<String> allSymbols() {List<String> result = new ArrayList<>();List<Market> markets = PersistUtil.queryList(Market.class, "select m from Market m");for (Market market : markets)result.add((market.getSymbol()));return result;}public static class MarketAmountBuilder {public DiscreteAmount fromPriceCount(long count) {return priceBuilder.fromCount(count);}public DiscreteAmount fromVolumeCount(long count) {return volumeBuilder.fromCount(count);}public DiscreteAmount fromPrice(BigDecimal amount, RemainderHandler remainderHandler) {return priceBuilder.fromValue(amount, remainderHandler);}public DiscreteAmount fromVolume(BigDecimal amount, RemainderHandler remainderHandler) {return volumeBuilder.fromValue(amount, remainderHandler);}public MarketAmountBuilder(double priceBasis, double volumeBasis) {this.priceBuilder = DiscreteAmount.withBasis(priceBasis);this.volumeBuilder = DiscreteAmount.withBasis(volumeBasis);}private final DiscreteAmount.DiscreteAmountBuilder priceBuilder;private final DiscreteAmount.DiscreteAmountBuilder volumeBuilder;}public MarketAmountBuilder buildAmount() {if (marketAmountBuilder == null)marketAmountBuilder = new MarketAmountBuilder(getPriceBasis(), getVolumeBasis());return marketAmountBuilder;}// JPAprotected Market() {}protected void setExchange(Exchange exchange) {this.exchange = exchange;}protected void setListing(Listing listing) {this.listing = listing;}protected void setActive(boolean active) {this.active = active;}protected void setPriceBasis(double quoteBasis) {this.priceBasis = quoteBasis;}protected void setVolumeBasis(double volumeBasis) {this.volumeBasis = volumeBasis;}private Market(Exchange exchange, Listing listing, double priceBasis, double volumeBasis) {this.exchange = exchange;this.listing = listing;this.priceBasis = priceBasis;this.volumeBasis = volumeBasis;this.active = true;}private Exchange exchange;//交易所private Listing listing;//挂牌清单private double priceBasis;//基准价格private double volumeBasis;//基准量private boolean active;//是否活跃private MarketAmountBuilder marketAmountBuilder;
}
相关文章:
滴滴开源在2019:十大重点项目盘点,DoKit客户端研发助手首破1万Star
整理 | Jane出品 | AI科技大本营(ID;rgznai100)2018 年,科技企业纷纷布局开源战略后迎来的第一个“丰收年”。但对滴滴来说,2019 年才迎来其第一波开源小高潮。自2017年滴滴零星开源数个项目后,滴滴开源项目…

PE文件和COFF文件格式分析——签名、COFF文件头和可选文件头2
之前的博文中介绍了IMAGE_FILE_HEADER结构,现在来讨论比较复杂的“可选文件头”结构体。(转载请指明来自breaksoftware的csdn博客)先看下其声明 typedef struct _IMAGE_OPTIONAL_HEADER {//// Standard fields.//WORD Magic;...DWORD BaseOfData; // not e…

9月第1周安全回顾 IM安全威胁严重 企业增加无线安全投入
本文同时发表在:[url]http://netsecurity.51cto.com/art/200709/55180.htm[/url]本周(0827至0902)安全方面值得关注的新闻集中在安全产品、即时通信安全、无线安全和安全市场。安全产品:Intel vPro技术逐渐升温,关注指…

centos下LAMP之源码编译安装httpd
1 最好先安装组件[rootlocalhost ~]# yum groupinstall additional development [rootlocalhost ~]# yum groupinstall development tool2 安装ap1.5.2r(Apache Portable Runtime),安装apr-util 1.5.4工具[rootlocalhost ~]wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2…

PE文件和COFF文件格式分析——签名、COFF文件头和可选文件头3
《PE2》中介绍了一些可选文件头中重要的属性,为了全面起见,本文将会讲解那些不是那么重要的属性。虽然不重要,但是还是可以发现很多好玩的情况。首先看一下32位的可选文件头详细定义。(转载请指明来源于breaksoftware的CSDN博客&a…

高效决策的三个关键
“领导者的责任,归纳起来,主要是出主意、用干部两件事。”***的这句话高度概括了领导者的关键任务,而这两件事都有一个共同的核心——决策。决策是管理者的天职,与其说这是他们的权力,不如说是一种责任。每一个经理人&…
开发者都想收藏的深度学习脑图,我们抢先曝光了!
可以看到,通过机器学习技术,软件或服务的功能和体验得到了质的提升。比如,我们甚至可以通过启发式引擎智能地预测并调节云计算分布式系统的节点压力,以此改善服务的弹性和稳定性,这是多么美妙。而对移动平台来说&#…

Cookie 位置_无需整理
为什么80%的码农都做不了架构师?>>> Cookie 位置 C:\Users\admin\AppData\Roaming\Microsoft\Windows\Cookies 转载于:https://my.oschina.net/Majw/blog/464018

PE文件和COFF文件格式分析——节信息
在《PE文件和COFF文件格式分析——签名、COFF文件头和可选文件头3》中,我们看到一些区块的信息都有偏移指向。而我们本文讨论的节信息是没有任何偏移指向的,所以它是紧跟在可选文件头后面的。(转载请注明来源于breaksoftware的csdn博客&#…

强悍!使用Flash和Silverlight制作控件
Silverlight已经发布了正式版本,我也到网站下载了一个并看看,突然发现了他的例子中包含了这个公司。NETiKA TECH。之所以说他强,是因为他尽然使用Flash和Silverlight制作了仿造WinForm的控件,包括:常见的控件ÿ…

《评人工智能如何走向新阶段》后记(再续8)
由AI科技大本营下载自视觉中国2019.12.13 81.近来一波人工智能热潮是在大数据的海量样本及超强计算能力两者支撑下形成的。所以说这一波人工智能是由大数据喂养出来的。这时的机器智能在感知智能和计算智能等一些具体问题上已经达到甚至超越人类水平,目前在语音识别…

Hadoop集群安全性:Hadoop中Namenode单点故障的解决方案及详介AvatarNode
2019独角兽企业重金招聘Python工程师标准>>> 正如大家所知,NameNode在Hadoop系统中存在单点故障问题,这个对于标榜高可用性的Hadoop来说一直是个软肋。本文讨论一下为了解决这个问题而存在的几个solution。 1. Secondary NameNode 原理&#…

PE文件和COFF文件格式分析——RVA和RA相互计算
之前几节一直是理论性质的东西非常多。本文将会讲到利用之前的知识得出一个一个非常有用的一个应用。(转载请指明来源于breaksoftware的csdn博客) 首先我们说下磁盘上A.exe文件和正在内存中运行的A.xe之间的关系。当我们双击A.exe后,A.exe会运…

《评人工智能如何走向新阶段》后记(再续9)
由AI科技大本营下载自视觉中国2019.12.16 96. 近日《Nature》杂志推荐2019年度10大科学进展的杰出论文,其中一篇是有关人工智能的,谈采用深度学习/强化学习算法来训练四足机器狗ANYmal,使它能快速爬起来。该文谈到,在反复训练下&…

RTX组织架构刷新出现了问题
今天发现RTX的组织架构刷新出现了问题。按照网络上的方法什么的把什么配置文件的IP地址改啊改啊。还是没有用。也TELNET了8010端口,也没有用。其实这样的方法之前把服务程序装在另一台机器上倒是可以的。有点麻烦的了。呵呵不知道各位博友有没有解决的好方法啊。呵呵…
一个最简单的通过WireShark破解SSL加密网络数据包的方法
原文地址: http://article.yeeyan.org/view/530101/444688 一般来说,我们用WireShark来抓取包进行分析是没有多大问题的。但这里有个问题是,如果你碰到的是用SSL/TLS等加密手段加密过的网络数据的时候,往往我们只能束手无策。在过…

PE文件和COFF文件格式分析——导出表
在之前的《PE可选文件头》相关博文中我们介绍了可选文件头中很多重要的属性,而其中一个非常重要的属性是(转载请指明来源于breaksoftware的CSDN博客) IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; 该数组保存了…
将Quartz.NET集成到 Castle中
Castle是针对.NET平台的一个开源项目,从数据访问框架ORM到IOC容器,再到WEB层的MVC框架、AOP,基本包括了整个开发过程中的所有东西,为我们快速的构建企业级的应用程序提供了很好的服务.具体可参看TerryLee的Castle 开发系列文章。 …

《评人工智能如何走向新阶段》后记(再续10)
本文由AI科技大本营下载自视觉中国106.百度自研的飞桨(Paddle paddle)框架是中国自研的首个开源产业极人工智能深度学习框架,目前飞桨已累计服务150多万开发者,在定制化训练平台上企业用户超过6.5万,发布了16.9万模型&…

水管工游戏 (深搜)
水管工游戏 本题依然是采用搜索,深搜,广搜都可以,本代码采用深搜,此题在搜索时需要增加一些判断条件以及下一步要搜索的位置即可。 代码如下: #include<stdio.h> int a[51][51]; int book[51][51],n,m,flag0,top…

PE文件和COFF文件格式分析——导出表的应用——一种插件模型
可能在很多人想想中,只有DLL才有导出表,而Exe不应该有导出表。而在《PE文件和COFF文件格式分析——导出表》中,我却避开了这个话题。我就是想在本文中讨论下载Exe中存在导出表的场景。(转载请指明出于breaksoftware的csdn博客&…

IBatis.Net学习笔记九--动态选择Dao的设计分析
在IBatis.Net中可以通过配置文件动态选择数据库、动态选择Dao对象。Dao对象也就是操作数据库的类,通过配置文件我们可以选择DataMapper的方式、Ado的方式、NHibernet的方式以前其他第三方的方式来操作数据库。有利于系统的灵活性和可扩展性。通过分析动态选择Dao的设…
Pytorch和Tensorflow,谁会笑到最后?
作者 | 土豆变成泥来源 | 知秋路(ID:gh_4a538bd95663)【导读】作为谷歌tensorflow某项目的Contributor,已经迅速弃坑转向Pytorch。目前Tensorflow还没有被Pytorch比下去,但之后极大概率被比下去。01 在学术界Pytorch已经超越Tenso…

HTTP请求的过程
HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1. 建立TCP连接在HTTP工作开始之前,Web浏览器首先要通过网络与Web服务器建立连接,该连接是通过TCP来完成的,该协议与IP协议共同…

JSTL+EL表达式方法获取Oracle的Clob字段内容
我们在页面获得数据的时候一般的类型还是很好获得的,但是一遇到Clob类型就比较麻烦,最常用的方法是用一个流将其读取出来.使用MVC框架的时候这些都是无所谓的事情,因为反正是写在java类中怎么写都行,可是不使用MVC框架,使用jsp页面JSTL的sql标签去读取数据库的数据这种方式就麻…
通向人工智能产业落地化的道路在哪?
整理 | 夕颜出品 | AI科技大本营(ID:rgznai100)世事浮云,白云苍狗,转眼间关于人工智能的研究已历经两个世纪。在研究者和践行者的不懈努力之下,如今人工智能应用已遍地可见,无论是繁华都市还是偏远小镇&…

PE文件和COFF文件格式分析——导出表的应用——通过导出表隐性加载DLL
通过导出表隐性加载DLL?导出表?加载DLL?还隐性?是的。如果觉得不可思议,可以先看《PE文件和COFF文件格式分析——导出表》中关于“导出地址表”的详细介绍。(转载请指明出于breaksoftware的csdn博客&#x…

系统启动时,spring配置文件解析失败,报”cvc-elt.1: 找不到元素 'beans' 的声明“异常...
现象:spring加载配置文件applicationContext.xml出错,抛出nested exception is og.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 47; cvc-elt.1: 找不到元素 beans 的声明r的异常信息。 造成该异常原因有两种:第一,配置文件头部配置的xsd版…
DllMain中不当操作导致死锁问题的分析--死锁介绍
最近在网上看到一些关于在DllMain中不当操作导致死锁的问题,也没找到比较确切的解答,这极大吸引了我研究这个问题的兴趣。我花了一点时间研究了下,正好也趁机研究了下进程对DllMain的调用规律。因为整个研究篇幅比较长,我觉得还是…
XGBoost缺失值引发的问题及其深度分析 | CSDN博文精选
作者 | 兆军(美团配送事业部算法平台团队技术专家)来源 | 美团技术团队(*点击阅读原文,查看美团技术团队更多文章)背景XGBoost模型作为机器学习中的一大“杀器”,被广泛应用于数据科学竞赛和工业领域&#…