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

转载须注明出自:http://blog.csdn.net/minimicall?viewmode=contentshttp://cloudtrader.top


货币,Cointrader中基本实体。我们通过代码来学习该实体:

package org.cryptocoinpartners.schema;

import java.util.List;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.NoResultException;

import org.cryptocoinpartners.util.PersistUtil;

/**
 * @author Tim Olson
 */
@Entity //实体
@Cacheable
public class Currency extends Asset {//货币是资产的一种,继承关系

    public boolean isFiat() {//是否为法定货币
        return fiat;
    }

    public static Currency forSymbol(String symbol) {
        return PersistUtil.queryOne(Currency.class, "select c from Currency c where symbol=?1", symbol);
    }

    public static List<String> allSymbols() {
        return PersistUtil.queryList(String.class, "select symbol from Currency");
    }

    // JPA
    protected Currency() {
    }

    protected void setFiat(boolean fiat) {
        this.fiat = fiat;
    }

    // used by Currencies
    static Currency forSymbolOrCreate(String symbol, boolean isFiat, double basis) {
        try {
            return forSymbol(symbol);
        } catch (NoResultException e) {
            final Currency currency = new Currency(isFiat, symbol, basis);
            PersistUtil.insert(currency);
            return currency;
        }
    }

    // used by Currencies
    static Currency forSymbolOrCreate(String symbol, boolean isFiat, double basis, double multiplier) {
        try {
            return forSymbol(symbol);
        } catch (NoResultException e) {
            final Currency currency = new Currency(isFiat, symbol, basis, multiplier);
            PersistUtil.insert(currency);
            return currency;
        }
    }

    private Currency(boolean fiat, String symbol, double basis) {
        super(symbol, basis);
        this.fiat = fiat;
    }

    private Currency(boolean fiat, String symbol, double basis, double multiplier) {
        super(symbol, basis);
        this.fiat = fiat;
        this.multiplier = multiplier;
    }

    private boolean fiat;//是否为法定货币
    private double multiplier;//乘数
}

multiplier乘数是一个比较生疏的一个概念。它的介绍见wikipedia:http://en.wikipedia.org/wiki/Multiplier_(economics)

还是一个比较难的概念。

上一篇:龙华区委书记余新国:坚持人才优先发展战略,构建人无我有、人有我优的环境体系。


下一篇:乐播新瑞,“破圈”声音经济 | 阿里巴巴诸神之战创业大赛系列报道