转载须注明出处:http://blog.csdn.net/minimicall?

viewmode=contentshttp://cloudtrade.top

Listing:挂牌。

比方某仅仅股票在某证券交易所挂牌交易。也就是上市交易。

老规矩,通过源代码学习:

package org.cryptocoinpartners.schema;

import java.util.ArrayList;
import java.util.List; import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
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; /**
* Represents the possibility to trade one Asset for another
*/
@SuppressWarnings("UnusedDeclaration")
@Entity //在数据库创建Listing这个表
@Cacheable//可缓存
//命名查询
@NamedQueries({ @NamedQuery(name = "Listing.findByQuoteBase", query = "select a from Listing a where base=?1 and quote=?2 and prompt IS NULL"),
@NamedQuery(name = "Listing.findByQuoteBasePrompt", query = "select a from Listing a where base=?1 and quote=?2 and prompt=?3") })
@Table(indexes = { @Index(columnList = "base"), @Index(columnList = "quote"), @Index(columnList = "prompt") })
//@Table(name = "listing", uniqueConstraints = { @UniqueConstraint(columnNames = { "base", "quote", "prompt" }),
//@UniqueConstraint(columnNames = { "base", "quote" }) })
public class Listing extends EntityBase {

<pre name="code" class="java">    protected Asset base;
protected Asset quote;
private Prompt prompt;


