码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-06-04 06:15:29      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:量化交易   cointrader   assert   hibernate   

转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top

任何可交易的都可以称之为Assert,资产。其类代码如下:

package org.cryptocoinpartners.schema;

import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Transient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Represents anything valuable and tradable, like currency or stock
 *任何有价值的并且可交易的物体,比如现金、股票
 * @author Tim Olson
 */
@Entity //实体,说明在数据库中会建立相应的表格。由于没有使用name参数,说明类名就是表明。
@Cacheable //可缓存
public abstract class Asset extends EntityBase {

    public static Asset forSymbol(String symbol) {
        // only Currency is supported
        return Currency.forSymbol(symbol);
    }

    @Basic(optional = false)
    public String getSymbol() {
        return symbol;
    }

    @Basic(optional = false)
    public double getBasis() {
        return basis;
    }

    @Transient
    public int getScale() {

        int length = (int) (Math.log10(Math.round(1 / basis)));
        return length;
    }

    @Override
    public String toString() {
        return symbol;
    }

    protected Asset(String symbol, double basis) {
        this.symbol = symbol;
        this.basis = basis;
    }

    // JPA
    protected Asset() {
    }

    protected void setSymbol(String symbol) {
        this.symbol = symbol;
    }

    protected void setBasis(double basis) {
        this.basis = basis;
    }

    private String symbol;//符号
    private double basis;//值

    private static Logger log = LoggerFactory.getLogger(Asset.class);
}


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

标签:量化交易   cointrader   assert   hibernate   

原文地址:http://blog.csdn.net/minimicall/article/details/46354483

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!