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


相关文章
|
12月前
|
存储 缓存 应用服务中间件
Nginx缓存清除方法(手把手教你轻松清理Nginx缓存)
本文来源https://www.vps5.cn/介绍Nginx缓存清除的常用方法,包括删除缓存文件、使用ngx_cache_purge模块及设置过期时间,帮助开发者高效管理缓存,提升网站性能。
|
弹性计算 安全
如何给一台云服务器绑定多个公网IP?
本文介绍了如何为云服务器绑定多个公网IP,适用于需多个IP地址托管不同应用的场景。以阿里云国际站为例,讲解使用弹性公网IP(EIP)和辅助弹性网卡实现该功能的步骤,适用于ECS实例。
如何给一台云服务器绑定多个公网IP?
|
数据可视化 前端开发 JavaScript
【Echarts大屏】智慧医疗可视化大屏(新手必用)
【Echarts大屏】智慧医疗可视化大屏(新手必用)
|
网络架构
第四章:介绍 BACnet 虚拟链路层
虚拟链路层 (VLL) 背后的基本概念是向现有的 BACnet 网络层呈现某些网络拓扑和功能的视图,利用新协议中内置的任何功能并根据需要添加功能以维护现有标准中的 BACnet 网络视点。
361 2
第四章:介绍 BACnet 虚拟链路层
|
缓存 安全 fastjson
Fastjson姿势技巧集合2
Fastjson姿势技巧集合
1901 0
|
Android开发
Android 使用BottomNavigationView和Novigation组件实现底部导航功能
Android 使用BottomNavigationView和Novigation组件实现底部导航功能
879 0
|
缓存 easyexcel Java
阿里开源的这个库,让 Excel 导出不再复杂(简简单单的写)
导出是中后台常见的功能,Excel文件是常见的导出格式。
3194 0
阿里开源的这个库,让 Excel 导出不再复杂(简简单单的写)
|
JavaScript
[Vue warn]: Duplicate keys detected: ‘1‘. This may cause an update error. for循环,key重复报错
[Vue warn]: Duplicate keys detected: ‘1‘. This may cause an update error. for循环,key重复报错
467 0
|
大数据 定位技术
数字之城:全球五个城市大数据创新应用案例
全球很多城市将市政大数据向公众开放,并设立项目鼓励大数据应用创新,基于政务大数据透明和Open Data项目的“大数据城市”正在成为科技创新的新引擎。 纽约市本周一发布了超过200个很有价值的城市数据集,此举为OpenStreetMap这样的开源地图项目提供了更多内容和数据支持。
1880 0