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

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

PriceData:价格数据。价格数据是市场数据的子类。

具体代码如下:

package org.cryptocoinpartners.schema;

import java.math.BigDecimal;

import javax.annotation.Nullable;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.joda.time.Instant;

/**
 * Superclass for any MarketData which contains a price and volume, such as an Offer or a Trade ???靠,这个有问题。不过整个平台的代码其实很垃圾。
 *
 * @author Tim Olson
 */
@MappedSuperclass
public abstract class PriceData extends MarketData {

    /**
     * @param time when the pricing event originally occured 
     * @param remoteKey the exchange's unique ID for the pricing event (to prevent duplicates)
     * @param market which Market this pricing is for
     * @param priceCount relative to the Market's quoteBasis
     * @param volumeCount relative to the Market's volumeBasis
     */
    public PriceData(Instant time, @Nullable String remoteKey, Market market, @Nullable Long priceCount, @Nullable Long volumeCount) {
        super(time, remoteKey, market);
        this.priceCount = priceCount;
        this.volumeCount = volumeCount;
    }

    public PriceData(Instant time, @Nullable String remoteKey, Market market, @Nullable BigDecimal price, @Nullable BigDecimal volume) {
        super(time, remoteKey, market);
        this.priceCount = DiscreteAmount.roundedCountForBasis(price, market.getPriceBasis());
        this.volumeCount = DiscreteAmount.roundedCountForBasis(volume, market.getVolumeBasis());
    }

    /**
     * @param time when the pricing event originally occured
     * @param remoteKey the exchange's unique ID for the pricing event (to prevent duplicates)
     * @param market which Market this pricing is for
     * @param priceCount relative to the Market's quoteBasis
     * @param volumeCount relative to the Market's volumeBasis
     */
    public PriceData(Instant time, Instant timeReceived, @Nullable String remoteKey, Market market, @Nullable Long priceCount, @Nullable Long volumeCount) {
        super(time, timeReceived, remoteKey, market);
        this.priceCount = priceCount;
        this.volumeCount = volumeCount;
    }

    public PriceData(Instant time, Instant timeReceived, @Nullable String remoteKey, Market market, @Nullable BigDecimal price, @Nullable BigDecimal volume) {
        super(time, timeReceived, remoteKey, market);
        this.priceCount = DiscreteAmount.roundedCountForBasis(price, market.getPriceBasis());
        this.volumeCount = DiscreteAmount.roundedCountForBasis(volume, market.getVolumeBasis());
    }

    public @Nullable
    Long getPriceCount() {
        return priceCount;
    }

    public @Nullable
    Long getVolumeCount() {
        return volumeCount;
    }

    @Transient
    @Nullable
    public DiscreteAmount getPrice() {
        if (priceCount == null)
            return null;
        if (price == null)
            price = new DiscreteAmount(priceCount, getMarket().getPriceBasis());
        return price;
    }

    @Transient
    @Nullable
    public Double getPriceAsDouble() {
        Amount price = getPrice();
        return price == null ? null : price.asDouble();
    }

    @Transient
    @Nullable
    public Double getPriceCountAsDouble() {
        Long price = getPriceCount();
        return price == null ? null : price.doubleValue();
    }

    @Transient
    @Nullable
    public Double getVolumeCountAsDouble() {
        Long volume = getVolumeCount();
        return volume == null ? null : volume.doubleValue();
    }

    @Transient
    @Nullable
    public BigDecimal getPriceAsBigDecimal() {
        Amount price = getPrice();
        return price == null ? null : price.asBigDecimal();
    }

    @Transient
    @Nullable
    public DiscreteAmount getVolume() {
        if (volumeCount == null)
            return null;
        if (volume == null)
            volume = new DiscreteAmount(volumeCount, getMarket().getVolumeBasis());
        return volume;
    }

    @Transient
    @Nullable
    public Double getVolumeAsDouble() {
        Amount volume = getVolume();
        return volume == null ? null : volume.asDouble();
    }

    @Transient
    @Nullable
    public BigDecimal getVolumeAsBigDecimal() {
        Amount volume = getVolume();
        return volume == null ? null : volume.asBigDecimal();
    }

    // JPA
    protected PriceData() {
        super();
    }

    protected void setPriceCount(Long priceCount) {
        this.priceCount = priceCount;
    }

    protected void setVolumeCount(Long volumeCount) {
        this.volumeCount = volumeCount;
    }

    private DiscreteAmount price;//价
    private DiscreteAmount volume;//量
    private Long priceCount;
    private Long volumeCount;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值