From aa403b83efee3d94dd03e98b39fa430c6508f576 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Tue, 12 May 2026 10:11:01 -0400 Subject: [PATCH] improve: Use quantity sign to indicate side in TopOfBookQuoter example --- src/cs/Bts.Spark.Sdk.Demo/TopOfBookQuoter.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cs/Bts.Spark.Sdk.Demo/TopOfBookQuoter.cs b/src/cs/Bts.Spark.Sdk.Demo/TopOfBookQuoter.cs index bc0872a71..d6ee2bc17 100644 --- a/src/cs/Bts.Spark.Sdk.Demo/TopOfBookQuoter.cs +++ b/src/cs/Bts.Spark.Sdk.Demo/TopOfBookQuoter.cs @@ -41,8 +41,8 @@ class TopOfBookQuoter : IHostedService { throw new ArgumentException("Failed to parse venue", nameof(config)); } var quantity = config.Quantity; - if (!(quantity > 0)) { - throw new ArgumentException("Quantity is not positive", nameof(config)); + if (quantity == 0 || !double.IsRealNumber(quantity)) { + throw new ArgumentException("Quantity must be real and non-zero", nameof(config)); } this.config = new(venue, contract, account, config.OffsetTicks, quantity); } @@ -86,11 +86,12 @@ class TopOfBookQuoter : IHostedService { if (!bk.Security.HasValue) { return; } - var bidPrice = bk[Side.Buy, 0].Price; - var orderPrice = bidPrice; var orderQty = config.Quantity; + var bidPrice = bk[orderQty < 0 ? Side.Sell : Side.Buy, 0].Price; + orderQty = Math.Abs(orderQty); + var orderPrice = bidPrice; if (config.OffsetTicks != 0) { - orderPrice = bk.Security.Value.tick_factors().tickdown(orderPrice, config.OffsetTicks); + orderPrice = bk.Security.Value.tick_factors().tick(orderPrice, config.OffsetTicks); } if (securityToOrderId.TryGetValue(bk.SecurityId, out var orderId) && orders.TryGetValue(orderId, out var orderTree)