zoukankan      html  css  js  c++  java
  • 程序猿的量化交易之路(24)--Cointrader之RemoteEvent远程事件实体(11)

    转载需注明出处:http://blog.csdn.net/minimicall,http://cloudtrader.top/

    在量化交易系统中。有些事件是远端传来的,比方股票的价格数据等。所以,在这一节我们定义了一个远端事件实体。

    它是一个基类。并不单独生成数据表。

    详细代码例如以下:

    package org.cryptocoinpartners.schema;
    
    import javax.annotation.Nullable;
    import javax.persistence.Basic;
    import javax.persistence.MappedSuperclass;
    import javax.persistence.Transient;
    
    import org.hibernate.annotations.Type;
    import org.joda.time.Instant;
    
    @MappedSuperclass
    public abstract class RemoteEvent extends Event {
    
        /**
         * @return the time when this event object was created.  it may be later than getTime() due to transmission delays
         */
        @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentInstantAsMillisLong")
        @Basic(optional = false)
        public Instant getTimeReceived() {
            return timeReceived;
        }
    
        @Transient
        public long getTimestampReceived() {
            return timestampReceived;
        }
    
        @Basic(optional = true)
        public String getRemoteKey() {
            return remoteKey;
        }
    
        @Override
        public void publishedAt(Instant instant) {
            super.publishedAt(instant);
            if (timeReceived == null)
                timeReceived = instant;
            this.timestampReceived = timeReceived.getMillis();
    
        }
    
        protected RemoteEvent(Instant time, @Nullable String remoteKey) {
            this(time, Instant.now(), remoteKey);
        }
    
        protected RemoteEvent(Instant time, Instant timeReceived, @Nullable String remoteKey) {
            super(time);
            this.remoteKey = remoteKey;
            this.timeReceived = timeReceived;
            this.timestampReceived = timeReceived.getMillis();
        }
    
        // JPA
        protected RemoteEvent() {
        }
    
        protected void setTimeReceived(Instant timeReceived) {
            this.timeReceived = timeReceived;
            this.timestampReceived = timeReceived.getMillis();
        }
    
        protected void setRemoteKey(@Nullable String remoteKey) {
            this.remoteKey = remoteKey;
        }
    
        private Instant timeReceived;
        private long timestampReceived;
        private String remoteKey;
    }


  • 相关阅读:
    hdu2222 AC自动机入门
    bzoj1095: [ZJOI2007]Hide 捉迷藏 动态点分治学习
    【NOI2014】起床困难综合症 贪心
    bzoj1822: [JSOI2010]Frozen Nova 冷冻波网络流
    洛谷3767 膜法 带权并查集+分治
    NOI2015品酒大会 后缀数组
    NOI2015程序自动分析 并查集
    NOI2015软件包管理器 树剖线段树
    51nod1244 欧拉函数之和 杜教筛
    51nod1244 莫比乌斯函数之和 杜教筛
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/6839561.html
Copyright © 2011-2022 走看看