    @ManyToOne(optional = false)
//@Column(unique = true)
public Asset getBase() {
return base;
} @PostPersist
private void postPersist() {
// PersistUtil.clear();
// PersistUtil.refresh(this);
//PersistUtil.merge(this);
// PersistUtil.close();
//PersistUtil.evict(this); } @ManyToOne(optional = false)
//@Column(unique = true)
public Asset getQuote() {
return quote;
} @ManyToOne(optional = true)
public Prompt getPrompt() {
return prompt;
} /** will create the listing if it doesn't exist */
public static Listing forPair(Asset base, Asset quote) { try {
Listing listing = PersistUtil.namedQueryZeroOne(Listing.class, "Listing.findByQuoteBase", base, quote);
if (listing == null) {
listing = new Listing(base, quote);
PersistUtil.insert(listing);
}
return listing;
} catch (NoResultException e) {
final Listing listing = new Listing(base, quote);
PersistUtil.insert(listing);
return listing;
}
} public static Listing forPair(Asset base, Asset quote, Prompt prompt) {
try { Listing listing = PersistUtil.namedQueryZeroOne(Listing.class, "Listing.findByQuoteBasePrompt", base, quote, prompt);
if (listing == null) {
listing = new Listing(base, quote, prompt);
PersistUtil.insert(listing);
}
return listing;
} catch (NoResultException e) {
final Listing listing = new Listing(base, quote, prompt);
PersistUtil.insert(listing);
return listing;
}
} @Override
public String toString() {
return getSymbol();
} @Transient
public String getSymbol() {
if (prompt != null)
return base.getSymbol() + '.' + quote.getSymbol() + '.' + prompt;
return base.getSymbol() + '.' + quote.getSymbol();
} @Transient
protected double getMultiplier() {
if (prompt != null)
return prompt.getMultiplier();
return getContractSize() * getTickSize();
} @Transient
protected double getTickValue() {
if (prompt != null)
return prompt.getTickValue();
return 1;
} @Transient
protected double getContractSize() {
if (prompt != null)
return prompt.getContractSize();
return 1;
} @Transient
protected double getTickSize() {
if (prompt != null)
return prompt.getTickSize();
return getPriceBasis();
} @Transient
protected Amount getMultiplierAsAmount() { return new DiscreteAmount((long) getMultiplier(), getVolumeBasis());
} @Transient
protected double getVolumeBasis() {
double volumeBasis = 0;
if (prompt != null)
volumeBasis = prompt.getVolumeBasis();
return volumeBasis == 0 ? getBase().getBasis() : volumeBasis; } @Transient
public FeeMethod getMarginMethod() {
FeeMethod marginMethod = null;
if (prompt != null)
marginMethod = prompt.getMarginMethod();
return marginMethod == null ? null : marginMethod; } @Transient
public FeeMethod getMarginFeeMethod() {
FeeMethod marginFeeMethod = null;
if (prompt != null)
marginFeeMethod = prompt.getMarginFeeMethod();
return marginFeeMethod == null ? null : marginFeeMethod; } @Transient
protected double getPriceBasis() {
double priceBasis = 0;
if (prompt != null)
priceBasis = prompt.getPriceBasis();
return priceBasis == 0 ? getQuote().getBasis() : priceBasis; } @Transient
protected Asset getTradedCurrency() {
if (prompt != null && prompt.getTradedCurrency() != null)
return prompt.getTradedCurrency();
return getQuote();
} @Transient
public FeeMethod getFeeMethod() {
if (prompt != null && prompt.getFeeMethod() != null)
return prompt.getFeeMethod();
return null;
} @Transient
public double getFeeRate() {
if (prompt != null && prompt.getFeeRate() != 0)
return prompt.getFeeRate();
return 0;
} @Transient
protected int getMargin() {
if (prompt != null && prompt.getMargin() != 0)
return prompt.getMargin();
return 0;
} public static List<String> allSymbols() {
List<String> result = new ArrayList<>();
List<Listing> listings = PersistUtil.queryList(Listing.class, "select x from Listing x");
for (Listing listing : listings)
result.add((listing.getSymbol()));
return result;
} // JPA
protected Listing() {
} protected void setBase(Asset base) {
this.base = base;
} protected void setQuote(Asset quote) {
this.quote = quote;
} protected void setPrompt(Prompt prompt) {
this.prompt = prompt;
} public Listing(Asset base, Asset quote) {
this.base = base;
this.quote = quote;
} public Listing(Asset base, Asset quote, Prompt prompt) {
this.base = base;
this.quote = quote;
this.prompt = prompt;
} public static Listing forSymbol(String symbol) {
symbol = symbol.toUpperCase();
final int dot = symbol.indexOf('.');
if (dot == -1)
throw new IllegalArgumentException("Invalid Listing symbol: \"" + symbol + "\"");
final String baseSymbol = symbol.substring(0, dot);
Asset base = Asset.forSymbol(baseSymbol);
if (base == null)
throw new IllegalArgumentException("Invalid base symbol: \"" + baseSymbol + "\"");
int len = symbol.substring(dot + 1, symbol.length()).indexOf('.');
len = (len != -1) ? Math.min(symbol.length(), dot + 1 + symbol.substring(dot + 1, symbol.length()).indexOf('.')) : symbol.length();
final String quoteSymbol = symbol.substring(dot + 1, len);
final String promptSymbol = (symbol.length() > len) ? symbol.substring(len + 1, symbol.length()) : null;
Asset quote = Asset.forSymbol(quoteSymbol);
if (quote == null)
throw new IllegalArgumentException("Invalid quote symbol: \"" + quoteSymbol + "\"");
if (promptSymbol == null)
return Listing.forPair(base, quote);
Prompt prompt = Prompt.forSymbol(promptSymbol);
return Listing.forPair(base, quote, prompt);
} @Override
public boolean equals(Object obj) {
if (obj instanceof Listing) {
Listing listing = (Listing) obj; if (!listing.getBase().equals(getBase())) {
return false;
} if (!listing.getQuote().equals(getQuote())) {
return false;
}
if (listing.getPrompt() != null)
if (this.getPrompt() != null) {
if (!listing.getPrompt().equals(getPrompt()))
return false;
} else {
return false;
} return true;
} return false;
} @Override
public int hashCode() {
return getPrompt() != null ? getQuote().hashCode() + getBase().hashCode() + getPrompt().hashCode() : getQuote().hashCode() + getBase().hashCode(); } }
    protected Asset base;
protected Asset quote;
private Prompt prompt;

程序猿的量化交易之路(26)--Cointrader之Listing挂牌实体(13)的更多相关文章

  1. 程序猿的量化交易之路(13)--Cointrader类图(1)

    转载须注明出处:http://blog.csdn.net/minimicall? viewmode=contents, htpp://cloudtrader.top 今天開始正式切入到Cointrad ...

  2. 程序猿的量化交易之路(20)--Cointrader之Assert实体(8)

