程序員的量化交易之路(28)--Cointrader之Offer報價實體(15)

轉載須註明出處:http://blog.csdn.net/minimicall?viewmode=contentshttp://cloudtrade.top/

Offer:報價。

bid:買方報價

ask:賣方報價


很簡單的一個類。是PriceData的子類。還記得PriceData有什麼吧。

時間戳、量、價,

而PriceData又是MarketData的子類,MarketData封裝了Market。Market包含市場數據,Exchange,Listing,priceBasis,volumeBasis等。

package org.cryptocoinpartners.schema;

import org.joda.time.Instant;

import javax.persistence.Entity;
import javax.persistence.Transient;


/**
 * Offers represent a bid or ask, usually from a Book.  Asks are represented by using a negative volumeCount
 *
 * @author Tim Olson
 */
@Entity
public class Offer extends PriceData {


    /** same as new Offer() */
    public static Offer bid(Market market, Instant time, Instant timeReceived, Long priceCount, Long volumeCount) {
        return new Offer( market, time, timeReceived, priceCount, volumeCount );
    }


    /** same as new Offer() except the volumeCount is negated */
    public static Offer ask(Market market, Instant time, Instant timeReceived, Long priceCount, Long volumeCount) {
        return new Offer( market, time, timeReceived, priceCount, -volumeCount );
    }


    public Offer(Market market, Instant time, Instant timeReceived, Long priceCount, Long volumeCount) {
        super(time, timeReceived, null, market, priceCount, volumeCount);
    }

    @Override
    public String toString() {
        return "Offer{" +
                       ", market=" + getMarket() +
                       ", priceCount=" + getPriceCount() +
                       ", volumeCount=" + getVolumeCount() +
                       '}';
    }


    @SuppressWarnings("ConstantConditions")
    @Transient
    public Side getSide() { return getVolumeCount() >= 0 ? Side.BUY : Side.SELL; }


    // JPA
    protected Offer() {}

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章