Files

42 lines
1.4 KiB
C#
Raw Permalink Normal View History

2024-10-27 16:11:08 -07:00
using System.Runtime.CompilerServices;
2024-09-22 17:31:24 -07:00
namespace QuanTAlib;
2024-10-06 14:44:43 -07:00
public interface ITValue
2024-09-22 17:31:24 -07:00
{
DateTime Time { get; }
double Value { get; }
bool IsNew { get; }
bool IsHot { get; }
}
2024-10-27 16:11:08 -07:00
[SkipLocalsInit]
2024-10-06 14:44:43 -07:00
public readonly record struct TValue(DateTime Time, double Value, bool IsNew = true, bool IsHot = true) : ITValue
2024-09-22 17:31:24 -07:00
{
public DateTime Time { get; init; } = Time;
2024-10-27 16:11:08 -07:00
public double Value { get; init; } = Value;
public bool IsNew { get; init; } = IsNew;
public bool IsHot { get; init; } = IsHot;
public DateTime t => Time;
public double v => Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue() : this(DateTime.UtcNow, 0) { }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TValue(double value, bool isNew = true, bool isHot = true)
: this(DateTime.UtcNow, value, IsNew: isNew, IsHot: isHot) { }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator double(TValue tv) => tv.Value;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator DateTime(TValue tv) => tv.Time;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator TValue(double value) => new TValue(DateTime.UtcNow, value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString() => $"[{Time:yyyy-MM-dd HH:mm:ss}, {Value:F2}, IsNew: {IsNew}, IsHot: {IsHot}]";
2024-09-22 17:31:24 -07:00
}