109 lines
3.4 KiB
C#
109 lines
3.4 KiB
C#
#nullable enable
|
|
namespace Spark.Api.MarketData {
|
|
using bts.api;
|
|
using bts.api.domain;
|
|
|
|
using Spark.Core.Collections;
|
|
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// Price/trade statistics for a particular security (fast moving)
|
|
/// </summary>
|
|
public readonly struct PriceTicker : IEquatable<PriceTicker>, IJsonFormatter<PriceTicker> {
|
|
public PriceTicker(
|
|
SecurityImmutable security,
|
|
TickDisplaySettingsImmutable quantity_display,
|
|
double high,
|
|
double low,
|
|
double volume,
|
|
double bid,
|
|
double bid_quantity,
|
|
double ask,
|
|
double ask_quantity,
|
|
double mark,
|
|
double last,
|
|
double last_quantity
|
|
) {
|
|
this.security = security;
|
|
this.quantity_display = quantity_display;
|
|
this.high = high;
|
|
this.low = low;
|
|
this.volume = volume;
|
|
this.bid = bid;
|
|
this.bid_quantity = bid_quantity;
|
|
this.ask = ask;
|
|
this.ask_quantity = ask_quantity;
|
|
this.mark = mark;
|
|
this.last = last;
|
|
this.last_quantity = last_quantity;
|
|
}
|
|
|
|
public SecurityImmutable security { get; }
|
|
public TickDisplaySettingsImmutable quantity_display { get; }
|
|
public double high { get; }
|
|
public double low { get; }
|
|
public double volume { get; }
|
|
public double bid { get; }
|
|
public double bid_quantity { get; }
|
|
public double ask { get; }
|
|
public double ask_quantity { get; }
|
|
public double mark { get; }
|
|
public double last { get; }
|
|
public double last_quantity { get; }
|
|
|
|
public bool Equals(PriceTicker other) =>
|
|
security.Equals(other.security) &&
|
|
quantity_display.Equals(other.quantity_display) &&
|
|
high.Equals(other.high) &&
|
|
low.Equals(other.low) &&
|
|
volume.Equals(other.volume) &&
|
|
bid.Equals(other.bid) &&
|
|
bid_quantity.Equals(other.bid_quantity) &&
|
|
ask.Equals(other.ask) &&
|
|
ask_quantity.Equals(other.ask_quantity) &&
|
|
mark.Equals(other.mark) &&
|
|
last.Equals(other.last) &&
|
|
last_quantity.Equals(other.last_quantity);
|
|
|
|
public override bool Equals(object? obj) =>
|
|
obj is PriceTicker other && Equals(other);
|
|
|
|
public override int GetHashCode() =>
|
|
new HashCode()
|
|
.with_values(new int[] {
|
|
security.Id.GetHashCode(),
|
|
high.GetHashCode(),
|
|
low.GetHashCode(),
|
|
volume.GetHashCode(),
|
|
bid.GetHashCode(),
|
|
bid_quantity.GetHashCode(),
|
|
ask.GetHashCode(),
|
|
ask_quantity.GetHashCode(),
|
|
mark.GetHashCode(),
|
|
last.GetHashCode(),
|
|
last_quantity.GetHashCode()
|
|
})
|
|
.ToHashCode();
|
|
|
|
public static bool operator ==(PriceTicker left, PriceTicker right) =>
|
|
left.Equals(right);
|
|
|
|
public static bool operator !=(PriceTicker left, PriceTicker right) =>
|
|
!(left == right);
|
|
public static System.Object ToJsonObj(PriceTicker obj) => new {
|
|
security = obj.security.Exchange.ToString() + "." + obj.security.ToString(),
|
|
high = obj.high,
|
|
low = obj.low,
|
|
volume = obj.volume,
|
|
bid = obj.bid,
|
|
bid_quantity = obj.bid_quantity,
|
|
ask = obj.ask,
|
|
ask_quantity = obj.ask_quantity,
|
|
mark = obj.mark,
|
|
last = obj.last,
|
|
last_quantity = obj.last_quantity
|
|
};
|
|
}
|
|
}
|