    转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top 不论什么可交易的都能够称之为Assert,资产.其类代码例如以下: pac ...

  3. 程序猿的量化交易之路(29)--Cointrader之Tick实体(16)

    转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrade.top Tick:什么是Tick,在交易平台中很常见,事实上就 单笔交易时某仅仅证券 ...

  4. 程序猿的量化交易之路(24)--Cointrader之RemoteEvent远程事件实体(11)

    转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrader.top/ 在量化交易系统中.有些事件是远端传来的,比方股票的价格数据等.所以,在这 ...

  5. 程序猿的量化交易之路(30)--Cointrader之ConfigUtil(17)

    转载须注明出处:viewmode=contents">http://blog.csdn.net/minimicall?viewmode=contents.http://cloudtra ...

  6. 程序猿的量化交易之路(32)--Cointrade之Portfolio组合(19)

    转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrade.top/ Portfolio:组合,代表的是多个 ...

  7. 程序猿的量化交易之路(27)--Cointrader之PriceData价格数据(14)

    转载须注明出处:http://blog.csdn.net/minimicall?viewmode=contents,http://cloudtrade.top/ PriceData:价格数据.价格数据 ...

  8. 程序猿的量化交易之路(18)--Cointrader之Event实体(6)

    转载需注明: 事件,是Esper的重要概念. 这里我们定义个事件类.它是Temporal实体的派生类. 不过对Temporal简单的包装.其代码例如以下: package org.cryptocoin ...

  9. 程序猿的量化交易之路(21)--Cointrader之Currency货币实体(9)

    转载须注明出自:http://blog.csdn.net/minimicall? viewmode=contents,http://cloudtrader.top 货币,Cointrader中基本实体 ...

随机推荐

  1. C++逗号运算符与逗号表达式

    C++将赋值表达式作为表达式的一种,使赋值操作不仅可以出现在赋值语句中,而且可以以表达式形式出现在其他语句(如输出语句.循环语句等)中.这是C++语言灵活性的一种表现. 请注意,用cout语句输出一个 ...

  2. 数据库神器:Navicat Premium

    Navicat premium是一款数据库管理工具.将此工具连接数据库,你可以从中看到各种数据库的详细信息.包括报错,等等.当然,你也可以通过他,登陆数据库,进行各种操作.Navicat Premiu ...

  3. ZOJ 3607贪心算法

    http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...

  4. 深入windows的关机消息截获-从XP到Win7的变化

    之前写了一个软件用于实验室的打卡提醒,其中一个重要的功能是在关机之前提醒当天晚上是否已经打卡.之前我是在WM_ENDSESSION中弹出一个模态对话框来提醒,在XP中基本工作正常,在Win7中大多数时 ...

  5. hdu 3917 (最大权闭合图)

    题意:政府有一些路,m个公司来修,每个公司修路要交税给政府,修路政府要付给公司费用,求政府能获得的最大利润,如果选择一个公司负责一个项目,那么该公司负责的其它项目也必须由他负责,并且与其有相连关系的公 ...

  6. perl 处理perl返回的json

    [root@wx03 ~]# cat a14.pl use Net::SMTP; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; u ...

  7. linux下tomcat shutdown后 java进程依然存在

    今天遇到一个非常奇怪的问题,如标题所看到的: linux下(之所以强调linux下,是由于在windows下正常),运行tomcat ./shutdown.sh 后,尽管tomcat服务不能正常訪问了 ...

  8. C# 未能加载文件或程序集“MySQLDriverCS..." 错误解决

    在解决方案的属性里,生成,里面有个目标平台,网上说的 大概也就是64位和32位的不兼容问题..试着把目标平台改为X86后竟然神奇的正常了!

  9. Javascript 生成指定范围数值随机数

    JavaScript对随机数的介绍比较少,所以今天分享一下有关随机数的一些事儿.希望能对大家有点小帮助. 主要的公式就是parseInt(Math.random()*(上限-下限+1)+下限); Ma ...

  10. string的不可变性

    1.不可变性 代码如下: static void Main(string[] args){string str1 = "a";string str2 = str1;str2 = & ...