微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

发布实时蜡烛计算

如何解决发布实时蜡烛计算

我正在尝试实时计算加密货币的蜡烛图。 (开盘价、最高价、最低价、收盘价)。我无法确定如何以及何时发布结果。

我有一个包含 O、H、L、C 的 metricsDTO:

public class CandleDTO 
{
    public decimal Open { get; set; }
    public decimal High { get; set; }
    public decimal Low { get; set; }
    public decimal Close { get; set; }    
}

当数据从套接字进入时,它会触发一个事件来调用我的 OnInput:

protected DateTimeOffset Nextelapsedtime =>
        this._movingMetrics.StartTimeStamp.AddMilliseconds(this._options.IntervalMilliseconds);

public override void OnInput(object sender,MatchEvent input)
{
    if (0 == this._movingMetrics.ItemCount)
    {
        this._movingMetrics.ItemCount++;
        this._movingMetrics.IntervalMilliseconds = this._options.IntervalMilliseconds;
        this._movingMetrics.StartTimeStamp = input.Time;
        this._movingMetrics.Open = input.Price;
    }
    else if (input.Time > this.Nextelapsedtime)
    {
        this.Publish(this._movingMetrics);
        this._movingMetrics = new MetricsDTO();
    }
    else
    {
        this._movingMetrics.ItemCount++;
    }

    //By default everything is the closing price,because we don't kNow when the frame will close
    this._movingMetrics.Close = input.Price;

    //By default the high should be initalized to 0
    //This should alway work even after initialied
    if(input.Price > this._movingMetrics.High)
    {
        this._movingMetrics.High = input.Price;
    }

    //We need to invert the prices so that when we initialize the low will be 0
    if((input.Price *-1) > (this._movingMetrics.Low * -1))
    {
        this._movingMetrics.Low = input.Price;
    }
}

我发布的问题。
我想到了 3 种不同的发布方式,但它们都有自己的问题。

  1. 目前,我依靠网络套接字事件来告诉我何时发布。 (如 Else If 语句中所示)因此,如果一秒钟内没有匹配,则该节点将不会发布。

  2. 我可以使用计时器来调用发布,但是,如果我在处理中途会导致问题,这可能意味着我的 DTO 上的某些值将被更新,而其他值则不会

  3. 我可以将发布逻辑和指标提供节点封装在一个锁中,但这些锁会减慢系统速度并阻止系统处理尽可能多的事件。

注意:该系统产生的指标不仅仅是 OHLC,否则我会采用计时器方法

有没有人有什么好的解决方案,告诉我如何在这种情况下发布最佳发布方式?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。