发布实时蜡烛计算

问题描述

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

我有一个包含 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 (将#修改为@)