53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using bts.api;
|
|
using bts.api.domain;
|
|
using bts.co2;
|
|
|
|
using mbts.analytics;
|
|
|
|
using Spark.Core;
|
|
|
|
namespace mbts.spark {
|
|
public readonly struct TradeInfo : bts.api.IJsonFormatter<TradeInfo> {
|
|
public readonly SecurityMD security_md;
|
|
public readonly TradeMessageImmutable trade;
|
|
public readonly GreeksTuple? greeks_tuple;
|
|
public readonly double volume;
|
|
|
|
public TradeInfo(
|
|
SecurityMD security_md,
|
|
TradeMessageImmutable trade,
|
|
GreeksTuple? greeks_tuple = null,
|
|
double volume = double.NaN) {
|
|
this.security_md = security_md;
|
|
this.trade = trade;
|
|
this.greeks_tuple = greeks_tuple;
|
|
this.volume = volume;
|
|
}
|
|
|
|
public SecurityImmutable security => security_md.security;
|
|
public TickDisplaySettingsImmutable qty_display => security_md.quantity_display;
|
|
|
|
public static System.Object ToJsonObj(TradeInfo obj) => new {
|
|
secuirty = obj.security.Exchange.ToString() + "." + obj.security.ToString(),
|
|
price = obj.trade.price(),
|
|
timestamp = obj.trade.Time,
|
|
quantity = obj.volume,
|
|
agg_side = obj.trade.AggressorSide.ToString()
|
|
};
|
|
}
|
|
|
|
public static class TradeInfoExtensions {
|
|
public static TradeInfo with(
|
|
this in TradeInfo trade_info,
|
|
SecurityMD? security_md = null,
|
|
TradeMessageImmutable? trade = null,
|
|
Optional<GreeksTuple?> greeks_tuple = default,
|
|
double? volume = null) =>
|
|
new(
|
|
security_md ?? trade_info.security_md,
|
|
trade ?? trade_info.trade,
|
|
greeks_tuple.value_or(trade_info.greeks_tuple),
|
|
volume ?? trade_info.volume);
|
|
}
|
|
}
|