ui: Format min order qty/notional cols with sec ticks
This commit is contained in:
1 parent
bb64760c62
commit
cc55fe1acf
3 files changed
+59
-2
No files matched your search
@@ -199,8 +199,8 @@ namespace mbts.spark {
|
||||
add_col(ColKey.Theta, r => fmt_greek(r.theta), nameof(Row.theta), theta_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.Rho, r => fmt_greek(r.rho), nameof(Row.rho), rho_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.CashPerPoint, r => r.cash_per_point.ToString("0.00#####"), nameof(Row.cash_per_point), cash_per_point_filter, FilterType.DoubleMinMax, ColWidth.Greeks);
|
||||
add_col(ColKey.MinOrderQuantity, r => r.min_order_quantity.ToString("0.00#####"), nameof(Row.min_order_quantity), min_order_quantity_filter, FilterType.DoubleMinMax, ColWidth.Qty);
|
||||
add_col(ColKey.MinOrderNotional, r => r.min_order_notional.ToString("0.00#####"), nameof(Row.min_order_notional), min_order_notional_filter, FilterType.DoubleMinMax, ColWidth.Qty);
|
||||
add_col(ColKey.MinOrderQuantity, r => r.security.format_quantity(r.min_order_quantity), nameof(Row.min_order_quantity), min_order_quantity_filter, FilterType.DoubleMinMax, ColWidth.Qty);
|
||||
add_col(ColKey.MinOrderNotional, r => r.security.format_price(r.min_order_notional), nameof(Row.min_order_notional), min_order_notional_filter, FilterType.DoubleMinMax, ColWidth.Qty);
|
||||
|
||||
// row vm filter
|
||||
// Althoguh securities are filtered at the row 'model' level (SecurityMD), the column base filters have to be applied at the row vm level,
|
||||
|
||||
@@ -83,6 +83,11 @@ namespace mbts.spark {
|
||||
public static string format(this ContractSpecificationImmutable spec, double price, double display_multiplier, bool show_commas, string nan_text) =>
|
||||
_get(spec).format(price, display_multiplier, show_commas, nan_text);
|
||||
|
||||
public static string format_quantity(this ContractSpecificationImmutable spec, double quantity) =>
|
||||
spec.QuantityInfos.TryGetFirst(out var qi)
|
||||
? new TickFactors(qi.TickBase, qi.TickUnit).format(quantity)
|
||||
: quantity.ToString();
|
||||
|
||||
public static double parse(this ContractSpecificationImmutable spec, string text, double display_multiplier, string nan_text) =>
|
||||
_get(spec).parse(text, display_multiplier, nan_text);
|
||||
|
||||
|
||||
@@ -2,7 +2,10 @@ namespace bts.api {
|
||||
using bts.api.domain;
|
||||
using bts.utils;
|
||||
|
||||
using mbts.spark;
|
||||
|
||||
using Spark.Api.Data;
|
||||
using Spark.Core;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -78,12 +81,61 @@ namespace bts.api {
|
||||
public static DateTime expiration_date(this FutureContractImmutable future) =>
|
||||
new((int)future.ExpirationYear, (int)future.ExpirationMonth, (int)future.ExpirationDay);
|
||||
|
||||
public static double MinNotionalValue(this SecurityImmutable security, double price = double.NaN) {
|
||||
if (security.HasSynthetic) {
|
||||
if (security.Synthetic.Legs.TryGetFirst(out var firstLeg) && firstLeg.HasSecurity) {
|
||||
return firstLeg.Security.MinNotionalValue();
|
||||
}
|
||||
} else if (security.HasContractSpec) {
|
||||
var spec = security.ContractSpec;
|
||||
// If price is nan, use first NotionalQuantityInfo item
|
||||
if (spec.NotionalQuantityInfos.TryGetFirst(qi => !(price > qi.MaxPrice), out var qi)) {
|
||||
return qi.MinValue;
|
||||
}
|
||||
}
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
public static double MinOrderQuantity(this SecurityImmutable security, double price = double.NaN) {
|
||||
if (security.HasSynthetic) {
|
||||
if (security.Synthetic.Legs.TryGetFirst(out var firstLeg) && firstLeg.HasSecurity) {
|
||||
return firstLeg.Security.MinOrderQuantity(price);
|
||||
}
|
||||
} else if (security.HasContractSpec) {
|
||||
var spec = security.ContractSpec;
|
||||
var minQty = spec.QuantityInfos
|
||||
.SelectFirstOrDefault(qi => !(price > qi.MaxPrice), NullableWrapper.Wrap)
|
||||
?.MinValue ?? double.NaN;
|
||||
if (!price.is_real_non_zero()) {
|
||||
return minQty;
|
||||
}
|
||||
var minNotionalValue = spec.NotionalQuantityInfos
|
||||
.SelectFirstOrDefault(qi => !(price > qi.MaxPrice), NullableWrapper.Wrap)
|
||||
?.MinValue ?? double.NaN;
|
||||
if (!minNotionalValue.is_real()) {
|
||||
return minQty;
|
||||
}
|
||||
var minNotionalQty = minNotionalValue / price;
|
||||
if (!minQty.is_real()) {
|
||||
return minNotionalQty;
|
||||
}
|
||||
return Math.Max(minQty, minNotionalQty);
|
||||
}
|
||||
return double.NaN;
|
||||
}
|
||||
|
||||
internal static ExpirationDate earliest_expiration(this SecurityImmutable security) =>
|
||||
security.normal_expirations().Min();
|
||||
|
||||
public static double strike(this SecurityImmutable security) =>
|
||||
security.HasOption ? security.Option.Strike : double.NaN;
|
||||
|
||||
public static string format_price(this SecurityImmutable security, double value) =>
|
||||
security.HasContractSpec ? security.ContractSpec.format(value) : value.ToString();
|
||||
|
||||
public static string format_quantity(this SecurityImmutable security, double value) =>
|
||||
security.HasContractSpec ? security.ContractSpec.format_quantity(value) : value.ToString();
|
||||
|
||||
internal static double signed_quantity(this ContractLegImmutable leg) =>
|
||||
leg.Side == Side.Buy ? leg.Quantity : -leg.Quantity;
|
||||
|
||||
|
||||
Reference in new issue
Block a user