So we can create ViewStreams that depend on other services, config, etc. Previously, the PrimitiveManager relied purely on static construction of types through reflection.
151 lines
5.4 KiB
C#
151 lines
5.4 KiB
C#
namespace Bts.SharedStreams.StreamFactories;
|
|
|
|
using BCG;
|
|
|
|
using bts.api;
|
|
using bts.md;
|
|
|
|
using Bts.DataStreamCore;
|
|
|
|
using Spark.Api.MarketData;
|
|
|
|
public class BookSchemaBuilder {
|
|
public int NumLevels { get; set; }
|
|
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 string TableName { get; set; } = "Book";
|
|
|
|
public IBlueTableSchema ToSchema() {
|
|
var bd = new BlueTableSchemaBuilder(TableName) {
|
|
("id", typeof(int))
|
|
};
|
|
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);
|
|
}
|
|
foreach (var side in new[] { Side.Buy, Side.Sell }) {
|
|
for (int i = 0; i < NumLevels; i++) {
|
|
if (ShowPrice) {
|
|
bd.Add(WellKnownColumns.DepthPrice(side, i));
|
|
}
|
|
if (ShowQuantity) {
|
|
bd.Add(WellKnownColumns.DepthQuantity(side, i));
|
|
}
|
|
if (ShowNotional) {
|
|
bd.Add(WellKnownColumns.DepthNotional(side, i));
|
|
}
|
|
}
|
|
}
|
|
return bd.ToSchema();
|
|
}
|
|
|
|
public BlueTableSchemaAdapter<BookTuple> BookTupleAdapter() {
|
|
var adapter = new BlueTableSchemaAdapter<BookTuple>(TableName);
|
|
adapter.AddColumn("id", r => (int)r.security_id);
|
|
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);
|
|
}
|
|
foreach (var side in new[] { Side.Buy, Side.Sell }) {
|
|
for (int i = 0; i < NumLevels; i++) {
|
|
if (ShowPrice) {
|
|
adapter.AddColumn(WellKnownColumns.DepthPrice(side, i).Name, priceGetter(side, i));
|
|
}
|
|
if (ShowQuantity) {
|
|
adapter.AddColumn(WellKnownColumns.DepthQuantity(side, i).Name, quantityGetter(side, i));
|
|
}
|
|
if (ShowNotional) {
|
|
adapter.AddColumn(WellKnownColumns.DepthNotional(side, i).Name, notionalGetter(side, i));
|
|
}
|
|
}
|
|
}
|
|
return adapter;
|
|
}
|
|
|
|
public BlueTableSchemaAdapter<BookTuple> BboAdapter() {
|
|
var adapter = new BlueTableSchemaAdapter<BookTuple>(TableName);
|
|
adapter.AddColumn("id", r => (int)r.security_id);
|
|
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.BidPrice.Name, b => b.book.bids[0].price);
|
|
}
|
|
if (ShowQuantity) {
|
|
adapter.AddColumn(WellKnownColumns.BidQuantity.Name, b => b.book.bids[0].size);
|
|
}
|
|
if (ShowNotional) {
|
|
adapter.AddColumn(WellKnownColumns.BidNotional.Name, b => b.book.bids[0].NotionalValue(b.security.ContractSpec.CashPerPoint));
|
|
}
|
|
if (ShowPrice) {
|
|
adapter.AddColumn(WellKnownColumns.AskPrice.Name, b => b.book.asks[0].price);
|
|
}
|
|
if (ShowQuantity) {
|
|
adapter.AddColumn(WellKnownColumns.AskQuantity.Name, b => b.book.asks[0].size);
|
|
}
|
|
if (ShowNotional) {
|
|
adapter.AddColumn(WellKnownColumns.AskNotional.Name, b => b.book.asks[0].NotionalValue(b.security.ContractSpec.CashPerPoint));
|
|
}
|
|
return adapter;
|
|
}
|
|
|
|
static Func<BookTuple, double> priceGetter(Side side, int level) =>
|
|
b => b.book[side, level].price;
|
|
|
|
static Func<BookTuple, double> quantityGetter(Side side, int level) =>
|
|
b => b.book[side, level].size;
|
|
|
|
static Func<BookTuple, double> notionalGetter(Side side, int level) =>
|
|
b => b.book[side, level].NotionalValue(b.security.ContractSpec.CashPerPoint);
|
|
}
|