程序员的量化交易之路(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;
}



相关文章
|
6月前
|
前端开发 大数据 数据库
临时抱佛脚必看|一个月速通高级系统架构设计师!(低分飘过版)
本文写给已决定报考高级软件架构设计师的同学,从软考报名到正式考试,有40天时间,本文纯应试备考经验,一个月速成,仅供参考。
|
新零售 人工智能 供应链
七星创客/艾倍生/推三返一/系统开发方案项目/开发案例/规则玩法/源码程序
  所谓新零售即是个人、企业以互联网为依托,通过运用大数据、人工智能等先进技术手段,对商品的生产、流通与销售过程进行升级改造,进而重塑业态结构与生态圈,并对线上服务、线下体验以及现代物流进行深度融合的零售新模式。
|
Rust 安全
Jogger跑鞋零撸项目系统开发/方案详细/规则玩法/源码案例/功能说明
At present, multi blockchain smart contract compatibility technology mainly includes two ways: one is to implement cross chain smart contracts, which is to apply smart contracts to cross chain scenarios; Another approach is to use converters to convert smart contracts from one programming language