112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
#nullable enable
|
|
namespace Spark.Api.Orders {
|
|
using bts.api;
|
|
using bts.api.orderman;
|
|
using bts.utils;
|
|
|
|
using mbts.spark;
|
|
|
|
using System;
|
|
|
|
public readonly struct OrderRecordTuple : IEquatable<OrderRecordTuple> {
|
|
public OrderRecordTuple(
|
|
OrderRecordImmutable order,
|
|
SecurityImmutable? security = null,
|
|
uint? piq = null,
|
|
AlgoData? algo = null,
|
|
AlgoDefinitionMetadata? algo_meta = null
|
|
) {
|
|
this.order = order;
|
|
this.security = security;
|
|
this.piq = piq;
|
|
this.algo = algo;
|
|
this.meta = algo_meta;
|
|
}
|
|
|
|
public OrderRecordImmutable order { get; }
|
|
public SecurityImmutable? security { get; }
|
|
public uint? piq { get; }
|
|
public AlgoData? algo { get; }
|
|
public AlgoDefinitionMetadata? meta { get; }
|
|
public CustomOrderDefinition.CustomOneofCase algo_type =>
|
|
(algo?.value)?.CustomCase ?? order.order_type();
|
|
public string? algo_name => algo?.name;
|
|
|
|
public uint key => order.Key;
|
|
public uint account_id => order.account_id();
|
|
public string account_name => order.account();
|
|
public uint security_id => order.security_key();
|
|
|
|
public bool Equals(OrderRecordTuple other) =>
|
|
order.Equals(other.order) &&
|
|
security.Equals(other.security);
|
|
|
|
public override bool Equals(object? obj) =>
|
|
obj is OrderRecordTuple other && Equals(other);
|
|
|
|
public override int GetHashCode() =>
|
|
HashCode.Combine(order.Key.GetHashCode(), security?.GetHashCode() ?? 0);
|
|
|
|
public static bool operator ==(OrderRecordTuple left, OrderRecordTuple right) =>
|
|
left.Equals(right);
|
|
|
|
public static bool operator !=(OrderRecordTuple left, OrderRecordTuple right) =>
|
|
!(left == right);
|
|
}
|
|
|
|
public readonly struct OrderRecordTupleWithRoot : IEquatable<OrderRecordTupleWithRoot>, IJsonFormatter<OrderRecordTupleWithRoot> {
|
|
readonly OrderRecordTuple? _root;
|
|
|
|
public OrderRecordTupleWithRoot(OrderRecordTuple order, OrderRecordTuple? root = null) {
|
|
this.order = order;
|
|
_root = root;
|
|
}
|
|
|
|
public OrderRecordTuple order { get; }
|
|
public OrderRecordTuple root => _root ?? order;
|
|
|
|
public uint key => order.key;
|
|
public uint security_id => order.security_id;
|
|
public SecurityImmutable? security => order.security;
|
|
|
|
// TODO: remove assumption that synthetic quantities are already notional values
|
|
public double notional_value =>
|
|
(security?.HasSynthetic ?? false)
|
|
? order.order.quantity()
|
|
: order.order.notional_value();
|
|
|
|
// TODO: remove assumption that synthetic quantities are already notional values
|
|
public double filled_notional_value =>
|
|
(security?.HasSynthetic ?? false)
|
|
? order.order.filled_quantity()
|
|
: order.order.filled_notional_value();
|
|
|
|
public bool Equals(OrderRecordTupleWithRoot other) =>
|
|
order.Equals(other.order) &&
|
|
EqualityComparer.nullable_equals(_root, other._root);
|
|
|
|
public override bool Equals(object? obj) =>
|
|
obj is OrderRecordTupleWithRoot other && Equals(other);
|
|
|
|
public override int GetHashCode() =>
|
|
HashCode.Combine(order, _root);
|
|
public static Object ToJsonObj(OrderRecordTupleWithRoot obj) => new {
|
|
key = obj.key,
|
|
root_key = obj.root.key,
|
|
security = obj.order.security.ToString(),
|
|
parent_key = obj.order.order.ParentKey,
|
|
kind = obj.order.algo_type.display_name(),
|
|
price = obj.order.order.price(), //how to get this
|
|
quantity = obj.order.order.quantity(),
|
|
side = obj.order.order.side(),
|
|
status = obj.order.order.status(),
|
|
status_message = obj.order.order.last_msg()
|
|
};
|
|
public static bool operator ==(OrderRecordTupleWithRoot left, OrderRecordTupleWithRoot right) =>
|
|
left.Equals(right);
|
|
|
|
public static bool operator !=(OrderRecordTupleWithRoot left, OrderRecordTupleWithRoot right) =>
|
|
!(left == right);
|
|
}
|
|
}
|