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

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

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

标签:量化交易   cointrader   currency   

转载须注明出自: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)

还是一个比较难的概念。

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

标签:量化交易   cointrader   currency   

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

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