93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
namespace Bts.SharedStreams.StreamFactories;
|
|
|
|
using BCG;
|
|
|
|
using bts.api;
|
|
|
|
using Bts.DataStreamCore;
|
|
|
|
using mbts.spark;
|
|
using mbts.utils;
|
|
|
|
public class TradeSchemaBuilder {
|
|
public bool ShowNotional { get; set; }
|
|
public bool ShowQuantity { get; set; } = true;
|
|
public bool ShowPrice { get; set; } = true;
|
|
public bool ShowVenue { get; set; }
|
|
public bool ShowAsset { get; set; } = true;
|
|
public bool ShowSecurityType { get; set; }
|
|
public bool ShowSecurityName { get; set; }
|
|
public bool ShowSecurityId { get; set; } = true;
|
|
public bool ShowCashPerPoint { get; set; }
|
|
public bool ShowTimestamp { get; set; } = true;
|
|
public string TableName { get; set; } = "Trade";
|
|
|
|
public IBlueTableSchema ToSchema() {
|
|
var bd = new BlueTableSchemaBuilder(TableName) {
|
|
("id", typeof(int))
|
|
};
|
|
if (ShowTimestamp) {
|
|
bd.Add(WellKnownColumns.Timestamp);
|
|
}
|
|
if (ShowVenue) {
|
|
bd.Add(WellKnownColumns.Venue);
|
|
}
|
|
if (ShowSecurityType) {
|
|
bd.Add(WellKnownColumns.SecurityType);
|
|
}
|
|
if (ShowAsset) {
|
|
bd.Add(WellKnownColumns.Asset);
|
|
}
|
|
if (ShowSecurityName) {
|
|
bd.Add(WellKnownColumns.SecurityName);
|
|
}
|
|
if (ShowSecurityId) {
|
|
bd.Add(WellKnownColumns.SecurityId);
|
|
}
|
|
if (ShowCashPerPoint) {
|
|
bd.Add(WellKnownColumns.CashPerPoint);
|
|
}
|
|
if (ShowPrice) {
|
|
bd.Add(WellKnownColumns.Price);
|
|
}
|
|
if (ShowQuantity) {
|
|
bd.Add(WellKnownColumns.Quantity);
|
|
}
|
|
return bd.ToSchema();
|
|
}
|
|
|
|
public BlueTableSchemaAdapter<TradeInfo> TradeInfoAdapter() {
|
|
var adapter = new BlueTableSchemaAdapter<TradeInfo>(TableName);
|
|
adapter.AddColumn("id", r => r.RecordId);
|
|
if (ShowTimestamp) {
|
|
adapter.AddColumn(WellKnownColumns.Timestamp.Name, b => new LLDateTime((ulong)b.trade.Time).to_datetime());
|
|
}
|
|
if (ShowVenue) {
|
|
adapter.AddColumn(WellKnownColumns.Venue.Name, b => b.security.Exchange.ToString());
|
|
}
|
|
if (ShowSecurityType) {
|
|
adapter.AddColumn(WellKnownColumns.SecurityType.Name, b => b.security.security_type().ToString());
|
|
}
|
|
if (ShowAsset) {
|
|
adapter.AddColumn(WellKnownColumns.Asset.Name, b => b.security.Symbol);
|
|
}
|
|
if (ShowSecurityName) {
|
|
adapter.AddColumn(WellKnownColumns.SecurityName.Name, b => b.security.ToString());
|
|
}
|
|
if (ShowSecurityId) {
|
|
adapter.AddColumn(WellKnownColumns.SecurityId.Name, b => b.security.Id);
|
|
}
|
|
if (ShowCashPerPoint) {
|
|
adapter.AddColumn(WellKnownColumns.CashPerPoint.Name, b => b.security.ContractSpec.CashPerPoint);
|
|
}
|
|
if (ShowPrice) {
|
|
adapter.AddColumn(WellKnownColumns.Price.Name, b => b.trade.Mantissa * Math.Pow(10, b.trade.Exponent));
|
|
}
|
|
if (ShowQuantity) {
|
|
// TODO: Make trade size a float (it's still uint)
|
|
adapter.AddColumn(WellKnownColumns.Quantity.Name, b => b.trade.Size);
|
|
}
|
|
return adapter;
|
|
}
|
|
}
|