转载需注明出处: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;
}

程序员的量化交易之路(25)--Cointrader之MarketData市场数据实体(12)相关推荐

  1. 程序员的量化交易之路(1)----规划开篇

    其实,一直对量化交易有一定的理解和情节.早在中大读研究生的时候实验室师兄,已经去了中国平安核心投资团队,做高频交易研究的国源师兄的影响,就开始对金融世界产生了浓厚的兴趣.看了丁磊编著的<量化投资 ...

  2. 程序员的量化交易之路(35)--Lean之DataFeed数据槽3

    转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top/ Lean引擎的模块划分非常的规范.其中DataFeed是数据槽,就是供应数 ...

  3. 程序员的量化交易之路(17)--Cointrader之Temporal实体(5)

    转载需要注明:http://blog.csdn.net/minimicall,http://cloudtrader.top/ 这一小节说明一个时间实体Temporal实体,它的代码很简单. packa ...

  4. 程序员的量化交易之路(26)--Cointrader之Listing挂牌实体(13)

    转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrade.top Listing:挂牌.比如某只股票在某证 ...

  5. 程序员转行量化交易可行吗?

    程序员转量化交易,其实是一件挺顺理成章的事,有一位网友他想向我佐证一下,职业量化交易这一条路,他可以做下去吗,以及其它一些细枝末节的问题. 他以前是某日系合资企业的程序工程师,程序背景是C++与pyt ...

  6. 热议:程序员转行量化交易可行吗?

    程序员转量化交易,其实是一件挺顺理成章的事,就在上周,有一位网友来我的店里拜访我,其实他来的目的也特别简单,他想向我佐证一下,职业量化交易这一条路,他可以做下去吗,以及其它一些细枝末节的问题. 他以前 ...

  7. 程序员的量化交易(34)--QuantConnect_Lean如何定义Indicator指标2

    转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top/ 指标(Indicator)由三大关键组件组成: 1. 实现你指标的类 2. ...

  8. Android从程序员到架构师之路3

    本文学习自高焕堂老师的Android从程序员到架构师之路系列教学视频 40 - 认识线程(Thread)模式a 1. 线程(Thread)概念 所谓线程(Thread) 是指一串连续的执行动作,以达成 ...

  9. 剖析Android移动开发程序员的职业发展之路

    剖析Android移动开发程序员的职业发展之路 做Android移动开发已经有三年时间,其中甘苦自知,对Android开发和对Android程序员的职业发展有一些自己的感悟,在这里愿与大家分享和讨论. ...

最新文章

  1. 转 plsql dev中Dynamic Performance Tables not accessible分析解决
  2. 服务器主板开机无显维修,电脑主板开机无显示的维修方法-1
  3. 洛谷——P1071 潜伏者
  4. 结合WebSocket编写WebGL综合场景示例
  5. 螺旋天线有方向性吗_螺旋天线方向图
  6. 2017.9.18 HH的项链 思考记录
  7. linux 查看cuda版本_Ubuntu18.04+Tensorflow GPU版本环境搭建
  8. JavaScript 真正的工作原理,你知道吗?
  9. ThinkPHP无限分类模块设计
  10. 问号匹配,带元组规则的位置匹配不到
  11. 多面集的表示定理 (Representation / Resolution / Caratheodory theorem of polyhedral Sets)
  12. Arcgis学习视频
  13. 计算机单元格的引用计算,2017年职称计算机考试Excel教程:单元格引用
  14. 利用Chrome翻译搞定大部分英文文件翻译的工作流
  15. simulink仿真结果出现振荡
  16. 常用性能测试工具有哪些
  17. 计算机知识对于老师的帮助,教师计算机学习心得体会
  18. skipping incompatible xxxx.a when searching for -lxxx问题的解决
  19. NAT以及基本配置(静态配置)
  20. JAVA数据加密压缩传输给服务端(Gzip加AES)

热门文章

  1. UML部署图(转载)
  2. 国外厂商在行业客户上输单的原因
  3. 大型网站架构演变和知识体系
  4. ios关于用xib创建的cell 自动返回cell的高度问题!
  5. Swoft 2 Beta 发布,基于 Swoole 的云原生协程框架
  6. 深度讲解:web前端性能优化
  7. 创建MySQL数据库
  8. 7——ThinkPhp中的响应和重定向:
  9. Android进阶笔记:Messenger源码详解
  10. Windows 10离线安装.NET Framework 3.5